CMSC 201
Programming Project Two
Rock - Paper - Scissors
Due Date: Before Midnight, 3/7/00
Clarification posted 2/21/00 7:40 PM
The Objective
The objective of this assignment is to give you practice
with top-down design and writing functions. You will also
write a sophisticated user interface and use the random number generator
The Background
In the old children's game called Rock-Paper-Scissors, each child
puts his hand behind his back. One child counts to 3. At the count
of 3, each child brings his hand forward. His hand is held to form
the shape of a rock (a fist), a piece of paper (held open and flat)
or a pair of scissors (index and middle finger wide apart). In
this game the winner is determined by the following rules.
If both children's hands are the same, it a tie.
Rock breaks Scissors
Paper covers Rock
Scissors cut Paper
|
The Task
Your assignment is to write a program that simulates playing
Rock-Paper-Scissors. The user will be one player and your program
("the system") will be the other player.
After an appropriate greeting, your program will prompt the user
for a random number "seed" value, then display the following menu:
R -- Choose Rock
P -- Choose Paper
S -- Choose Scissors
G -- Display current Game statistics
H -- Display this Help menu
Q -- Quit
If the user enters R, P or S, your program will play the game
by randomly choosing Rock, Paper or Scissors, then determining if the
player wins, the system wins, or there is a tie. Your program will accumulate
the number of wins, losses and ties for the player. This information will
be displayed when the user chooses G (Game stats) or Q (quits). Your program
must accept both upper and lowercase input. If your program detects
an invalid menu choice, it should respond with an appropriate error
message, then display the menu.
Clarification 2/21/00
When using random numbers to represent Rock, Paper, Scissors, you MUST
use the following values. If you use any other values, you (and the grader)
will not be able to match the sample output.
Use 1 for Paper, 2 for Rock and 3 for Scissors
Assumptions
- Because entering characters one a time can be tricky, your program
may assume that the user will type just one character and ENTER.
- You MAY NOT assume that the character which is typed will be valid.
Your program must be robust and handle invalid menu choices.
Hints
- When using scanf to input characters, you must deal with
the NEWLINE character that is present when the user hits the ENTER key.
There are several methods of handling this problem, two of which are
described below.
- In each scanf, read in an extra character (the NEWLINE)
into a variable called newline which is never used.
char choice, newline;
scanf ("%c%c", &choice, &newline);
- Call the function fflush after every scanf
as in
the following code fragment. The function call fflush (stdin);
will throw away
all characters that were typed after the 1st character, including the NEWLINE
char choice;
scanf ("%c", &choice);
fflush (stdin);
This issue will be discussed in more detail in discussion class.
- The random number seed is used as a parameter to srand
to initialize the random number generator. Call srand
ONLY ONCE. You request a random number from the random number
generator by calling rand ( ). Do this whenever you need
a randomw number. srand and rand
will be covered in more detail
in your discussion session. You may learn more about them from
the Unix man pages.
Sample Run
New sample output posted 2/22/00 3:15PM
Although your output need not be identical to the above,
all information (including the greeting) must be present.
Submitting the Program
Your C source code file for this project MUST be called
proj2.c.
To submit your project, type the following at the Unix prompt.
Note that the project name starts with uppercase 'P'.
submit cs201 Proj2 proj2.c
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show all files that
you submitted in a format similar to the Unix 'ls' command.
submitls cs201 Proj2