Game Development Reference
In-Depth Information
Figure 7-12. The state of the dice tray after a player roll
Next, the number of rolls left in the current round is checked. If the number is greater than 0, the dice and roll
button are enabled so both dice holding and dice rolling can continue.
One more thing needs to happen when the dice stop. A player can choose a category in the middle of a round,
so the scorecard needs to become enabled every time the dice stop, regardless of how many rolls are left.
You've seen the enableDice and holdDie functions called on in a few different cases so far in the code. You most
likely have a pretty good idea of what these functions are doing. Listing 7-23 shows how these functions are written.
Listing 7-23. The holdDie Function Toggles the Hold Value on the Die Clicked
function enableDice(enable) {
var die, i;
for (i = 0; i < NUM_DICE; i++) {
die = diceTray.getChildByName('die' + i);
die.mouseEnabled = enable;
}
}
function holdDie(e) {
var die = e.target;
if (!die.hold) {
die.hold = true;
die.alpha = .7;
}
else {
die.hold = false;
die.alpha = 1;
}
}
The enableDice function accepts one parameter, which is a Boolean and will be used to set the mouseEnabled of
each die. This allows you to write one function for handling both the enabling and disabling of the dice.
The dice are held by calling the holdDie function, which is the click handler set on each die sprite. A simple
conditional is written to toggle its hold value, as well as its alpha value to visually represent its state.
Scoring on Categories
When a player is out of rolls, or is happy with the current roll they are on, the next step in a round is to choose a
category to apply a score to. This section will cover score messaging for the category buttons, as well as the scoreboard
section scores and total score message, respectively.
 
Search WWH ::




Custom Search