Due Date: Wednesday, Nov 12, 8:30 AM
Program Five will demonstrate the use of arrays and files. This program
will be somewhat longer than previous assignments. It would be more aptly
named a project. Please use this extra time to make a plan of
attack before writing code -- design function prototypes and algorithms
before digging into the heart of the program. Good luck!
BackgroundThis program is a variation on a very old computer game called Hunt the Wumpus. In this game, you will move a human through a maze in search of a creature known only as The Wumpus. The terrified Wumpus can smell you coming, and will attempt to stay away from you.The MazeThe maze will be represented on the screen as a rectangle of characters. A . represents open space, a X represents a wall, a * represents the human player, and a # represents The Wumpus. Both the player and the wumpus are free to move one square at a time in any direction (including diagonally) as long as there is no wall in the way. Neither the player or The Wumpus may move off of the top, bottom, left, or right of the maze. An example display including a player and a Wumpus might look like this:........................ ..X.............XXXXXX.. ..X..XXXXXXXXXXXX..#.... ..X.............X....... XXXXXXXX....X...XXXXXXX. .......X....X...X.....X. .*.....X....XXX.X.....X. .......XXXXXX...X.X.X.X. ..................X.X.X. XXXXXXXXXXXXXXX...X.X.X. ..X..........X....X.X.X. ..X..XXXXXXXXXX...X.XXX. ..................X..... The GameIn every round of the game, your program will display the maze, including the positions of the player and The Wumpus. The program must then ask the user what direction he/she wishes to go. The user may specify a direction by entering a number. The direction is given by that number's position on the numeric keypad. For example, 8 means go north, 9 means go northeast, and 6 means go east. Thus, the player may move one square in any straight or diagonal direction. (You may need to press the NumLock key to make the keypad word).There are, however, some limitations. The player may not enter a square containing a wall, nor may the player move off the edge of the map. If the player selects a valid direction, the player will move one square in that direction. If the player enters the same location as The Wumpus, the game is over and the player wins. If not, the program decides how the wumpus must move, and then begins a new round. The player may end the program prematurely by entering 'q'. If the player wins the game, the program should ask if the player wishes to begin again. The WumpusThe Wumpus is a poor little creature who does not want to be caught by the player. You may give the Wumpus whatever decision-making ability you feel is necessary to make it evade the player. However, it must follow these two rules:Program StructureAs always, your program must have the elements of good design: modularity, readability, etc. I strongly suggest you split up your program into the following functions:bool load_maze( ... ); /* Read the maze from a file */ void print_maze( ... ); /* Print the maze */ char get_player_move( ... ); /* Get the player's action */ char get_wumpus_move( ... ); /* Decide The Wumpus' action */ bool is_legal_move( ... ); /* Can a player or a wumpus move */ /* to this position? */ The (...) indicates you are free to define whatever parameters you feel are necessary. In class, I have discouraged the use of global variables. This program might be simpler to write using a limited number of globals. Please comment any global variables to provide a brief explanation why using non-global variables is impractical for your purposes. Handin Procedure
|