char get_kb(void) { char c; while (!kbhit()); c = fgetc(stdin); fflush(stdin); usleep(1000); kbfini(); return c; }
main() { int x, y, ret=0; int delay; char buf[100],symbol[10], sym_2[10], sym_3[10], sym_4[10]; memset(co_ordinates, 0x00, sizeof(co_ordinates)); sprintf(symbol,"."); sprintf(sym_2,"."); sprintf(sym_3,"0"); sprintf(sym_4," "); refresh_screen(); //initial position gotoxy(x_cur, y_cur, sym_3, strlen(sym_3)); fflush(stdin); while(1){ c = -1; gotoxy_none(24,4); if(!kbhit()){ continue; } c = fgetc(stdin); if(c =='x'){ goto terminate_game; } switch(c){ case 65://up sprintf(buf, "UP "); gotoxy(22, 43, buf, strlen(buf)); ret = 0; break; case 66://down sprintf(buf, "DOWN "); gotoxy(22, 43, buf, strlen(buf)); ret = 0; break; case 67://right sprintf(buf, "RIGHT "); gotoxy(22, 43, buf, strlen(buf)); ret = 0; break; case 68://left sprintf(buf, "LEFT "); gotoxy(22, 43, buf, strlen(buf)); ret = 0; break; default: sprintf(buf, "INVLD "); gotoxy(22, 43, buf, strlen(buf)); ret = move_left(); ret = -1; break; } if(ret == 0){ break; } } if(key_event_update() == -1){ goto terminate_game; } terminate_game: refresh_screen(); sprintf(buf, " GAME OVER \n"); gotoxy(10, 15, buf, strlen(buf)); fflush(stdin); fflush(stdout); kbfini(); sprintf(buf, "\n"); gotoxy(24, 5, buf, strlen(buf)); }