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, then some spots on the two upward faces is calculated.
- If some are 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 continue 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
- {
-
- private Random randomNumber = new Random();
- private enum Status
- {
- CONTINUE,
- WON,
- LOST
- }
- private enum DiceNames
- {
- SNAKE_EYES = 2,
- TREY = 3,
- SEVEN = 7,
- YO_LEVEN = 11,
- BOX_CARS = 12
- }
-
- 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();
- if (sumOfDice == myPoint)
- gameStatus = Status.WON;
- if (sumOfDice == (int)DiceNames.SEVEN)
- gameStatus = Status.LOST;
- }
-
-
- if (gameStatus == Status.WON)
- Console.WriteLine("Palyer Wins");
- else
- Console.WriteLine("Player Losses");
- }
- public int RollDice()
- {
- int die1 = randomNumber.Next(1, 7);
- int die2 = randomNumber.Next(1, 7);
- int sum = die1 + die2;
-
- Console.WriteLine("Player rolled {0} + {1} = {2}", die1, die2, sum);
- return sum;
- }
- }
//class CrapTest.cs
- using System;
- class CrapTets
- {
- public static void Main()
- {
- CRAP game = new CRAP();
- game.Play();
- Console.ReadLine();
- }
- }
Screenshots of output
Fig 1: Snapshot of output
Fig 2: Snapshot of output
Fig 3: Snapshot of output
Fig 2: Snapshot of output