Packagecom.presenttechnologies.phunegaming.client.platform.view.game
Classpublic class GameRoot
InheritanceGameRoot Inheritance starling.display.Sprite

Base class for the game root. The game developer should extend this class when creating a game.

GameRoot usage:

  1. Create a class that extends GameRoot (e.g. GameRootImplementation)
  2. Override public functions to handle messages
Example:
     //It should extends GameRoot. The GameRoot extends a starling.display.Sprite.
     public class TictactoeImpl extends GameRoot 
     {
     
         //constructor
         public function TictactoeImpl(){ 
                 
             //Create the graphics for game (for example)
             _theme = new OriginalTheme(this);
             
             //call super class with default values. It creates the default header with the players and avatars 
             super();
     
         }
     
         //override function to receive players after the match making process
         override public function matchPrepare(players:Array, me:Number):void
         {
             
             //call the function in extended class
             super.matchPrepare(players, me);
             
             //Create the screen (for example)
             _playScreen  = new PlayScreen();    
     
             //add the screen to display list 
             addChild(_playScreen);
     
             //inform the phune gaming server that is ready to receive moves.
             ready(true);
         }
     
         //The match will start after receiving this event
         override public function matchStart(isMe:Boolean):void 
         {
             //call the function in extended class
             super.matchStart(isMe);
         
             //start the match in UI (for example)
             _playScreen.matchStart(isMe);
         }
     
         //received after sending a play to the server. the plays will be evaluated in the server.
         override public function confirmPlay(success:Boolean, playData:String, evaluationContent:String, nextPlayerId:Number):void 
         {
             //call the function in extended class
             super.confirmPlay(success, playData, evaluationContent, nextPlayerId);
         
             //If not succes (invalid move) 
             if (!success) {
                 //The UI should retract the move.
                 _playScreen.retractMove();
             }
         }
     
         //Received after an opponent play.
         override public function oponentPlay(playData:String, evaluationcontent:String, playerId:Number, nextPlayerId:Number):void 
         {
             //call the function in extended class
             super.oponentPlay(playData, evaluationcontent, playerId, nextPlayerId);
         
             //Convert the move to an object (in this example is in json format)
             var move:MoveVO = UtilService.jsonDecode(playData, MoveVO);
         
             //update UI
             _playScreen.opponentMove(move.posY + move.posX);
         }
     
         //received in the end of match.
         override public function endMatchResult(winContent:String, isTie:Boolean, playerWinner:Number):void 
         {
             //call the function in extended class
             super.endMatchResult(winContent, isTie, playerWinner);
         
             //If it´s not tie it should update the UI (in this example)
             if(!isTie){
                 _playScreen.endMatch(winContent);
             }
         }
     
         //example function that the UI will call the platform
         private function doPlay(index:int):void
         {
             //Create the move Object
             var move:MoveVO = new MoveVO();
             move.className = "Move";
             move.posX = index % 3;
             move.posY =  Math.floor(index / 3);
         
             //Stringify the object (convert a AS3 object to a json object format)
             var jsonObject:String = JSON.stringify(move);
         
             //Call the GameRootsend doPlay function to send the play to server the play
             doPlay(jsonObject, true);
         }
     }
     
Notes:

The game developers should be responsible to free objects created for the game, by setting objects to null or calling delete



Public Properties
 PropertyDefined By
  me : Number
My player id.
GameRoot
  phuneGameHeader : PhuneGameHeader
The header of the game.
GameRoot
Public Methods
 MethodDefined By
  
GameRoot(phuneGameHeader:PhuneGameHeader = null, headerArea:Number = 0)
Constructor.
GameRoot
  
confirmPlay(success:Boolean, playData:String, evaluationcontent:String, nextPlayerId:Number):void
Received after sending a play.
GameRoot
  
endMatch(endMatchData:String):void
Received when a end match is received
GameRoot
  
endMatchResult(winContent:String, isTie:Boolean, playerWinner:Number):void
Received when a final result of a game in a normal play.
GameRoot
  
matchMakingTimeout(hasBot:Boolean):void
Received when a timeout occurred and the platform request to user a decision.
GameRoot
  
matchPrepare(players:Array, me:Number):void
Received when a match making is occurred.
GameRoot
  
matchStart(isMe:Boolean):void
Received for first move
GameRoot
  
onUserDefinedMessage(isMe:Boolean, content:*, result:*):void
Receive messages specific to game (other then move).
GameRoot
  
oponentPlay(playData:String, evaluationcontent:String, playerId:Number, nextPlayerId:Number):void
Received when a play from an opponent is received.
GameRoot
Protected Methods
 MethodDefined By
  
Dispatched to a explicit cancel of a match.
GameRoot
  
close(reason:String = null):void
Dispatched when the game is ready to be closed.
GameRoot
  
