Game Development Reference
In-Depth Information
The next set of new variables contains settings for the difficulty of the game. These could have also
been created as difficulty settings, but since we have used the DifficultyLevel class for this game,
doing so was really not necessary. playerLifeStart is the number of hit points the player will start
with at the beginning of each level (added to the number of hit points left at the end of the previous
level). DICE_BONUS is the number of bonus points awarded for each connected die (over one) that
the player or computer plays on a single turn. The other new variables here are simply renamed
from Color Drop: clickedDiceArray was clickedBlockArray , and tempDie was tempBlock . We do
this a lot in the code for this game, so get ready for it.
private var playerLifeStart:int = 100;
private const DICE_BONUS:int = 2;
private var clickedDiceArray:Array;
private var board:Array;
private var tempDie:Die;
private var gameState:int = 0;
private var nextGameState:int = 0;
private var framesToWait:int = 0;
private var framesWaited:int = 0;
By the way, do you think you could take the code for this game and Color Drop and turn it into a
base class that could be used to derive many different games of this type? How would you go
about doing that? Think about it as you read this chapter.
Recall that we have two tile sheets to utilize in the game, DiceSheet and Characters . The
following code creates variables to hold those sheets. It also creates two variables to hold
instances of the Character class we defined earlier, one for the player's one screen character
( playerTile ), and one for the computer's onscreen character ( enemyTile ).
private var tileSheet:TileSheet;
private var charSheet:TileSheet;
private var enemyTile:Character;
private var playerTile:Character;
//***** Flex *****
//[Embed(source = 'assets/dicebattleassets.swf', symbol = 'Characters')]
//private var Characters:Class;
//[Embed(source = 'assets/dicebattleassets.swf', symbol = 'DiceSheet')]
//private var DiceSheet:Class;
//***** End Flex *****
The constructor for Dice Battle is nearly identical to that of Color Drop. The code for it follows:
public function DiceBattle(gameWidth:int,gameHeight:int) {
this.gameWidth=gameWidth;
this.gameHeight=gameHeight;
init();
gameState = GameStates.STATE_INITIALIZING;
}
The init function for Dice Battle acts pretty much like the other init function we have created for
previous games: it sets up tile sheets and creates the difficulty levels. Besides having two tiles
sheets ( DiceSheet and Characters ), there is little new to discuss on that front. However, the
Search WWH ::




Custom Search