Game Development Reference
In-Depth Information
The Interfaces
Before we proceed any further into the GameBoard engine, we
need to look at the two interfaces that will be used in it, and which
we
ve already seen glimpses of in the MixUp and Game classes. As
you
'
ll recall from Chapter 4, an interface simply defines the names
and parameters of public methods that will be used in a class.
There is no actual logic performed in an interface. They are used
to supply a common interface through which classes of disparate
types can be used in the same context. The first is ISourceImage.It
is this interface that must be implemented by any source of ima-
gery the game will use for its puzzle, regardless of whether it is still
embedded photos, external photos, video, and so on.
'
package {
import flash.display.BitmapData;
public interface ISourceImage {
function getImages(rows:int, columns:int, width:
int = 0, height:int = 0):Vector. < BitmapData > ;
function cleanUp():void;
function destroy():void;
}
}
Classes that implement this interface only need to have three
methods defined in them. The first method, getImages,isarguablythe
most important. It needs to return a vector list of BitmapData objects
representing the sliced up original image, based on the number of
rows and columns. The next two, cleanUp and destroy,dopretty
much what you would expect based on their names. The cleanUp
method will be called when the GameBoard wants to dispose of the
sliced up images used to create the puzzle. The destroy method takes
it one step further and also is intended to dispose of the original
source image as well. Because BitmapData takes up a lot of space in
memory, it is important to provide easy ways of freeing up that space.
The other interface used with the GameBoard class is one called
IGamePiece. It defines the methods that will be used by the click-
able game pieces that will make up the game board. Each game
piecewillhaveaBitmapDataobjectfromthevectorlistreturned
by ISourceImage.getImages().
package {
import flash.display.BitmapData;
import flash.events.IEventDispatcher;
Search Nedrilad ::




Custom Search