
/*
    This program simulates one game of Craps.  A pair of dice is rolled.
    The total on the dice is called the "point".  If the point is 7 or 11,
    the player wins.  If the point is 2, 3, or 12, the player loses.
    Otherwise, the player tries to "make his point".  The dice are
    rolled over and over until one of two things happen.  If the roll
    comes up 7, the player loses.  If the roll is equal to the player's
    point, then the player wins.  This program requires the PairOfDice
    class.
*/

public class Craps {

   public static void main(String args[]) {
   
      PairOfDice dice;          // A pair of dice to use in the game.
      dice = new PairOfDice();  // Create the dice.
      
      int point;  // The first roll of the dice.
      point = dice.roll();
      
      System.out.println("This game simulates a game of craps.");
      System.out.println("On your first roll, you get a  " + point);
      
      if (point == 7 || point == 11) {
          System.out.println("You win!");
          System.out.println("Congradulations.");
      }
      else if (point == 2 || point == 3 || point == 12) {
          System.out.println("You lose!");
          System.out.println("Too bad.");
      }
      else {
          System.out.println("Rolling for a " + point + "...");
          while (true) {
              int nextRoll;  // Next roll of the dice.
              nextRoll = dice.roll();
              System.out.println("   The dice come up " + nextRoll);
              if (nextRoll == 7) {
                  System.out.println("You lose!  Too bad.");
                  break;
              }
              else if (nextRoll == point) {
                  System.out.println("You made the point.  You win!");
                  break;
              }
          }
      }
   
   }
   
} // end class Craps
