Project 4 – The Game of Craps
DUE: June 30th, 2005
Introduction
Craps is played with two dice which are rolled together. The sum of these two dice is computed and if the sum is:
· 2, 3, or 12 – the player loses.
· 7 or 11 – the player wins.
· Any other number is referred to as the “point.” The goal then becomes to keep rolling the dice until:
o The player rolls a 7 – the player loses
o The player rolls the “point” – the player wins.
Examples
Ex 1:
Roll 1: Player rolls a 12. Player loses.
Ex 2:
Roll 1: Player rolls a 7. Player wins.
Ex 3:
Roll 1: Player rolls a 5. The “point” becomes 5.
Roll 2: Player rolls a 9.
Roll 3: Player rolls a 7. Player loses.
Ex 4:
Roll 1: Player rolls a 10. The “point” becomes 10.
Roll 2: Player rolls a 2.
Roll 3: Player rolls a 10. Player wins.
Assignment
Your job on this assignment is to make a simple craps game. In this game the player will enter his or her name, the program will display a welcome message, and ask if the player would like to play or quit. The program will then roll two dice, and display them and their total. If the player has won, display a message congratulating them. If the player has lost, report it to them. Otherwise, store this first roll as the “point” roll and keep rolling until the player wins or loses. When the game ends, ask if the player would like to play again.
Ex:
|
Note that you need not match this exactly; it is only shown to give you an idea of how to proceed.
Rolling dice
Since we haven’t studied random numbers yet, here’s the code to roll a single die. It returns a number 1 to 6 inclusive:
|