CRAP is a dice game played in casino and back alleys throughout the world.
A Game of Chance CRAP
Rules of the game:
You roll two dice. Each die has a six faces, which contain one, two, three, four, five, six spots, respectively. After the dice have come to rest, the some of spots n the two upward face is calculated.
if some is 7 or 11 on the first throw, you win.
if some is 2,3 or 12 on the first throw (called CRAPS ) you lose (i.e the house wins).
if some is 4,5,6,8,9 or 10 on the first throw, that sum become "your point".
To win you must continues rolling your dice until you "make your point" (i.e roll that same value).
You lose by rolling a 7 before making your point.
Source code:
// class crap.cs
- using System;
- public class CRAP
- {
- //Creating a random number generator for use in methd RollDice
- private Random randomNumber = new Random();
- private enum Status //ENUM WITH CONSTATNT THAT REPRESENT GAME STATUS
- {
- CONTINUE,
- WON,
- LOST
- }
- private enum DiceNames
- {
- SNAKE_EYES = 2,
- TREY = 3,
- SEVEN = 7,
- YO_LEVEN = 11,
- BOX_CARS = 12
- }
- // PLAY ONE GAME OF CRAP
- public void Play()
- {
- Status gameStatus = Status.CONTINUE;
- int myPoint = 0;
- int sumOfDice = RollDice();
- switch ((DiceNames)sumOfDice)
- {
- case DiceNames.SEVEN:
- case DiceNames.YO_LEVEN:
- gameStatus = Status.WON;
- break;
- case DiceNames.BOX_CARS:
- case DiceNames.SNAKE_EYES:
- case DiceNames.TREY:
- gameStatus = Status.LOST;
- break;
- default:
- gameStatus= Status.CONTINUE;
- myPoint = sumOfDice;
- Console.WriteLine("Point is {0}", myPoint);
- break;
- }
- while (gameStatus == Status.CONTINUE)
- {
- sumOfDice = RollDice(); // roll dice again
- if (sumOfDice == myPoint)
- gameStatus = Status.WON;
- if (sumOfDice == (int)DiceNames.SEVEN)
- gameStatus = Status.LOST;
- }// end of while method
- // Display won or loss
- if (gameStatus == Status.WON)
- Console.WriteLine("Palyer Wins");
- else
- Console.WriteLine("Player Losses");
- }//end of method Play
- public int RollDice()
- {
- int die1 = randomNumber.Next(1, 7);
- int die2 = randomNumber.Next(1, 7);
- int sum = die1 + die2;
- //Display result of this roll
- Console.WriteLine("Player rolled {0} + {1} = {2}", die1, die2, sum);
- return sum;
- }// End method roll dice
- }
//class CrapTest.cs