package Checkers { import flash.events.Event; import flash.display.Sprite; import flash.events.EventDispatcher; import Checkers.logics.*; /** * Player Black * The Host is always Black (single player, player is Black) * @author Fan Di * Black player gets the first turn in the game and always on the bottom of screen * TODO */ public class SymPlayer implements ISymPlayer { protected static var dispatcher:EventDispatcher; private var _lives:int = 12; private var referee:RefereeAbstract; private var game:IGameView; private var move:Object; public function SymPlayer(r:RefereeAbstract, v:IGameView) { referee = r; game = v; } /* * Multiplayer Wrappers into the SymPlayerInterface * Send Game Object through Referee * Again this object(move) is defined by you */ protected function sendGameObject(obj:Object):void { dispatchEvent(new CheckersEvent(CheckersEvent.SEND_GAME_OBJECT, obj)); } /* * Multiplayer Wrappers into the SymPlayerInterface * On Receive Game Object * Again this object(move) is defined by you */ public function onGameObject(obj:Object):void { onProxyMove(obj); } /* * Checks how many lives left */ public function get lives():int { return _lives; } public function set lives(l:int):void { _lives = l; } /* * The player makes a move * fires both doMove() and localMove() * m comes from Game.as obviously since View does the controlling */ public function makeMove(m:Object):void { doMove(m); localMove(m); } /* * The player makes a move * operation calls server to pass on the move to its proxy */ public function doMove(s:Object):void { sendGameObject(s); } /* * The player makes a move * stores its move and sets a Boolean indcating the fact that the player has moved */ public function localMove(locMove:Object):void { move = locMove; takeTurn(); } /* * Responds to the server call of a shared object and acts like localMove() but on the player's proxy */ public function onProxyMove(proxMove:Object):void { move = proxMove; takeTurn(); } /* * Acts when either localMove or onProxyMove is called to force a call from referee to determine * the next outcome (update board, win/loose, reset game) * it should also update the status of the player */ public function takeTurn():void { referee.moveComplete(move, game); } /* * Event Dispatcher Wrap */ public function addEventListener(p_type:String, p_listener:Function, p_useCapture:Boolean=false, p_priority:int=0, p_useWeakReference:Boolean=false):void { if (!dispatcher) { dispatcher = new EventDispatcher(); } dispatcher.addEventListener(p_type, p_listener, p_useCapture, p_priority, p_useWeakReference); } public function removeEventListener(p_type:String, p_listener:Function, p_useCapture:Boolean = false):void { if (dispatcher == null) { return; } dispatcher.removeEventListener(p_type, p_listener, p_useCapture); } public function dispatchEvent(evt:Event):void { if (dispatcher == null) { return; } dispatcher.dispatchEvent(evt); } } }