Game Development Reference
In-Depth Information
A factory object must be instantiated as shown previously and should be assigned
to m_netClient property. The factory class is one of the classes that is created under
the gsrc folder for us during code generation. The m_netClient is a protected
property of the PulseGame parent class.
We will also override two more methods; one is for the game screen where the
jigsaw game will be played, and the other is for the new game screen where a new
room will be created by the player.
protected override function initGameScreen():void {
m_gameScreen = new JigsawGameScreen();
m_gameScreen.init();
}
protected override function initNewGameScreen():void {
m_newGameScreen = new NewJigsawGameScreen();
m_newGameScreen.init();
}
Server communication
Since the parent class (PulseGame) implements the Pulse SDK's GameClientCallback,
all the notifications are processed by the parent class. For this game, we are
interested in knowing when a new (PieceMatch) game state is added.
public override function
onNewGameState(gameState:GameStateClient):void {
var gs:PieceMatchClient;
gs = gameState as PieceMatchClient;
trace("Received new game state.");
trace("sender: " + gs.getSenderId() +
" Id: " + gs.getId() +
" PieceId: " + gs.getPieceId() +
" Direction: " + gs.getDir());
// Up the score of the sender.
var av:GameAvatarClient;
av = m_netClient.getPlayer(gs.getSenderId());
if ( av == null )
return; // cannot find player!?
av.setScore(av.getScore()+1);
m_netClient.publishMyAvatar();
if ( gs.getSenderId() !=
m_netClient.getMyAvatar().getId() ) {
PieceSprite.
onPieceMatch(gs.getPieceId(), gs.getDir());
}
}
 
Search WWH ::




Custom Search