Game Development Reference
In-Depth Information
else if (this.dice[0] == this.dice[1] && this.dice[1] == this.dice[2] &&
this.dice[2] != this.dice[3] && this.dice[3] == this.dice[4]) {
pass = true;
}
score = (pass ? 25 : 0);
return score;
}
A full house is awarded if one of two possible scenarios occurs. If the first two dice are of equal value, and the last
three are equal of a different value, 25 points are awarded. The only other possible scenario is checked in a similar
way, only the first three are evaluated, and then the last two. If neither of these is true, a score of 0 is returned.
Scoring for Chance
Chance is usually chosen when your dice won't give you a particularly good score, given the available choices.
The getChance function is shown in Listing 7-38.
Listing 7-38. The Sum of All Dice for the Chance Category
Scoring.getChance = function () {
var score = 0;
var len = this.dice.length;
for (var i = 0; i < len; i++) {
score += this.dice[i];
}
return score;
}
Chance is simply the sum of all dice. A loop is created to increment the score variable, which is then returned at
the end of the function.
Scoring for Fakezee and Bonus Fakezee
A Fakezee is a five of a kind. Listing 7-39 loops through all dice to check for a valid Fakezee.
Listing 7-39. The getFakezee Function Checks if All Dice Are of the Same Value
Scoring.getFakezee = function () {
var pass = false;
var score = 0;
if (this.dice[0] == this.dice[1] && this.dice[1] == this.dice[2] &&
this.dice[2] == this.dice[3] && this.dice[3] == this.dice[4]) {
pass = true;
}
score = (pass ? 50 : 0);
return score;
}
 
Search WWH ::




Custom Search