From 39d6bc5b37aa224f93458e8132287476cf7342a1 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Thu, 14 Jul 2011 15:11:53 +1000 Subject: [PATCH] Add the abort_game global variable The abort_game variable allows the program to abort the game without showing the final winner. --- src/game.c | 10 +++++----- src/globals.c | 1 + src/globals.h | 1 + src/trader.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/game.c b/src/game.c index bdda9a3..51fd789 100644 --- a/src/game.c +++ b/src/game.c @@ -148,8 +148,8 @@ static const int game_file_crypt_key[] = { On entry to this function, the "game_num" global variable determines whether an old game is loaded (if possible). On exit, all global variables in globals.h are initialised, apart from game_move[]. If the - user aborts entering the necessary information, quit_selected is set to - true and number_players is 0. + user aborts entering the necessary information, abort_game is set to + true. */ void init_game (void) @@ -201,7 +201,7 @@ void init_game (void) done = ((key >= '1') && (key <= (MAX_PLAYERS + '0'))) || (key == 'C'); if ((key == KEY_ESC) || (key == KEY_CTRL('C')) || (key == KEY_CTRL('\\'))) { - quit_selected = true; + abort_game = true; return; } @@ -475,6 +475,7 @@ void init_game (void) } quit_selected = false; + abort_game = false; } @@ -489,13 +490,12 @@ void init_game (void) void end_game (void) { - if (quit_selected && (number_players == 0)) { + if (abort_game) { // init_game() was cancelled by user return; } // @@@ To be written - save_game(2); } diff --git a/src/globals.c b/src/globals.c index 6dcb5cd..ede3df0 100644 --- a/src/globals.c +++ b/src/globals.c @@ -71,3 +71,4 @@ bool game_loaded = false; // True if game was loaded from disk int game_num = 0; // Game number (1-9) bool quit_selected; // Is a player trying to quit the game? +bool abort_game; // Abort game without declaring winner? diff --git a/src/globals.h b/src/globals.h index 0294b73..ef11dd7 100644 --- a/src/globals.h +++ b/src/globals.h @@ -141,6 +141,7 @@ extern bool game_loaded; // True if game was loaded from disk extern int game_num; // Game number (1-9) extern bool quit_selected; // Is a player trying to quit the game? +extern bool abort_game; // Abort game without declaring winner? #endif /* included_GLOBALS_H */ diff --git a/src/trader.c b/src/trader.c index 1bfbdf9..1318f18 100644 --- a/src/trader.c +++ b/src/trader.c @@ -70,7 +70,7 @@ int main (int argc, char *argv[]) // Play the actual game init_game(); - while ((! quit_selected) && (turn_number <= max_turn)) { + while (! quit_selected && ! abort_game && turn_number <= max_turn) { select_moves(); get_move(); process_move();