doPlay(playData:String, isPlay:Boolean):void
Dispatched when the game needs to do a play.
GameRoot
  
ready(ready:Boolean):void
Dispatched when the game is ready to be shown (normally after configuration).
GameRoot
  
sendUserDefinedMessage(content:*, publicAnswer:Boolean = false, requiresConcurrencyControl:Boolean = true):void
Send messages specific to game (other then move).
GameRoot
Property Detail
meproperty
public var me:Number

My player id.

phuneGameHeaderproperty 
phuneGameHeader:PhuneGameHeader

The header of the game. It can use de generic implementation of the Phunegaming or extend it.


Implementation
    public function get phuneGameHeader():PhuneGameHeader
    public function set phuneGameHeader(value:PhuneGameHeader):void
Constructor Detail
GameRoot()Constructor
public function GameRoot(phuneGameHeader:PhuneGameHeader = null, headerArea:Number = 0)

Constructor.

Parameters
phuneGameHeader:PhuneGameHeader (default = null) — The instance of the game header. If it´s not defined (null) it will assume the default implementation with the default values.
 
headerArea:Number (default = 0) — The area defined in the top. The header wil be centered in this area.
Method Detail
cancelMatch()method
protected function cancelMatch():void

Dispatched to a explicit cancel of a match.

close()method 
protected function close(reason:String = null):void

Dispatched when the game is ready to be closed. The Game devs should not override this method

Parameters

reason:String (default = null) — The reason (if any) to be closed.

confirmPlay()method 
public function confirmPlay(success:Boolean, playData:String, evaluationcontent:String, nextPlayerId:Number):void

Received after sending a play. It will be evaluated in the server and a response is received.

Parameters

success:Boolean — If the play was a success.
 
playData:String — The move after evaluatition from the server (can be changed from the original move sent).
 
evaluationcontent:String — The content evaluated in the server.
 
nextPlayerId:Number — Confirm if it´s your trun by checking if (nextPlayerId==me).

doPlay()method 
protected function doPlay(playData:String, isPlay:Boolean):void

Dispatched when the game needs to do a play. The Game devs should not override this method

Parameters

playData:String — The object of play defined as a string (eg. JSON).
 
isPlay:Boolean — If is a play to be send to the server (delivery guarantee) or if it´s a peer to peer mesage to be sent to the opponents (no delivery guarantee).

endMatch()method 
public function endMatch(endMatchData:String):void

Received when a end match is received

Parameters

endMatchData:String — the end match object defined as a string (eg. JSON)

endMatchResult()method 
public function endMatchResult(winContent:String, isTie:Boolean, playerWinner:Number):void

Received when a final result of a game in a normal play.

Parameters

winContent:String — The content sent from the server to the game.
 
isTie:Boolean — Tie result.
 
playerWinner:Number — The winner player id (if it´s not a tie).

matchMakingTimeout()method 
public function matchMakingTimeout(hasBot:Boolean):void

Received when a timeout occurred and the platform request to user a decision.

Parameters

hasBot:Boolean — If the game has a bot to be played as standalone

matchPrepare()method 
public function matchPrepare(players:Array, me:Number):void

Received when a match making is occurred. The game receives the list of players. After UI update the game should call the app ready.

Parameters

players:Array — The list of players [com.presenttechnologies.phunegaming.client.platform.model.vo.PlayerVO] in the match.
 
me:Number — My player id.

See also

matchStart()method 
public function matchStart(isMe:Boolean):void

Received for first move

Parameters

isMe:Boolean — If it´s my turn to play.

onUserDefinedMessage()method 
public function onUserDefinedMessage(isMe:Boolean, content:*, result:*):void

Receive messages specific to game (other then move).

Parameters

isMe:Boolean — If it´s a message from my user
 
content:* — The content received
 
result:* — The result received

oponentPlay()method 
public function oponentPlay(playData:String, evaluationcontent:String, playerId:Number, nextPlayerId:Number):void

Received when a play from an opponent is received.

Parameters

playData:String — The play object defined as a string (eg. JSON)
 
evaluationcontent:String — The player responsible for the play.
 
playerId:Number
 
nextPlayerId:Number

ready()method 
protected function ready(ready:Boolean):void

Dispatched when the game is ready to be shown (normally after configuration). The Game devs should not override this method

Parameters

ready:Boolean — If the game is ready

sendUserDefinedMessage()method 
protected function sendUserDefinedMessage(content:*, publicAnswer:Boolean = false, requiresConcurrencyControl:Boolean = true):void

Send messages specific to game (other then move). The Game devs should not override this method

Parameters

content:* — The content defined by the game (eg. JSON).
 
publicAnswer:Boolean (default = false) — If the response is sent to all the users in the match or only to the originator.
 
requiresConcurrencyControl:Boolean (default = true) — If requires a synchronization in the server.