472 | Chapter 13: Symmetric Proxy Pattern
- Reset the game variables to the beginning conditions. Because the players
have been keeping track of who has moved, which moves were selected, and
which player was declared the winner, all the variables keeping track of
these different states have to be cleared.
Each operation will be cast as a method and then arranged into an order that consti-
tutes the template method. Following the Hollywood Principle (see Chapter 9), the
Referee instance will make calls on the Player objects.
Now that we have a referee, we need to look at the relationship between the players
and the referee. Figure 13-2 is an object diagram for a two-player game with a referee:
Just like a non-virtual game, the single referee makes decisions about the game out-
come for two or more players. At this point, the game is immaterial—it could be any
game. Looking at the object diagram, it’s not difficult to imagine two or more play-
ers interacting on a single host (computer). In fact, if the goal were to create a game
where one of the players is the computer and the other’s a user interacting through a
UI, our job would be done. In a game ofRock, Paper, Scissors, a random move gener-
ator could easily be one of the two players. However, because we want to play the
game over the Internet, we have a few more steps.
The Internet, Proxies, and Players
As soon as we introduce remote players over the Internet, everything changes. Each
player makes a move, that move is sent over the Internet, and the referee decides the
outcome, displays it, and then cleans everything up. With serial turn taking, the
problem may not be as daunting because after each move, both players can see the
other’s move. The referee can wait until the first win condition is met and then send
messages to all players. However, this can get messy because you have to decide
where the referee’s going to reside. The referee could be placed on the host with the
first player to start. The second player would be referenced through a proxy.
Another solution would be to place the referee on its own server, and, while work-
able, this requires that the moves travel over the Internet twice. Also, depending on
the server, the basic game design may have to be changed to accommodate what the
referee looks like.
Figure 13-2. Referee and players
Referee
Player 1 Player 2