Java Reference
In-Depth Information
Designing class ClockGame
An instance of class ClockGame will have methods that allow a game to be
played. This will involve a player, a clock, and a clock window that will contain
the clock and a label that displays details of the game.
The constructor of the clock game will create the player, clock, and clock
window. It will initialize the player by asking the player for their name and the
level at which they want to play.
The constructor constructs the game, getting it ready to play, but it does not
play it. For this, we write a method playGame . This completes the design of the
specification of ClockGame . See Fig. 3.16 for the specification.
Concluding remarks
This completes the design of the specification of Player and ClockGame .
The only object that we have not dealt with is the dialog box that opens when the
player is asked to give some input. You can see how this object is created when
you read the implementation of ClockGame .
We do not provide the implementations of Player and ClockGame here —
our emphasis is more on designing the classes than on providing their imple-
mentation. The classes themselves can be obtained from the ProgramLive CD.
Lesson page 3-
8 tells you how
to get the pro-
gram from the
/** An instance is a player practicing clock-reading. */
public class Player {
/** Constructor: player with name s , score 0 , and playing level lev */
public Player(String s, int lev) { }
/** = the name of the player */
public String getName()
{ return null ; }
/** = the current score of the game */
public String getScore()
{ return null ; }
/** = the level at which the player is playing */
public String getLevel()
{ return null ; }
/** Increment the score (and level if necessary) */
public void incrementScore() { ... }
/** = a representation of the player */
public String toString()
{ return null ; }
Figure 3.15:
Specification of class Player
Search WWH ::

Custom Search