Programming Craps Stage 2 - Making the Point
First part. Before starting this, be sure you've finished the Programming Craps - First Stage.
Rules for trying for a point
Point. If the first roll wasn't a win or a lose, it resulted in a value known as the point. When rolling for a point, the rules are completely different than for the first roll.
- Lose if 7. Rolling a 7 is an immediate loss.
- Win with point. Rolling any combination that produces the point value wins.
- Otherwise keep rolling until either a 7 or a point is rolled.
Loop trying to make the point
You will need to use a while
or do...while
loop.
The do...while
loop is probably a little easier to use in this
case because one simple way to structure the loop is as follows.
Note: I'm writing this in English so that you have to think about translating
it to Java.
- Roll the dice.
- Generate the win / loss / roll again message (if / else if / else).
- Print the message.
- While the roll was not the point or 7, go back to the first step.
Optional: Repeating the game, wins and losses, betting
- You could put an outer loop around the code so the user could continue playing additional games.
- If you allow them to repeatedly play, count and display wins and losses.
- Allow betting. Perhaps you an give them an initial amount of money to play with. I'm not familiar with the betting rules, but I belive there are numerous possibilites.