Game Development Reference
In-Depth Information
break;
case GameStates.STATE_FADE_DICE_WAIT:
if (!checkForFadingDice()) {
gameState = nextGameState;
}
break;
case GameStates.STATE_FALL_DICE_WAIT:
if (!checkForFallingDice()) {
gameState = nextGameState;
}
break;
case GameStates.STATE_END_LEVEL:
endLevel();
gameState = GameStates.STATE_INITIALIZING;
break;
case GameStates.STATE_END_GAME:
endGame();
break;
case GameStates.STATE_WAIT:
framesWaited++;
if (framesWaited >= framesToWait) {
gameState = nextGameState;
}
break;
}
update();
render();
}
Capturing and scoring a player move
Besides the fact that nearly every line of code in
dieClickListener
has been changed to include
the word “die” or “dice” instead of “block,” the function of the code is almost identical to
blockClickListener
in Color Drop. One minor but important difference is that this function
accepts an instance of
CustomEventClickDie
instead of
CustomEventClickBlock
. However, the big
difference is that we now calculate the score in this function instead of in
removeClickedDice
(
removeClickedBlocks
in Color Drop), because we will use
removeClickedDice
for both the player
and computer move. By moving the score calculation here,
removeClickedDice
can remain a
universal function instead of having to know the context in which it was called.
The important code that we have added follows. First, we get the value of the dice by calling
getDiceValue
passing
clickedDiceArray
as the parameter to get
dicevalue
. Then, we call
addToScore
passing
dicevalue
.
var dicevalue:Number = getDiceValue(clickedDiceArray);
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_COMPUTER_LIFE,
String(computerLife)));
addToScore(dicevalue);