Today I want to finish the functions on the interface and we need to determine how to pass data. I think we need to create a game object to pass into the functions for now until I understand more about scope.
Here is what we have left to implement for the first set of functions:
4. Resolve dice (game logic)
5. Set Bet
6. Resolve Bet
I think the game logic will be a bit tedious but should be relatively straight forward and simple. My first thought is to just use if then else if then statements to handle each outcome.
I did end up using some nested if statements. the idea is that if the point is not defined the the win / lose conditions are different than if the point is set. so we check to see if point is defined and if it is we check to see if it is a lose condition and then if it is a win and if not then we roll again (loop restarts)
Also thank you to Nicolas Marcora https://blog.usejournal.com/mastering-javascripts-and-logical-operators-fd619b905c8f for the help with the Logical Operators.
See resolveDice() function code below:
function resolveDice() {
// The come out roll comes next.
let roll;
let rollCount;
let point;
while(true) {
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) {
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 == 3 ) { return console.log('lose');}
else {
// A Point number, which is a number other than those mentioned above, must be set up.
point = roll;
}
} 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');
}
}
}
}