Global Positioning System Reference
In-Depth Information
enterScenario();
...
}
Due to the decoupling of the client server, the developer can start the server
and then start random players on one or more JVMs.
We now go back to the details of the game at the state where the first
player-client has registered and entered the game.
12.8.2 Game Controller
The player factory in RandomPlayer creates a number of players to enter
the game. On the server side in LondonChase.enter(client) , you can
nd a Controller instance to represent the game master. The controller
should always have control over all game state and the involved classes.
Technically speaking, the controller serves as a monitor and is created with
the properties file.
The controller should be the main authority to dispatch the properties
to the application's components. In other words, the controller synchro-
nizes the game activities, and the vital methods have to be synchronized to
ensure clear states of the game. The developer should be aware that syn-
chronized methods are much more costly and should only be used, where
necessary. Generally, the synchronized keyword does not belong to the
method signature and can also be used on a higher overriding layer.
Once all players for one game are identified and have entered the game
at a station, the controller sets the list of authorized players, creates a
Callable to notify all players about the game start, and starts the game|
after returning from enter :
if ( allAboard ) { // lets play
controller.setAuthorizedPlayers( players );
Callable<Void> startGame = new Callable<Void>() {
...
notifyActors( status );
...
controller.startGame();
...
};
executorService.submit( startGame );
// submit and immediately continue
}
The controller changes its status from REGISTERING to PLAYING and notifies
all classes waiting for something to happen, for example, the GameThread .
A GameThread to run rounds and take turns. The GameThread is start ed with
the server construction and waits for the controller to start the game. Once
the game starts, it retrieves several settings relevant to each game and then
 
Search WWH ::




Custom Search