Text by Robert Rodgers
Hunt the Wumpus is probably the first interactive computer game ever written, predating games like spacewar or pong by about a decade. You will implement a simple version of Hunt The Wumpus.
DESCRIPTION: The game board is a simple 4 x 4 matrix. The matrix is completely empty except for two things: the player (moves freely) the wumpus (moves randomly) The goal of the game is for the player to move into a square containing the wumpus, capturing it. The game is turn based -- first your human player enters a move, then the wumpus moves. If the WUMPUS moves into the human's square in the matrix, the human loses. and the game is over. If the human moves into the wumpus's square, the human wins and the game is over. WHAT YOU NEED TO DO: The body of your program should be a loop. (1) initialize the location of the wumpus and the player at the beginning of the game (the player should always start at 0,0 (2) loop: DRAW THE MATRIX MOVE THE WUMPUS let the PLAYER MOVE CHECK FOR GAME-ENDING CONDITION (3) keep track of and output the total number of moves the human player has made in this game and output that total at the end: "You killed the wumpus in only %d moves!\n" "The wumpus ate you after %d moves!\n" USE LOOPS WHEREVER POSSIBLE! Good news! All you are responsible for writing is the main body of the program. You may use the following functions to handle all movement. Drawing the matrix and handling player moves is up to you. usage: int wumpus_x = 0; int wumpus_y = 0; . . movewumpus(&wumpus_x, &wumpus_y); /* moves the wumpus to a new square */ You need to include, and . The first line of your program after declaring your variables MUST read: srand(time(0)); Other than that, the program is up to you. Here is the wumpus move function prototype: void movewumpus(int*, int*); and here is the function body: void movewumpus(int* x, int* y) { *x = rand() %4; *y = rand() %4; } SAMPLE GAME OUTPUT: (your program should look like this, but close is FINE.) Welcome to Hunt the Wumpus. 0 1 2 3 _______________________ | | | | | 0 | P | | | | |_____|_____|_____|_____| | | | | | 1 | | | | | |_____|_____|_____|_____| | | | | | 2 | | | W | | |_____|_____|_____|_____| | | | | | 3 | | | | | |_____|_____|_____|_____| Player, what is your move (enter x,y)? 1,1 Wumpus moves to 3,0. 0 1 2 3 _______________________ | | | | | 0 | | | | W | |_____|_____|_____|_____| | | | | | 1 | | P | | | |_____|_____|_____|_____| | | | | | 2 | | | | | |_____|_____|_____|_____| | | | | | 3 | | | | | |_____|_____|_____|_____| Player, what is your move (enter x,y)? 2,1 Wumpus moves to 2,1 0 1 2 3 _______________________ | | | | | 0 | | | | | |_____|_____|_____|_____| | | | | | 1 | | | W | | |_____|_____|_____|_____| | | | | | 2 | | | | | |_____|_____|_____|_____| | | | | | 3 | | | | | |_____|_____|_____|_____| Player, the wumpus ate you after 2 moves! % Hints: Since the wumpus moves randomly, you may find it useful to stop moving the wumpus altogether until you're finished with the game logic (or to always make the wumpus move one square to the left every turn). You should test and remove the wumpus if botht he player and wumpus start the game in 0,0. You don't need to use an array to store the matrix -- all you care about is the position of the wumpus and the position of the player. Start your program by copying and pasting the following: #include <stdlib.h> #include <stdio.h> #include <time.h> void movewumpus(int*, int*); int main() { /* variables here */ /* initialize player, wumpus here */ /* game loop here */ /* draw current matrix */ /* accept a player move (make sure it's legal! */ /* move the wumpus */ /* check victory conditions */ /* loop until...? */ return 0; } void movewumpus(int* x, int* y) { *x = rand() %4; *y = rand() %4; }
graphics images Copyright 1998-2003 Elizabeth Fraley HTML code copyright 1998-2003 Elizabeth Fraley. Permission is given to provide these pages in their original, unaltered form online for educational purposes. They may not be republished or included on a CDROM, disk or other media or with any published work without the express permission of the copyright holder (this includes FAQ books).