First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Prashanth Hirematada | Website: http://www.gamantra.com/pulse/

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 player’s 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 player’s 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 developer’s guide.

» Level Intermediate

Added: 2009-02-21
Rating: 6.48 Votes: 23
(10 being the highest)
» Author
Prashanth Hirematada is the founder & Chief Architect of Gamantra, a game technology company.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

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

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.