Game Development Reference
In-Depth Information
The GameBoard Class
This class is the engine at the heart of this entire game, and where
all the major logic happens. In order to be as flexible and reusable
as possible, it refers to objects by their interfaces rather than by
their specific class.
public class GameBoard extends Sprite {
static public var GAME_READY:String = " gameReady " ;
static public var GAME_OVER:String = " gameOver " ;
static public var PIECE_SWAP:String = " pieceSwap " ;
static public var PIECE_LOCK:String = " pieceLock " ;
protected var _pieces:Vector. < IGamePiece > ;
protected var _rows:int, _columns:int;
protected var _imageWidth:int, _imageHeight:int;
protected var _boardImage:ISourceImage;
protected var _selectedPiece:IGamePiece;
protected var _pieceClass:Class;
public function GameBoard(boardImage:ISourceImage,
pieceClass:Class, rows:int, columns:int, imageWidth:int = 0,
imageHeight:int = 0) {
_rows = rows;
_columns = columns;
_imageWidth = imageWidth;
_imageHeight = imageHeight;
_boardImage = boardImage;
_pieceClass = pieceClass;
When a new GameBoard object is created, it looks for an image
object to slice, the number of rows and columns, to use the width
and height of the puzzle, and which class to use for the game
piece (because it will be generically referred to as IGamePiece for
the rest of the code). In addition to these properties, the class
defines four different events that it will dispatch, and a list object,
_pieces, which will store a list of the game pieces in play.
public function createBoard():void {
_pieces = new Vector.
var numPieces:int = _rows * _columns;
var imageData:Vector. < BitmapData > = _boardImage.
getImages(_rows, _columns);
for (var i:int = 0; i < numPieces; i++) {
var piece:IGamePiece = new _pieceClass();
piece.index = i;
Search Nedrilad ::

Custom Search