int main() { int key; init_display(); play_again: reset_game(); display_board(&grid); play_game(); movecur(15, 9 + brd_h * 2); textcolour(12); strout("Game Over! Press ESCAPE to exit or ENTER to play again."); do { key = os_wait_for_key(); } while (key != ESC_KEY && key != ENTER_KEY); if (key == ENTER_KEY) goto play_again; end_program(); }
char getchar() { return os_wait_for_key() & 0x00FF; }
void play_game() { board *b = &grid; do { switch (os_wait_for_key()) { case ESC_KEY: return; case UP_KEY: if (can_move_up(b)) { shift_up(b); merge_up(b); shift_up(b); add_big_int(&score, &merge_score); break; } else { continue; } case DOWN_KEY: if (can_move_down(b)) { shift_down(b); merge_down(b); shift_down(b); add_big_int(&score, &merge_score); break; } else { continue; } case LEFT_KEY: if (can_move_left(b)) { shift_left(b); merge_left(b); shift_left(b); add_big_int(&score, &merge_score); break; } else { continue; } case RIGHT_KEY: if (can_move_right(b)) { shift_right(b); merge_right(b); shift_right(b); add_big_int(&score, &merge_score); break; } else { continue; } default: continue; } add_tile(b); display_board(b); } while (!game_is_lost()); }