1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-12-04 14:46:45 -05:00

Add the abort_game global variable

The abort_game variable allows the program to abort the game without
showing the final winner.
This commit is contained in:
John Zaitseff 2011-07-14 15:11:53 +10:00
parent 200f7cdf97
commit 39d6bc5b37
4 changed files with 8 additions and 6 deletions

View File

@ -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);
}

View File

@ -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?

View File

@ -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 */

View File

@ -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();