Example #1
0
int main()
{
	const terminal term('.'); //The constructor for term calls term_construct.

	const unsigned xmax = term.xmax();
	const unsigned ymax = term.ymax();

	unsigned x = xmax / 2;	    //center of screen
	unsigned y = ymax / 2;

	term.put(x, y, 'X');
	char c = term.get(x, y);
	term.next(x, y);
	term.put(x, y, c);

	term.put(0, 0, "Please type printable characters ending with a q.");

	for (x = 0, y = 1; term.in_range(x, y); term.next(x, y)) {
		while ((c = term.key()) == '\0') {
		}

		if (c == 'q') {         //quit
			break;
		}

		term.put(x, y, c);
	}

	term.wait(1000);
	term.beep();
	return EXIT_SUCCESS;      //The destructor for term calls term_destruct.
}
Example #2
0
int main()
{
    srand(static_cast<unsigned>(time(0)));
    const terminal term('.');

    const unsigned xmax = term.xmax();
    const unsigned ymax = term.ymax();

    wolf   w(term, xmax * 1 / 3, ymax / 2);
    //rabbit r(term, xmax * 2 / 3, ymax / 2);
    rabbit a[] = {
        rabbit (term, rand() % xmax, rand() % ymax),
        rabbit (term, rand() % xmax, rand() % ymax),
        rabbit (term, rand() % xmax, rand() % ymax)
    };

    const size_t n = sizeof a / sizeof a[0];

    for (;; term.wait(250)) {   //250 milliseconds equals .25 seconds
        if (!w.move()) {
            goto done;
        }
        /*if (!r.move()) {
        	break;
        }*/
        for (rabbit *p = a; p < a + n; ++p) {
            if(!p->move()) {
                goto done;
            }
        }
    }

done:
    term.put(0, 0, "You killed a rabbit!");
    term.wait(3000);     //Give user three seconds to read the message.
    return EXIT_SUCCESS; //Destruct rabbit, wolf, & terminal, in that order.
}
Example #3
0
int main()
{
	srand(static_cast<unsigned>(time(0)));
	const terminal term('.');

	const unsigned xmax = term.xmax();
	const unsigned ymax = term.ymax();

	wolf   w(term, xmax * 1 / 3, ymax / 2);
	rabbit r(term, xmax * 2 / 3, ymax / 2);

	for (;; term.wait(100)) {   //250 milliseconds equals .25 seconds
		if (!w.move()) {
			break;
		}
		if (!r.move()) {
			break;
		}
	}

	term.put(0, 0, "You killed the rabbit!");
	term.wait(3000);     //Give user three seconds to read the message.
	return EXIT_SUCCESS; //Destruct rabbit, wolf, & terminal, in that order.
}