Game Development Reference
In-Depth Information
Here is the full code listing for dieClickListener :
public function dieClickListener(e:CustomEventClickDie):void {
if (gameState == GameStates.STATE_WAITING_FOR_INPUT) {
dispatchEvent( new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_CLICK,false,1,0,1));
tempDie = e.die;
clickedDiceArray = findLikeColoredDice(tempDie);
for (var i:int =0; i< clickedDiceArray.length; i++) { //changed dice battle
clickedDiceArray[i].makeDieClicked(); //changed dice battle
}
var dicevalue:Number = getDiceValue(clickedDiceArray);
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_COMPUTER_LIFE,
String(computerLife)));
addToScore(dicevalue);
framesToWait=15;
framesWaited=0;
dispatchEvent( new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_BONUS,false,1,0,1));
nextGameState = GameStates.STATE_REMOVE_CLICKED_DICE;
gameState = GameStates.STATE_WAIT;
}
}
The findLikeColoredDice function is very much like the findLikeColoredBlocks function from
Color Drop. The main difference is that we need to consider the diceValue of each Die class
when testing matches as well as the diceColor . To do this, we will perform a check similar to this
in two places:
if (tempDie.dieColor == tColor && tempDie.dieValue == tValue)
Basically, we are testing both dieColor and dieValue to find a match for Die objects in board . If
there is match, we will push the Die object into the appropriate array for our test.
To fully understand how this code works, please refer to the discussion of
findLikeColoredBlocks in Chapter 8.
private function findLikeColoredDice(tDie:Die):Array {
var diceToCheck:Array = new Array();
var diceMatched:Array = new Array();
var diceTested:Array = new Array();
var rowList:Array = [-1, 0, 1, -1, 1, -1, 0, 1];
var colList:Array = [-1, -1, -1, 0, 0, 1, 1, 1];
var tColor:Number = tDie.dieColor;
var tValue:Number = tDie.dieValue;
diceToCheck.push(tDie);
while(diceToCheck.length > 0) {
tempDie = diceToCheck.pop();
if(tempDie.dieColor == tColor && tempDie.dieValue == tValue){ //changed for dice drop
diceMatched.push(tempDie);
}
var tB2:Die;
Search WWH ::




Custom Search