ActionScript 3.0 Design Patterns

(Chris Devlin) #1
The Referee | 479

developed with an eye to the order in which they’ll be placed. We’ll begin with a


look at the Referee class to get an overview and then look at the methods for the


class. Example 13-2 shows the Referee class.


The comment at the top of the class indicating that the class is an abstract one is sim-


ply a comment. It stands as a reminder that ActionScript 3.0 has no real abstract


classes, and we need to remind ourselves to use overrides where needed. Likewise,


Example 13-2. Referee.as


package
{
//Abstract Class
public class Referee
{
//Move
private var p1Move:String;//Player 1's move
private var p2Move:String;//Player 2's move
private var winner:String;//Value for winner
private var outcome:String;//Describe winnder
private var displayWindow:DynamicText;
private var movecheck:Array;//Array to keep track of moves


//Template Method
final function moveComplete(p1Move:String,p2Move:String,
displayWindow:DynamicText,movecheck:Array):void
{
outcome=doWinner(p1Move,p2Move);
displayResults(displayWindow,outcome);
resetGame(movecheck);
}


//Abstract methods


protected function doWinner(p1Move:String,p2Move:String):String
{
return winner;
}
function displayResults(displayWindow:DynamicText,
outcome:String):void
{
displayWindow.setMove(outcome);
}
protected function resetGame(movecheck:Array):void
{
for (var r:uint =0; r< movecheck.length; r++)
{
movecheck[r]=false;
}
}
}
}

Free download pdf