/* CLS is unused in this example. */ #ifdef __TURBOC__ #include #define CLS() clrscr() #define SETPOS(a,b) gotoxy(a,b) #else #include #define CLS() clear() #define SETPOS(a,b) move(b,a) #endif #include int getKey(void){ #ifdef __TURBOC__ return getch(); /* it exists in conio but I don't know if it is equivalent */ #else return getch(); #endif } void printChar(int in){ #ifdef __TURBOC__ // putchar((char)in); putchar('*'); #else printw("%c", in); #endif } int main(int argc, char *argv[]){ unsigned int Busy; int MAX_X, MAX_Y; struct Object{ int x, y; char Character; } Object; Object.x = 38; Object.y = 13; Object.Character = '*'; #ifdef __TURBOC__ MAX_X = 80; /* FIXME dunno how to get this */ MAX_Y = 25; /* FIXME dunno how to get this */ CLS(); #else /* curses init */ initscr(); curs_set(0); raw(); nodelay(stdscr, TRUE); noecho(); MAX_X = COLS; MAX_Y = LINES; #endif assert(MAX_X); assert(MAX_Y); Busy = 1; while(Busy){ /* Clear */ SETPOS(Object.x, Object.y); printChar(' '); /* Keyboard input */ switch(getKey()){ case ';': Busy = 0; break; case 'w': Object.y--; break; case 's': Object.y++; break; case 'a': Object.x--; break; case 'd': Object.x++; } if(Object.x < 1 || Object.y < 1 || Object.x >= MAX_X || Object.y >= MAX_Y) Busy = 0; /* Draw */ SETPOS(Object.x, Object.y); printChar('*'); #ifndef __TURBOC__ refresh(); #endif } #ifndef __TURBOC__ endwin(); CLS(); #endif return 0; }