Game Development Reference
In-Depth Information
ensure that we get a unique order every time. This method makes
direct use of the swapElements function to move the elements in
the list. Now, we
ll look at the GamePiece class that is used for the
implementation of the IGamePiece interface. Remember how the
GameBoard class only referenced pieces through the IGamePiece
interface? Because of this, the GamePiece class has the luxury to
have whatever internal mechanisms we want, as long as it correctly
implements all the methods of the interface. As a result, this class
has a fair amount of
values, such as the color, size,
and speed of animations. To make a different type of game piece,
you could use this class as a starting point and then modify any of
the functionality inside it or start from scratch. Ultimately, all that
matters in this case is that the interface methods are defined and
that the game piece in some way extends from DisplayObject, or
preferably InteractiveObject. This is because in the GameBoard
class, pieces are added to the Stage and a non-DisplayObject des-
cendant will display an error.
public class GamePiece extends Sprite implements IGamePiece {
protected var _image:Bitmap;
protected var _index:int;
protected var _currentIndex:int;
protected var _rolloverHighlight:Shape;
protected var _clickHighlight:Shape;
public function GamePiece() {
For this implementation, GamePiece will extend Sprite and con-
tains a Bitmap variable to store its image slice, two int variables to
store its current and original index, and two Shape variables that
will be used for rollover and click states.
protected function createRolloverHighlight():void {
_rolloverHighlight = new Shape();, 0xFFFFFF, 1);, .3);, .5, _image.
width-1, _image.height-1);;
_rolloverHighlight.visible = false;
protected function createClickHighlight():void {
_clickHighlight = new Shape();, 0, 1);
Search Nedrilad ::

Custom Search