From 1beb2003ef5e0968f6d7a14fa583ece9c41d46f0 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Mon, 18 Jul 2011 16:22:24 +1000 Subject: [PATCH] Remove the global variables selection, credit_limit and bid_used --- src/globals.c | 4 ---- src/globals.h | 4 ---- src/move.c | 29 +++++++++++++++-------------- src/move.h | 4 ++-- src/trader.c | 6 ++++-- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/globals.c b/src/globals.c index 8c6d7df..f8afe8b 100644 --- a/src/globals.c +++ b/src/globals.c @@ -70,8 +70,6 @@ player_info_t player[MAX_PLAYERS]; // Array of players map_val_t galaxy_map[MAX_X][MAX_Y]; // Map of the galaxy move_rec_t game_move[NUMBER_MOVES]; // Current moves -sel_val_t selection; // Move selected by current player - int max_turn; // Max. number of turns in game int turn_number; int number_players; @@ -79,8 +77,6 @@ int current_player; int first_player; // Who WAS the first player to go? double interest_rate; // Current interest rate -double credit_limit; // Credit limit of current player -bool bid_used; // True if bid used for player bool game_loaded = false; // True if game was loaded from disk int game_num = 0; // Game number (1-9) diff --git a/src/globals.h b/src/globals.h index e11ba8c..0826a06 100644 --- a/src/globals.h +++ b/src/globals.h @@ -163,8 +163,6 @@ extern player_info_t player[MAX_PLAYERS]; // Array of players extern map_val_t galaxy_map[MAX_X][MAX_Y]; // Map of the galaxy extern move_rec_t game_move[NUMBER_MOVES]; // Current moves -extern sel_val_t selection; // Move selected by current player - extern int max_turn; // Max. number of turns in game extern int turn_number; extern int number_players; @@ -172,8 +170,6 @@ extern int current_player; extern int first_player; // Who WAS the first player to go? extern double interest_rate; // Current interest rate -extern double credit_limit; // Credit limit of current player -extern bool bid_used; // True if bid used for player extern bool game_loaded; // True if game was loaded from disk extern int game_num; // Game number (1-9) diff --git a/src/move.c b/src/move.c index 1bddd9b..fca269f 100644 --- a/src/move.c +++ b/src/move.c @@ -130,29 +130,28 @@ void select_moves (void) /*----------------------------------------------------------------------- - Function: get_move - Wait for the player to enter their move + Function: get_move - Wait for the player to enter their move Arguments: (none) - Returns: (nothing) + Returns: sel_val_t - Choice selected by player This function displays the galaxy map and the current moves, then waits for the player to select one of the moves. On entry, current_player points to the current player; quit_selected and/or abort_game may be true (if so, get_move() justs returns without waiting for the player to - select a move). On exit, selection contains the choice made by the - player. Note that two windows (the "Select move" window and the galaxy - map window) are left on the screen: they are closed in process_move(). + select a move). The return value is the choice made by the player. + + Note that two windows (the "Select move" window and the galaxy map + window) are left on the screen: they are closed in process_move(). */ -void get_move (void) +sel_val_t get_move (void) { int i, x, y; + sel_val_t selection = SEL_NONE; if (quit_selected || abort_game) { - selection = SEL_QUIT; - return; - } else { - selection = SEL_NONE; + return SEL_QUIT; } // Display map without closing window @@ -386,19 +385,21 @@ void get_move (void) } } } + + return selection; } /*----------------------------------------------------------------------- Function: process_move - Process the move selected by the player - Arguments: (none) + Arguments: selection - Selection made by current player Returns: (nothing) - This function processes the move in the global variable selection. It - assumes the "Select move" and galaxy map windows are still open. + This function processes the move in selection. It assumes the "Select + move" and galaxy map windows are still open. */ -void process_move (void) +void process_move (sel_val_t selection) { if (! quit_selected && ! abort_game) { switch(selection) { diff --git a/src/move.h b/src/move.h index be95a18..45136e2 100644 --- a/src/move.h +++ b/src/move.h @@ -37,8 +37,8 @@ ************************************************************************/ extern void select_moves (void); -extern void get_move (void); -extern void process_move (void); +extern sel_val_t get_move (void); +extern void process_move (sel_val_t selection); extern void next_player (void); diff --git a/src/trader.c b/src/trader.c index dbaa8c5..cddcff4 100644 --- a/src/trader.c +++ b/src/trader.c @@ -70,9 +70,11 @@ int main (int argc, char *argv[]) // Play the actual game init_game(); while (! quit_selected && ! abort_game && turn_number <= max_turn) { + sel_val_t selection; + select_moves(); - get_move(); - process_move(); + selection = get_move(); + process_move(selection); exchange_stock(); next_player(); }