CPE 101
Iteration and Selection Lab
Objectives
Problem Description
You will be developing a simple guessing game called Hurkle. The Hurkle is an imaginary creature that hides somewhere in a two-dimensional 9x9 integer game-space. Each time the game is run the program places the Hurkle at a random position in the game-space (a row and column pair) and the player has a maximum of five (5) guesses to guess the Hurkle s location. The Hurkle does not move during the game. If the player finds the Hurkle, the program reports the success and ends. If the player does not find the Hurkle the program gives a hint about what direction to the player move to find the Hurkle. The hint must be correct and the optimal direction the program doesn t lie or mislead the player! There are eight possible hints: north, northeast, east, southeast, south, southwest, west, and northwest. The program must detect guesses that are not in the game-space and re-prompt until a valid value is given (invalid guesses don t count as one of the five).
Except for a few explicit requirements (specified below), the program design - both the code and the look-and-feel - are up to you. To receive full credit the program should display a map of the game-space that looks very similar to the example below and contain all of the same information, i.e., map row and column values, and compass directions. This map only has to be displayed once at the beginning of the game. You should design a user interface that is easy to use and plays well have fun and be creative!
Be sure to read the Given, Suggestions, Constraints, and Grading sections below before you begin to write any code.
NORTH
0 1 2 3 4 5 6 7 8
-------------------------------------
0 | | | | | | | | | |
-------------------------------------
1 | | | | | | | | | |
-------------------------------------
2 | | | | | | | | | |
-------------------------------------
3 | | | | | | | | | |
-------------------------------------
WEST 4 | | | | | | | | | | EAST
-------------------------------------
5 | | | | | | | | | |
-------------------------------------
6 | | | | | | | | | |
-------------------------------------
7 | | | | | | | | | |
-------------------------------------
8 | | | | | | | | | |
-------------------------------------
SOUTH
Given
To place the Hurkle in a random place in the game-space you will need to obtain random numbers for its row and column. To do so you should use the provided code below. Your instructor will likely discuss pseudo-random numbers and their generation in lecture or lab. Using them is relatively easy, first you must initialize the C-Standard Library s random number generator by calling the function srand once (with a nested function call to the function time, then you call the function rand any time you need another random number. So, place the following function call in your code so that it executes only once and before you obtain the Hurkle s position:
srand(time(0));
Any time after the srand call above you may call the function rand to get a different pseudo-random number between 0 and a constant RAND_MAX (a large to very large integer value that depends on the compiler implementation)
int row;
row = rand();
Notice that you probably want values between 0 and 8 (9 unique values) for row and column values in the game-space. Think about how you might use the modulus operator (%) to modify the value returned by rand to do that.
To be able to use the srand, rand, and time functions be sure to include the following header files:
#include <time.h>
#include <stdlib.h>
Suggestions
Constraints
Grading
Handing in Your Source Electronically
handin graderjd Lab06 hurkle.c