The program will play a tournament of
Paper, Scissors, Rock. The tournament will begin with 16 players
(you will pick their names) and play four rounds. In a round each
player entering the round will play one game (so there will be eight
games in the first round). Each round after the first will be
entered by the winners of the previous round and hence have half the
number of players of the previous round. Round four will have two
players and the winner of this round will be the winner of the
tournament. In each round each player will have a
seed number from 0 to ((the number of players in the round) - 1).
Each round will begin with the number of the round displayed. The
round will then run in a loop which will terminate when all games for
that round have been displayed. On each pass the players who have
not yet played in the round will be displayed along with their seed
numbers. The user will pick a player by entering a seed number.
The program will then pair this player with another whose seed
number is ((number of players in the round) - (seed number of the first
player) - 1), and these two players will play a game of Paper,
Scissors, Rock. In case of a tie the players will play until one
of them wins.
Please read
here to see a sample
tournament before continuing.
Organization
Your program will have four classes, each in its own source file. The classes are:
- PlayerRecord
This class contains the information stored for a player. An
instance will be created for each player and is used only to store
information on the player.
- Game
This class contains the data and methods needed to play one game of
Paper, Scissors, Rock. No instances of this class will be
created. All of its members will be static and only one method, play, will be public. play will be called from the class Round.
- Round
This class will hold the data and methods to play one round of the
tournament. A new instance will be created each time a new round
is started. Its only public method (other than a constructor)
will be playRound which will play an entire round of games by repeatedly calling Game.play. The user will choose the order in which the games will be played. playRound will be called from main in class PSR.
- PSR
This class will store the names of 16 players and will run the tournament from main. It will call playRound for the rounds in a loop.
You should code the classes in the order in which they are described
below. Refer to the example at the link above to see what is to
be displayed.
Class PlayerRecord
This class contains three public instance variables and a constructor,
and is used to store data on an individual player. There is a
String instance variable,
name, to hold the player's name, and two boolean instance variables:
played (whether the player has played in the current round) and
won
(whether the player has won a game in the current round). The
constructor will takes a String parameter which is used to initiialize
name. The two booleans are initialized to
false.
Class Game
This class has only static members and its only public method is
play. Three integer constants ("
private static final int") will be defined: SCISSORS (0), ROCK (1), and PAPER (2) and a random number generator (instance of class
Random) will be created.
play will take two parameters, a (reference to)
playerRecord for each player.
play
will randomly choose PAPER, SCISSORS, or ROCK for each player then
determine the winner using the rule PAPER beats ROCK, ROCK beats
SCISSORS, SCISSORS beats PAPER. (Note: a simpler Paper, Scissors,
Rock game can be found at
http://cs.gmu.edu/~dnord/cs112/examples/PaperScissorsRock.java.)
The players' choices (along with their names) are displayed as
well as the winner or tie. If there is a tie (players make the
same choice) the game is repeated until one player wins. After
the game the boolean values of the
PlayerRecord instances are updated (
won according to the result of the game and
played gets
true
for both players). You should write other (private) methods to do
the work of finding a String representation for the integer constants
(for reporting in
play) and to determine the winner or tie.
Before continuing in the project you should write a
test driver
which will run your program so far. A test driver is a short
program used for testing and debugging which will call the method(s)
which you wish to test..
Do not continue in the project until you are certain that your
Game class works properly. You will not hand in your test driver as part the assignment.
Class Round
This class does most of the work for the program. It will have (private) instance variables
int playerCount for the number of players in this round, an array
PlayerRecord[] currentPlayers
of player records, one for each player in the current round, and a
(static) Scanner to take keyboard input from the user. The
constructor will take two parameters: the (integer) number of
players in the round (and assign this to
playerCount)
and an array of Strings. This array will have the names of the
players in the current round. The constructor will fill the
currentPlayers array with new instances of
PlayerRecord using the names from this parameter..
Each player will have a
seed number in the range 0 to
playerCount - 1 which is equal to its index in
currentPlayers. In real life seeds would be numbered from 1 to
playerCount
but we choose this numbering to make the coding less confusing.
You will write a (private) method which will display the names of
all of the players who have not yet played in this round (check the
played
member of its player record) preceded by seed numbers and another which
will display the names only of the players who have won in this round.
The
playGame
method in this class will play a single game.
It will first display a list of all players (prececed by their
seed numbers) in this round who have not yet played (call another
method for this) and then ask the user to choose a player by entering a
seed number. If the number entered doesn't correspond to a player
in this list keep asking the user until he or she gets it right.
The player is paired with the player whose seed is (
playerCount
- seed number of other player - 1) who will be the opponent.
Display the two players' names, saying that they will be playing
this game, and then call
Game.play passing the player records of the players as parameters.
The (public)
playRound method will call
playGame in a loop which will run
playerCount/2
times to play all games of the round. It will then display the
names of the winners of the round and return a String array with
the names of these winners. (This list will be used to play the
next round.)
Before continuing write a test driver (not to be submitted with your
project) to test and debug this class. It should create an
instance of
Round, passing a number such as 4, 8, or 16 (for
playerCount) and a String array with that many names to the constructor.
Do not continue in the project until you are certain that your Round class works properly.
Class PSR
This class has the
main. It will create an array of 16 names (you make them up) as a (static) instance variable. A String array
playersLeft will initially be this array of names.
main
will run in a loop which will play the rounds of the game. In
this loop it will first display the number of the round (1, 2, 3,
4) and then create and instance of
Round passing the number of remaining players and the String array
playersLeft to the constructor as parameters. It will then call
playRound for this instance and save the array it returns as
playersLeft in preparation for the next round (next pass through the loop).