//This file is main.C (C++ example). #include #include #include #include #include //for copy, fill, find, random_shuffle, sort #include "printable.h" #include "terminal3d.h" using namespace std; typedef terminal3d terminal_t; int main() { srand(static_cast(time(0))); const terminal_t term("192.168.20.199", 9265, '.'); const terminal_t::iterator center(term, term.xmax() / 2, term.ymax() / 2, term.zmax() / 2); terminal_t::iterator it = center; const terminal_t::difference_type down = term.xmax(); it[1] = it[0] = 'X'; //Move one step from the center towards the begin, and write a 'Y'. const terminal_t::difference_type d = term.step(center, term.begin()); it += d; *it = 'Y'; //Move one step from the center away from the begin, and write a 'Z'. it = center; it -= d; *it = 'Z'; //Move a random step away from the center, and write an 'R'. it = center; it += term.rand(); *it = 'R'; it = term.begin(); string s = "qwertyuiopasdfghjklzxcvbnm"; copy(s.begin(), s.end(), it); it += down; copy(s.begin(), s.end(), it); sort(it, it + s.size()); it += down; copy(s.begin(), s.end(), it); sort(it, it + s.size(), greater()); it += down; copy(s.begin(), s.end(), it); random_shuffle(it, it + s.size()); s = "Please type printable characters ending with a q: "; it += down; it = copy(s.begin(), s.end(), it); for (; it != term.end(); ++it) { char c; //uninitialized variable while ((c = term.key()) == '\0') { } if (c == 'q') { break; } *it = c; } fill(term.begin(), term.end(), term.background()); //Clear the screen. s = "Etch-a-sketch: please type hjklfbq for " "left, down, up, right, forward, backward, quit."; copy(s.begin(), s.end(), term.begin()); it = find(term.begin(), term.end(), 's'); if (it != term.end()) { *it = 'S'; } const terminal_t::keypad_t k = term.keypad(); for (it = center;;) { *it = 'X'; char c; //uninitialized variable while ((c = term.key()) == '\0') { } if (c == 'q') { break; } const terminal_t::keypad_t::const_iterator i = k.find(c); if (i == k.end() || !term.in_range(it + i->second)) { term.beep(); } else { it += i->second; } } term.beep(); term.wait(1000); return EXIT_SUCCESS; }