First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Prashanth Hirematada | Website: http://www.gamantra.com/pulse/

Sub-class Details


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;

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);

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();

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.04 Votes: 28
» 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!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
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: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.