Simultaneous Game Moves and Outcomes | 471
- Indicate that a remote player has made a move (onProxyMove). Records the
move of the remote player, and prevents a further move by the remote player
until the next turn. - Send the local player move to the remote player (doMove). The move will be
picked up by the opponent’sonProxyMove method. - Conclude the turn after both players have moved (takeTurn). Once both
players have moved, the moves are turned over to the Referee to determine
who’s won and reset the values for the next turn. - Prevents play until both players are connected (numConnect). This method
has the dual function of letting players know of each other’s presence, and
prevents a move if only one player’s present.
By first working out the basics of a move and a turn, we’ve laid the basis for turn-
based games. The next step is putting the moves into a game context.
The Referee
In order to keep everything fair and fun, we need a referee. The class diagram for the
referee in relationship to the player can be seen in Figure 13-1:
Essentially, the referee will be a class containing the rules of the game encased in a
template method. As a design pattern, the methods need to be fairly general, in case
we want to reuse the sameRefereeclass for another game. Using a template method,
we can order the operations in the methods to launch in sequence, but we want flexi-
bility for other games. So, we begin with a list of operations for the referee that
applies to all games:
- Evaluate the moves and determine who won. All games need a set of win-
ning conditions and the ability to determine which player won, which lost or
whether they tied. - Display the results of the game. Once the results have been calculated, they
must be communicated to all players.
Figure 13-1. Referee and Player class diagram
Player Interface
Referee Player