Game Development Reference
In-Depth Information
GameStateSprite class
This is a simple helper class to aid us in rendering a game state on the game screen.
This is the class that takes the form of a colored circle. The constructor takes a
HelloGameStateClient and initializes the color based on the ID of the game state.
Instances of these are created by the game screen class that we will visit next. A new
instance is created whenever we receive a message from the server that a new game
state has been added to the game room.
package hw.ui
{
import flash.display.Sprite;
import hw.gsrc.client.HelloGameStateClient;
public class GameStateSprite extends Sprite
{
public var m_gs:HelloGameStateClient;
public function GameStateSprite(gs:HelloGameStateClient)
{
super();
m_gs = gs;
var color:uint;
if ( gs.getId()%2 )
color = 0xFF0000;
else if ( gs.getId()%3 )
color = 0x00FF00;
else
color = 0x000FF;
graphics.beginFill(color, 0.5);
graphics.drawCircle(0, 0, 25);
graphics.endFill();
}
}
}
General flow of events
When a client adds, updates, removes, or sends game states to the server, all the
clients will receive the state update, including the client that sent it.
We should defer taking any action on the sending client in case the server rejects
the request. In case the server validation fails, the sending client will receive a
corresponding notification. For validation rules regarding the game state types and
room states, refer to the previous section.
 
Search WWH ::




Custom Search