Game Development Reference
In-Depth Information
The new game screen is required to be customized only for the purpose of defining
the kind of room that is needed for the game. The above code is specific to the tic-
tac-toe game. The code creates a new room object instance, specifies that the player is
automatically set to ready when they join the room, sets up the room name for others
to see in the lobby, allows a maximum of two players into the room, specifies that the
room is turn-based, and finally requests the server to create the room. Once it is created
on the server, the room will appear in the lobby screen for other players to join.
TictactoeGameScreen
Lastly, there is the class where all the action happens inside of the game room, once
the game has started. This class is sub-classed from GameScreen class found in
PulseUI framework.
In order to implement the required game display, we define a helper class,
TictactoeHotspot , a subclass of sprite used for tracking the nine regions of the
game board and onto which we add a sprite child, either O or X, depending on the
player. We instantiate the nine objects of this class for each spot.
package tictactoe.game
{
import flash.display.Sprite;
public class TictactoeHotspot extends Sprite {
public var value:int; // who's clicked?
public var row:int; // my pos
public var col:int; // my pos
public var win:Boolean; // part of win?
public function TictactoeHotspot(c:int, r:int) {
value = 0;
col = c;
row = r;
win = false;
}
}
}
Additionally, TictactoeGameStatus is a simple class for holding constants required
for the game.
package tictactoe.game
{
public class TictactoeGameStatus
{
public static var CONTINUE:int = 100;
public static var HOST_WIN:int = 101;
public static var GUEST_WIN:int = 102;
 
Search WWH ::




Custom Search