10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 13-1. ISymPlayer.as<br />

package<br />

{<br />

//Symetrical Proxy Interface<br />

import flash.events.Event;<br />

}<br />

interface ISymPlayer<br />

{<br />

function numConnect(cl:uint):void;<br />

function makeMove(event:Event):void;<br />

function doMove(s:String):void;<br />

function localMove(locMove:String):void;<br />

function onProxyMove(proxMove:String):void;<br />

function takeTurn( ):void;<br />

}<br />

At this point, we’ll provide a quick overview of what each method does. In order to<br />

get a mental image of what occurs, the functions are placed in the approximate order<br />

of their launch, except for the last one, which is part of the housekeeping chore of<br />

making sure that two players are connected to FMS prior to any move by either side.<br />

1. First, the numConnect( ) method checks to see how many clients are connected,<br />

and, if two are connected, it allows moves to be made by both players.<br />

2. The players select a move by pressing one of the three possible move buttons<br />

(Rock, Paper, or Scissors). Once a player selects a move, he presses a move button<br />

that fires the makeMove( ) method.<br />

3. The makeMove( ) function fires both the doMove( ) and localMove( ) methods.<br />

4. The doMove( ) operation calls the server to pass on the move to its proxy.<br />

5. The localMove( ) method first stores the move in a variable, and then sets a Boolean<br />

indicating the fact that the player has moved.<br />

6. Next, the onProxyMove( ) function responds to the server call of a shared object<br />

and acts like the localMove( ) method, except it’s on the player’s proxy.<br />

7. When either the localMove( ) or onProxyMove( ) indicates that both players have<br />

moved, the takeTurn( ) method acts to force a call from the Referee to determine<br />

the winner and reset the values for a new game.<br />

Some variation in the implementation of these methods determines whether moves<br />

can be taken simultaneously or serially.<br />

The Referee<br />

Because the Referee class is abstract, it’s relatively small. The methods are fairly general<br />

with the idea that they can be overridden; however, they must be purposely<br />

developed. Further, because they’ll be placed in a template method, they have to be<br />

478 | Chapter 13: Symmetric Proxy Pattern

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!