Sub-class Details
TictactoeGame
This is the main class where the game code begins.
Overriding the constructor:
public function TictactoeGame() {
new TictactoeSkinner();
}
Constructor is a good place to instantiate the game specific skinner class, more on implementing the skinner class is discussed later.
Override the getGameId method from PulseGame as follows:
public override function getGameId():String {
return "Tictactoe";
}
The pulse runtime needs a unique game id for each game, since many games could be hosted on a single server. This id is also used by server to match up other players playing the same game. Meaning players playing jigsaw will not be able to go into a room that is playing Tictactoe.
Overriding the start method:
import tictactoe.gsrc.client.GNetClientObjectFactory;
protected override function start():void {
var factory:GNetClientObjectFactory;
factory = new GNetClientObjectFactory();
m_netClient = new GameClient(factory, this);
s_instance = this;
super.start();
}
Start method is where it all begins. A factory object must be created as shown above. The factory class is one of the classes that is created for you during code generation.
The Game Client should also be created with the instance of factory passed in. The new GameClient must be assigned to m_netClient field that is defined in PulseGame class.
Only one GameClient instance is required. Finally, the super.start() should be called, so the splash screen is displayed and then fades away to take the player to the login screen.
At this point the player will be presented with a login screen. The player can either enter a registered username and password or login as guest.
Creating custom classes for the game:
protected override function initGameScreen():void {
m_gameScreen = new TictactoeGameScreen(this);
m_gameScreen.init();
}
The above two override are needed to create game specific screens, one for during new room creation and the other during game play.
Turn based:
Since tictactoe is defined to be a turn-based game (see sub-class details of TictactoeNewGameScreen), the Pulse Server fires a callback to let the client know that it now the players turn, during this time, a visual hint should be displayed to the player.
public override function onPlayerTurn():void {
(m_gameScreen as TictactoeGameScreen).onPlayerTurn();
}
The logic here is simply to call the game screen to display the hint.
Server Communication:
public override function onGameStateAction(gameState:GameStateClient):void{
(m_gameScreen as TictactoeGameScreen).onPlayerMoved(gameState);
}
public function sendGameState(xPos:int,yPos:int,value:int):void {
var putMsg:PutClient = new PutClient();
putMsg.setStateType(GameConstants.GS_IS_UNIQUE);
putMsg.setPutRow(xPos);
putMsg.setPutColumn(yPos);
putMsg.setPutValue(value);
m_netClient.sendGameStateAction(putMsg);
m_netClient.nextTurn();
}
There are two methods that need to be implemented, one to receive the action of another player and the other to send the action to the other player.
To receive the action of another player, we simply override and the onGameStateAction and pass it to the game screen.
To send up the player action, we write a convenience method sendGameState that is called by the game screen object. During this time, we also tell the server that the player turn is done so the server can inform the next players turn. Note that the the PutClient was defined in the schema file and generated during code gen phase.
For more information on the types of game states available, please refer to the pulse developers guide.
| » Level Intermediate |
|
Added: 2009-02-21 Rating: 7.35 Votes: 17 |
| » Author |
| Prashanth Hirematada is the founder & Chief Architect of Gamantra, a game technology company. |
| » Download |
| Download the files used in this tutorial. |
| Download (0 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!