From c90980cacc0e9755716016868307d4f8bb7947de Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Thu, 28 Dec 2017 22:50:37 +0100 Subject: [PATCH] wump(6): Staticize. --- games/wump/wump.c | 116 +++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/games/wump/wump.c b/games/wump/wump.c index 5eb2d937eb..1676d37937 100644 --- a/games/wump/wump.c +++ b/games/wump/wump.c @@ -73,7 +73,7 @@ #define plural(n) (n == 1 ? "" : "s") /* simple cave data structure; +1 so we can index from '1' not '0' */ -struct room_record { +static struct room_record { int tunnel[MAX_LINKS_IN_ROOM]; int has_a_pit, has_a_bat; } cave[MAX_ROOMS_IN_CAVE+1]; @@ -82,45 +82,45 @@ struct room_record { * global variables so we can keep track of where the player is, how * many arrows they still have, where el wumpo is, and so on... */ -int player_loc = -1; /* player location */ -int wumpus_loc = -1; /* The Bad Guy location */ -int level = EASY; /* level of play */ -int arrows_left; /* arrows unshot */ +static int player_loc = -1; /* player location */ +static int wumpus_loc = -1; /* The Bad Guy location */ +static int level = EASY; /* level of play */ +static int arrows_left; /* arrows unshot */ #ifdef DEBUG -int debug = 0; +static int debug = 0; #endif -int pit_num = PIT_COUNT; /* # pits in cave */ -int bat_num = BAT_COUNT; /* # bats */ -int room_num = ROOMS_IN_CAVE; /* # rooms in cave */ -int link_num = LINKS_IN_ROOM; /* links per room */ -int arrow_num = NUMBER_OF_ARROWS; /* arrow inventory */ - -char answer[20]; /* user input */ - -int bats_nearby(void); -void cave_init(void); -void clear_things_in_cave(void); -void display_room_stats(void); -int getans(const char *); -void initialize_things_in_cave(void); -void instructions(void); -int int_compare(const void *, const void *); -void jump(int); -void kill_wump(void); -int move_to(char *); -void move_wump(void); -void no_arrows(void); -void pit_kill(void); -int pit_nearby(void); -void pit_survive(void); -int shoot(char *); -void shoot_self(void); -int take_action(void); -void usage(void); -void wump_kill(void); -int wump_nearby(void); +static int pit_num = PIT_COUNT; /* # pits in cave */ +static int bat_num = BAT_COUNT; /* # bats */ +static int room_num = ROOMS_IN_CAVE; /* # rooms in cave */ +static int link_num = LINKS_IN_ROOM; /* links per room */ +static int arrow_num = NUMBER_OF_ARROWS; /* arrow inventory */ + +static char answer[20]; /* user input */ + +static int bats_nearby(void); +static void cave_init(void); +static void clear_things_in_cave(void); +static void display_room_stats(void); +static int getans(const char *); +static void initialize_things_in_cave(void); +static void instructions(void); +static int int_compare(const void *, const void *); +static void jump(int); +static void kill_wump(void); +static int move_to(char *); +static void move_wump(void); +static void no_arrows(void); +static void pit_kill(void); +static int pit_nearby(void); +static void pit_survive(void); +static int shoot(char *); +static void shoot_self(void); +static int take_action(void); +static void usage(void); +static void wump_kill(void); +static int wump_nearby(void); int main(int argc, char **argv) @@ -236,7 +236,7 @@ quiver holds %d custom super anti-evil Wumpus arrows. Good luck.\n", return (0); } -void +static void display_room_stats(void) { int i; @@ -266,7 +266,7 @@ display_room_stats(void) printf("and %d.\n", cave[player_loc].tunnel[link_num - 1]); } -int +static int take_action(void) { /* @@ -295,7 +295,7 @@ take_action(void) return(0); } -int +static int move_to(char *room_number) { int i, just_moved_by_bats, next_room, tunnel_available; @@ -386,7 +386,7 @@ move_to(char *room_number) return(0); } -int +static int shoot(char *room_list) { int chance, next, roomcnt; @@ -498,7 +498,7 @@ The arrow is weakly shot and can go no further!\n"); return(0); } -void +static void cave_init(void) { int i, j, k, wumplink; @@ -572,7 +572,7 @@ try_again: wumplink = (random() % room_num) + 1; #endif } -void +static void clear_things_in_cave(void) { int i; @@ -585,7 +585,7 @@ clear_things_in_cave(void) cave[i].has_a_bat = cave[i].has_a_pit = 0; } -void +static void initialize_things_in_cave(void) { int i, loc; @@ -625,7 +625,7 @@ initialize_things_in_cave(void) (link_num / room_num < 0.4 ? wump_nearby() : 0) : 0)); } -int +static int getans(const char *prompt) { char buf[20]; @@ -650,7 +650,7 @@ getans(const char *prompt) /* NOTREACHED */ } -int +static int bats_nearby(void) { int i; @@ -662,7 +662,7 @@ bats_nearby(void) return(0); } -int +static int pit_nearby(void) { int i; @@ -674,7 +674,7 @@ pit_nearby(void) return(0); } -int +static int wump_nearby(void) { int i, j; @@ -691,13 +691,13 @@ wump_nearby(void) return(0); } -void +static void move_wump(void) { wumpus_loc = cave[wumpus_loc].tunnel[random() % link_num]; } -int +static int int_compare(const void *va, const void *vb) { const int *a, *b; @@ -708,7 +708,7 @@ int_compare(const void *va, const void *vb) return(a < b ? -1 : 1); } -void +static void instructions(void) { const char *pager; @@ -752,7 +752,7 @@ puff of greasy black smoke! (poof)\n"); } } -void +static void usage(void) { fprintf(stderr, @@ -762,7 +762,7 @@ usage(void) /* messages */ -void +static void wump_kill(void) { printf( @@ -774,7 +774,7 @@ so long since the evil Wumpus cleaned his teeth that you immediately\n\ passed out from the stench!\n"); } -void +static void kill_wump(void) { printf( @@ -786,7 +786,7 @@ dead Wumpus is also quite well known, a stench plenty enough to slay the\n\ mightiest adventurer at a single whiff!!\n"); } -void +static void no_arrows(void) { printf( @@ -796,7 +796,7 @@ with its psychic powers, the evil Wumpus rampagees through the cave, finds\n\ you, and with a mighty *ROAR* eats you alive!\n"); } -void +static void shoot_self(void) { printf( @@ -807,7 +807,7 @@ and immediately rushes to your side, not to help, alas, but to EAT YOU!\n\ (*CHOMP*)\n"); } -void +static void jump(int where) { printf( @@ -816,7 +816,7 @@ notice that the walls are shimmering and glowing. Suddenly you feel\n\ a very curious, warm sensation and find yourself in room %d!!\n", where); } -void +static void pit_kill(void) { printf( @@ -828,7 +828,7 @@ you fall many miles to the core of the earth. Look on the bright side;\n\ you can at least find out if Jules Verne was right...\n"); } -void +static void pit_survive(void) { printf( -- 2.11.4.GIT