Game Development Reference
In-Depth Information
for (var i:int = 0; i < rowList.length; i++) {
if ((tempDie.row + rowList[i]) >= 0 && (tempDie.row + rowList[i]) < DIE_ROWS &&
(tempDie.col + colList[i]) >= 0 && (tempDie.col + colList[i]) < DIE_COLS) {
var tr:int = tempDie.row + rowList[i];
var tc:int = tempDie.col + colList[i];
tB2 = board[tr][tc];
if(tB2.dieColor == tColor && tB2.dieValue == tValue && diceToCheck.indexOf(tB2)
== -1 && diceTested.indexOf(tB2) == -1){
diceToCheck.push(tB2)
}
}
}
diceTested.push(tempDie);
}
return diceMatched;
}
The getDiceValue function is brand new for Dice Battle. This function was not necessary in Color
Drop, because the colored blocks in that game did not have values. This function takes an array
of Die objects as it a parameter. It looks through the array and calculates the value of all the dice
based on the dieValue plus bonusPoints, which are incremented by DICE_BONUS for every Die
in the array after the first one. Incrementing bonusPoints in this way means that a move made
that includes multiple dice will have a bonus over a similar move with dice of the same dieValue
with fewer dice in the set.
public function getDiceValue(tdice:Array):Number {
var value:int = 0;
var bonusPoints:int = 0;
for (var d:int = 0;d< tdice.length;d++) {
tempDie = tdice[d];
value += (tempDie.dieValue+bonusPoints);
bonusPoints += DICE_BONUS;
}
return value;
}
The addToScore function is very close to the same function in Color Drop. The main difference is
that computerLife is decremented by the amount of the score (to take hit points away from the
computer), and it is reported back to the ScoreBoard.
private function addToScore(val:Number):void {
score += int(val);
computerLife -= int(val);
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_SCORE,String(score)));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_COMPUTER_LIFE,
String(computerLife)));
}
Search WWH ::




Custom Search