#include #include #include //for isprint (or ctype.h) #include #include "terminal.h" using namespace std; terminal::terminal(char initial_background) : _background(initial_background), _xmax((term_construct(), term_xmax())), _ymax(term_ymax()) { if (_background != ' ') { for (unsigned y = 0; y < _ymax; ++y) { for (unsigned x = 0; x < _xmax; ++x) { put(x, y); } } } } terminal::~terminal() { for (unsigned y = 0; y < _ymax; ++y) { for (unsigned x = 0; x < _xmax; ++x) { put(x, y, ' '); } } term_destruct(); } void terminal::put(unsigned x, unsigned y, char c) const { if (!isprint(static_cast(c))) { cerr << "unprintable character " << static_cast(static_cast(c)) << ".\n"; system("PAUSE"); exit(EXIT_FAILURE); } check(x, y); term_put(x, y, c); } void terminal::put(unsigned x, unsigned y, const char *s) const { for (; *s != '\0'; ++s) { put(x, y, *s); next(x, y); } } //Move to the next (x, y) position: left to right, top to bottom. //Warning: will change the values of the arguments. void terminal::put(unsigned x, unsigned y, const string &s) const { for (string::size_type i = 0; i = _xmax) { x = 0; ++y; } } void terminal::check(unsigned x, unsigned y) const { if (!in_range(x, y)) { cerr << "coordinates (" << x << ", " << y << ") must be >= (0, 0) and < (" << _xmax << ", " << _ymax << ")\n"; exit(EXIT_FAILURE); } }