CS139
Algorithm Development
|
Software
Requirements Specification
Programming Assignment 5
The Game of Rats!
Due Thursday Nov 19, by 11:00pm
See updates highlighted in Yellow that were
made on Monday Nov 16. (NOTE: Change to Player class. A
player needs a way to reset their score at the end of the game.)
Introduction
Purpose: The
game of Pig is a dice game played with two dice. This game,
Rats!, is a variant of that game played with human or computer players.
In the game, players take turns throwing two dice. They keep
score using the face value of the dice. The first player to reach 100
points wins. On each turn, the player may throw both dice and
record the number of points shown on the dice. They can
choose to continue to throw the dice or relinquish their turn to the
next player. If they relinquish the dice, the total number of
points for that turn are added to their overall score. If
they hog the dice (be a Rat) and throw "Rat's Eyes" (double 1), then
they lose all of the points that they accumulated that turn. Anytime
Boxcars (double 6's) are thrown, accumulated points are added to the
total score for that player and the player must relinquish their turn.
Play continues until one player reaches 100 points.
If the first player reaches 100 points, the second player
does not get a turn.
Objectives - At the
conclusion of this exercise the student will demonstrate that they can:
- Use looping to solve
specific categories of problems.
- Use objects to represent
parts of the application
- Use methods written into a
Toolkit in a prior exercise.
- Precisely follow
specifications for methods.
- Do everything necessary to
create, debug, and run a java program.
- Use comments to delineate
each section of the program.
- Adhere to a Style Guide.
- READ
AND FOLLOW DIRECTIONS!!!!!
Deadlines
- Submit: Thursday, Nov 19th,
2009
by 11:00pm.
- Report: Monday, Nov 30th,
2009
at
the beginning of class. A late penalty will apply for
each of the 2 deadlines. If the submit is late, the report is due the
next class or lab session day after successful submission.
Programs will not be accepted after 7 days late.
Prerequisites
You have covered the material
about classes and objects in Gaddis, Chapter 6 and 9.
Application
Structure
Your application will consist of a number of different classes each
with its own specific purpose. More detail will follow below -
See the links for the "Starters" for all programs.
Rats
- Will set up the game and call the playGame method.
RatGame
- Will carry out the actions of game play.
Player
- Holds the name and the
score for each player.
RatDice
- This class is provided for you and contains the methods to get the
sum of the thrown dice and to see if RatsEyes or Boxcars are thrown.
Application Behavior
- The
application announces the game. (see output below
for all output statements).
- The application requests
from the user the number of players.
- If a non-integer value is
entered, display an error message and reprompt the user.
- If a number other than one
or two is entered, display an error message and reprompt the user.
- The application requests
from the user the names of each player and creates a Player object for
each one.
- If only one player, ask
for the name for player 1, and then create a human player and a
computer player. (The computer's name is "HAL").
- If two players, ask for
the name for each player, and create two human players.
- The application than creates
the game and begins play.
- To determine who starts,
each player in turn throws the dice starting with player 1. The
player with the
highest roll goes first. Play alternates between each game.
For example, if we have a human and computer player ("Dave"
and "HAL"), if Dave rolls higher, he goes first in game one, second in
game two, first in game three, etc. In case of a tie, rethrow the
dice until one player has a high throw. Announce each throw and who is
going first.
- Throw the first dice for the
first player and announce the roll. If the player is the
human player, ask if they want to throw again. Continue
throwing until:
- the user says that they
want to relinquish the dice. (Y or yes or any variant of
these). All accumulated points in this turn are added to
their total points.
- RatsEyes are rolled.
All accumulated points are lost.
- Boxcars are rolled.
The boxcar points are added to the turn points and then turn
points are added to the accumulated points.
- Turn points +
accumulated
points reach or exceed 100 for this player.
If the player is the computer player, continue to throw until:
- the computer accumulates
more than 20 points in this turn.
- RatsEyes are rolled.
All accumulated points are lost.
- Boxcars are rolled.
The boxcar points are added to the turn points and then turn
points are added to the accumulated points.
- Turn points +
accumulated
points reach or exceed 100 for this player.
- Repeat
step 6 for the second
player.
- Repeat steps 6 and 7 until one of the player wins.
- Announce the winner and the points accumulated by both players.
- Ask if the players want to play again.
- If yes or y (ignoring case), reset all points totals to zero for
both players. Resume play at step 6. (See step 5 for
alternating turns).
- If no, thank the players for playing and exit.
Output Statements
Program
Behavior
Reference |
Output
printf statement |
parameter
1 |
parameter
2 |
parameter
3 |
parameter 4 |
1 |
"Welcome
to the game of Rat\n\n" |
|
|
|
|
2 |
"How many players today? " |
|
|
|
|
2 |
"\n" - After
reading in the value. |
|
|
|
|
2.a |
"Bad
value %s\n" |
bad input value |
|
|
|
2.a |
"This is not an integer. Try again.\n" |
|
|
|
|
2.b |
"You may only play with one or two players.
Try again.\n" |
|
|
|
|
3 |
"What
is the name of player %d: " |
1 or 2 depending on which player we need the name for |
|
|
|
3 |
"\n" - After
reading in the value. |
|
|
|
|
5 |
"%s rolls %d-%d, %s rolls %d-d, %s goes
first\n"
OR "%s rolls %d, %s rolls %d, TIE throw
again\n" - if both players throw the same value. |
player 1 name and throw
(throws will always be shown as x-y where x is die one and y is die two) |
player 2 name and throw |
first player to go |
|
6 and 7 |
"%s rolls %d-%d\tturn %d total %d\n" OR "%s rolls %d-%d - RATS! total %d\n" OR "%s rolls %d-%d - BOXCARS! turn %d total %d\n" -
The
first is for most rolls, the second for RatsEyes and the third for a
roll of Boxcars. |
player name |
throw |
turn accumulated points (not used for RatsEyes) |
total points including the turn total |
6.a |
"Give up the dice? " |
|
|
|
|
6.a |
"\n"- After
reading in the value. |
|
|
|
|
9 |
"\n%s WINS!\t%s points %d\t%s points %d\n" |
winning player name |
player 1 name then points |
player 2 name then points |
|
10 |
"Do you want to play again? " |
|
|
|
|
10 |
"\n"- After
reading in the value. |
|
|
|
|
12 |
"Thanks for playing RATS! Good bye\n" |
|
|
|
|
Toolkit
changes
You should use your toolkit to verify the number of players for the
game. There are no changes required.
Additional Program Requirements
- The RatGame constructor requires a seed value for the random
generator used in the RatDice class. This seed will come through
as a command line argument. (See book Chapter 8.12 or hardcode
one in your RatDriver and come to class on Monday Nov 16 for more
information). If
there is no argument or the argument provided is not an integer, use
the seed value of 0.
- You will use the
starter classes for RatGame and Player provided.
- You must use
the RatDice class provided and may not make any changes to it.
- You may NOT use recursive method calls to playGame.
Instead, playGame should loop for successive games.
- All input and output will be done in RatDriver, RatGame, and
Toolkit except for the question about taking another turn which is done
in the player goAgain method.
You must use the programs as stated above. You may not make any
changes to the RatDice class.
Honor Code
This work must conform to the
JMU Honor Code and the specific requirements
of this class. NO help may be provided by any student to another
student.
Authorized help is limited to your textbook, the TAs for any
CS139
or CS239 section, and the professor for your section. See collaboration
policy.
Grading
- Your program will be
evaluated both by its correctness and conformance to the required
elements.
- You will achieve a grade of
80 for a program that runs correctly
and produces exactly the required output in the required format.
- The remainder (20 points)
will be
based on your conformance to the Style and other requirements of the
assignment. Review the Style
Guide before submitting your
program and the grade sheet which is produced by the submit system.
- All grades will be based on
100 points.
- You may submit any number of
times. The only one I will count is the one that corresponds to the
hardcopy report that you turn in.
- The hardcopy that you turn
in will be the formatted version that
I will check. Make sure it has no line wraps or other spacing
issues.
- Successfully submitted
programs that are late will be graded, then the late penalty is
assessed for each day late according to the following schedule.
For
submissions after:
- Nov 19 - 5 points
- Nov 20 at 5pm - 15 points
- Nov 29 - 25 points
- Nov 30 - 35 points
- Dec 1 - 45 points
- Dec 2 - 100 points
HINTS
- Work and test this code in pieces. Make the Player class
and use a test driver to test each of the methods, constructor,
toString, and each of the methods involved in game play. Then
work through the game, only playing one game. When one game is
working properly then add in the code for multiple games and the
alternating starting players.
- You must use a single
Scanner object for this problem.
Using multiple Scanner objects (calling the Scanner
constructor
with System.in multiple times) will result in a failure to read all of
the input in submit.
- Stub out your code and build
each method individually.
- You should build in extra printlns to use in debugging your code.
You can always comment these out or condition them with a DEBUG
variable.
- Start with the provided
code. We have built the shell of
the RatGame and Player classes
that you will use.
- To control the tests, build
a small program that will generate
the random numbers needed in this program. Use different
seeds to
generate different patterns that will allow you to test each player
going first, RatsEyes, boxcars, etc. See class notes from Monday
Nov 16 for more information.
- Begin early.
Students run into trouble by waiting too long to start the
program.
- Understand the problem at
hand. Make sure that you follow
the requirements precisely. Don't add additional
"flourishes".
You will be downgraded.
- Play the game with a friend before you design your code to
understand how the game will work. (This does not violate the
honor code even if the two players are in this class.)
- In the body of your main
method, outline your steps with comment lines for each part of the
project. Do the same with each of the other methods.
- If you wish to use
additional methods to break up your code, feel
free to do so. If you wish to add additional classes, feel free
to do so.