Game Development Reference
In-Depth Information
The newGame function does very little new in Dice Battle except initialize both playerLife and
computerLife . These values will be set in newLevel .
override public function newGame():void {
level = 0;
score = 0;
playerLife=0;
computerLife=0;
}
Creating a computer player
The majority of the big changes to DiceBattle class from ColorDrop class have to do with the
creation of the computer AI player for the human player to battle. These changes begin to take
serious shape in the newLevel function.
override public function newLevel():void {
level++
var tempLevel:int = level;
if (tempLevel > (difficultyLevelArray.length-1)) {
tempLevel = difficultyLevelArray.length-1
}
currentLevel = difficultyLevelArray[tempLevel-1];
The first new thing we need to do is calculate bonusLife . bonusLife is the number of extra hit
points we give the player when a new level starts. For this game, the player gets 10 percent of
the hit points left over from the previous level added to the value of playerStartLife . We also set
computerLife , to the value of enemyLife set in the instance of DifficultyLevel held in
currentLevel .
var bonuslife:int = (Math.ceil(playerLife/10));
playerLife = playerLifeStart + bonuslife;
computerLife = currentLevel.enemyLife;
turn ="";
board = new Array();
for (var r:int = 0; r < DIE_ROWS; r++) {
board[r] = new Array();
for (var c:int = 0; c <DIE_COLS; c++) {
board[r][c] = null;
}
}
Now, we need to get the enemyTile and the playerTile so we can display those graphics on the
screen. To do this, we create new Character classes for each and pass in a reference to the tile
we want to set for them. Recall that the playerTile is always the first tile in the Characters tile
sheet, while the enemyTile is set to the enemyTile property set when we created the instance of
DifficultyLevel referenced in currentLevel .
clickedDiceArray = new Array();
enemyTile = new Character(charSheet,currentLevel.enemyTile);
playerTile = new Character(charSheet,0);
Search WWH ::




Custom Search