Project 4 Design Recommendations
It is recommended that you use the following classes in your program:
- The Die class - a modified version of the one from the textbook
is in the file Die.java. A method to
draw a Die object has been added. Currently the method only draws a
rectangle with the number on the face rather than the dots that are
on real dice.
- The PairOfDice class - a modified version of the class you wrote
in a post lab earlier in the semester is in the file
PairOfDice.java. A method to draw
the PairOfDice object has been added.
- A Player class to represent a player of the game. The class should
have the following instance data:
- an integer that keeps the overall score
- an integer that saves the first roll on each turn
- an integer that saves the maximum rolled so far in a turn
- a boolean that keeps track of whether or not it is this player's turn
- a boolean that indicates whether or not the player is a computer
The following methods should be provided:
- A constructor with a boolean parameter indicating whether or not
the player is a computer.
- A method that rolls the dice. The pair of dice should be sent to
the method as a parameter. This is the method that will be invoked
when a button is clicked on the GUI - it is where the logic for what
happens each time the dice are rolled. For the most part what happens
here is exactly the same for a human player and a computer. The
only difference is that the computer needs some strategy for quitting.
That strategy should be very simple.
- A method that updates the score - that is it adds the points for
the current turn to the overall score. Note that the points are only
added when the player decides to stop. You can also do anything else
that helps you keep track of the fact that the player's turn is over.
- Accessor methods that return the overall score and the first roll.
- Anything else you deem necessary.
- A class for the panel that the dice will be drawn on. See the
DrawSMPanel handed out in class. You can play with that by getting
the files DrawSMPanel.java,
SnowmanPanel.java, ,
and Snowman.java from the course web page.
- A class for the GUI panel. This class will have all the components
you use to construct the GUI and will have the listener class
nested in it. The components that are needed by the actionPerformed
method should be instance variables; the others should be local to the
constructor (see the ATM example from lab). For the game playing the
class should also have the following instance variables:
- a PairOfDice object
- a Player object for the computer
- a Player object for the person
The actionPerformed method in your listener needs to respond
to at least three buttons. The player needs to be given options to
either roll the dice or stop. In order for a person to see what the
computer is doing you need a button for the user to click to see
each of the computer's moves.
- A class that contains the main program that sets up the frame and
the main panel.
Extra Credit (10 Points): Control when the user can press the
buttons using the setEnabled method in the AbstractButton class.