//This file is main.C (C++ example). #include #include #include //for toupper extern "C" { #include "term3d.h" //the above file } using namespace std; int main() { struct keystroke { char c; int dx; //horizontal offset int dy; //vertical offset int dz; //front to back offset }; static const keystroke k[] = { {'h', -1, 0, 0}, //left {'j', 0, 1, 0}, //down {'k', 0, -1, 0}, //up {'l', 1, 0, 0}, //right {'f', 0, 0, -1}, //forward {'b', 0, 0, 1} //backward }; static const size_t n = sizeof k / sizeof k[0]; term3d_construct("192.168.20.195", 9265); const unsigned xmax = term3d_xmax(); const unsigned ymax = term3d_ymax(); const unsigned zmax = term3d_zmax(); term3d_puts(0, 0, 0, "type hjklfbq for left, down, up, right, front, back, quit."); //Capitalize the "t" in "type". const char c = term3d_get(0, 0, 0); term3d_put(0, 0, 0, toupper(c)); for (unsigned x = xmax / 2, y = ymax / 2, z = zmax / 2;;) { term3d_put(x, y, z, 'X'); char c; //uninitialized variable while ((c = term3d_key()) == '\0') { } if (c == 'q') { break; } const keystroke *p; //uninitialized variable for (p = k; p < k + n; ++p) { if (p->c == c) { goto found; } } term3d_beep(); continue; found:; const unsigned newx = x + p->dx; const unsigned newy = y + p->dy; const unsigned newz = z + p->dz; if (0 <= newx && newx < xmax && 0 <= newy && newy < ymax && 0 <= newz && newz < zmax) { x = newx; y = newy; z = newz; } else { term3d_beep(); } } done:; term3d_wait(1000); //one full second term3d_beep(); term3d_destruct(); return EXIT_SUCCESS; }