Game Development Reference
In-Depth Information
Multiplayer and networking
Interestingly, we don't try to keep individual piece positions synchronized across
players. We only broadcast a message to all the players in the room when two or
more pieces were matched by any of the players. This implementation also does not
change the piece's or group's movement in real time, although this could be done.
Imagine if all the pieces moved around because of other players; it would just be
plain distracting.
We only send the piece ID and the direction in which the match was made. If two
groups of pieces were matched, then for each matching edge we would send
a message.
The Schema file for the game is listed below:
<ObjectSchema>
<import>
<client import="pulse.gsrc.client.*" />
</import>
<class name="PieceMatch" parent="GameState" classId="600" >
<public>
<property name="pieceId" type="int"/>
<property name="dir" type="int"/>
</public>
</class>
</ObjectSchema>
The schema file defines one game state called PieceMatch , which contains two
properties as follows:
pieceId —Uniquely identifies the piece
dir —The direction, four possible values
As we can see, the information exchanged between the players within the room
is quite simple. Let's now look at the code that is responsible for sending this
information to other players and the code that receives it and how it is dealt with.
When the player moves a piece or a group of pieces and if we find that two pieces
were matched (refer _checkMatch method), then we call the _sendPieceMatch
method as follows:
private function _sendPieceMatch(dir:int):void {
// Create a new instance of the game state
var gs:PieceMatchClient = new PieceMatchClient();
 
Search WWH ::




Custom Search