#include // getch() kbhit() #include #define FALSE (0) #define TRUE (!FALSE) int main(void) { int x, y; int vx, vy; int i, j; int stayinloop; int cmd; int row, col; clock_t start, now; for(x = 2; x < 78; x++) { gotoxy(x, 2); putch('-'); gotoxy(x, 22); putch('-'); } for(y = 2; y < 22; y++) { gotoxy(2, y); putch('|'); gotoxy(78, y); putch('|'); } x=40; y=4; vx = -1; vy = 1; start = clock(); stayinloop = TRUE; while(stayinloop) { now = clock(); if(kbhit()) cmd = getch(); switch(cmd) { case 'q': case 'Q': stayinloop = FALSE; break; } if(now > start + 5) { gotoxy(x,y); putch(' '); x += vx; y += vy; if((x < 2) || (x > 78)) vx *= -1; if((y < 2) || (y > 22)) vy *= -1; gotoxy(x,y); putch('*'); start = now; } } return(0); }