From: Julian Cowley Date: Mon, 7 Mar 2022 18:48:15 +0000 (-1000) Subject: Print type of hazards in same order every time X-Git-Tag: 1.8~2 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=044bb851de16f988dcce5c324221b1152acb670e;p=wumpus.git Print type of hazards in same order every time It is important to print the hazards in the same order every time whenever you are adjacent to them, such as the order they appear in the loc variable (the Wumpus, pits, bats). Currently, the hazards are printed in the order the rooms appear in the cave list. As an example, say you are in room 1 and there are super bats in room 2, a pit in room 5, and the Wumpus in room 8. The hazards are shown like this: BATS NEARBY! I FEEL A DRAFT I SMELL A WUMPUS! This is problematic since someone might notice the order corresponds to cave list and therefore figure out which type of hazard is in each room. Instead, the order based on the loc variable is: I SMELL A WUMPUS! I FEEL A DRAFT BATS NEARBY! This gives no clues as to which room has what. --- diff --git a/wumpus.c b/wumpus.c index 0bb6315..5d4efe4 100644 --- a/wumpus.c +++ b/wumpus.c @@ -230,16 +230,20 @@ void check_hazards() /* 635 PRINT "BATS NEARBY!" */ /* 640 NEXT K */ /* 645 NEXT J */ - for (k = 0; k < 3; k++) + for (j = WUMPUS; j < LOCS; j++) { - int room = cave[loc[YOU]][k]; - - if (room == loc[WUMPUS]) - (void) puts("I SMELL A WUMPUS!"); - else if (room == loc[PIT1] || room == loc[PIT2]) - (void) puts("I FEEL A DRAFT"); - else if (room == loc[BATS1] || room == loc[BATS2]) - (void) puts("BATS NEARBY!"); + for (k = 0; k < 3; k++) + { + if (cave[loc[YOU]][k] != loc[j]) + continue; + + if (j == WUMPUS) + (void) puts("I SMELL A WUMPUS!"); + else if (j == PIT1 || j == PIT2) + (void) puts("I FEEL A DRAFT"); + else if (j == BATS1 || j == BATS2) + (void) puts("BATS NEARBY!"); + } } /* 650 PRINT "YOU ARE IN ROOM "L(1) */