Now that we have a game object we need to update all of our existing functions and modify our resolveDice() function so that it doesn’t loop. Here is the new resolveDice() function.
function resolveDice(game) {
// this function needs to return whether it is a win a loss or a roll again
// this function will take a dice total and the point if point is undefined the it is the first roll otherwise it is not the first roll
// The come out roll comes next.
let roll = game.currentDiceResult;
//let rollCount;
let point = game.point;
//roll = sumDice(rollDice(2,6));
//rollCount++;
//console.log(roll);
//console.log(rollCount);
// This is the game’s first roll and it could end the game if it is a 7, 11, 2, 3 or 12.
// The shooter and any other player who bet in favor of the shooter win the game if a 7 or 11 is rolled.
if (point == undefined) { //isFirstRoll = true
if (roll == 7 || roll == 11) {return console.log('win');}
// If a 2, 3 or 12 come up when the dice are rolled the shooter and other players who bet for him lose.
if (roll == 2 || roll == 3 || roll == 12 ) { return console.log('lose');}
else {
// A Point number, which is a number other than those mentioned above, must be set up.
setPoint(game);
}
} else {
// So if the come out roll is not any of those numbers listed above that number will be designated as the point number.
if (roll == 7) {
// The 7 is referred to an “Out 7” and once the shooter gets this before rolling the point he loses the game.
return console.log('lose');
// The shooter loses if the 7 comes up and wins if the Point is rolled.
} else if (roll == point) {
// The roll is next and the goal is for the shooter to roll the number identified as the point before he rolls a 7.
return console.log('win');
}
}
Next I need to handle setting the bet and resolving the bet, then work on a game controller. And finally create a web UI.
Here is the recording of this coding session: