
/* GUI version of a simple Craps game, with betting. */

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class Craps extends Applet implements ActionListener {

   Dice dice;   // An object of type Dice, which represents a
                //   visual pair of dice.

   Button betButton;   // The button that the user will click to 
                       //    place a bet and begin a game.

   Button rollButton;  // The button that the user will click to
                       //    roll the dice.

   TextField betInput; // A text-input box where the user can enter
                       //    the amount of the bet.
   
   Label message1;     // There labels that will be used to display
   Label message2;     //    messages to the user.
   Label message3;
   
   final static int WAIT_FOR_BET = 0,         // Constants to represent
                    WAIT_FOR_FIRST_ROLL = 1,  //     possible states of
                    ROLLING_FOR_POINT = 2;    //     the applet.
                    
   int state;  // The basic state of the applet.  This is one of
               //    of the constants WAIT_FOR_BET, WAIT_FOR_FIRST_ROLL,
               //    or ROLLING_FOR_POINT.  Note that the initial value
               //    is 0, meaning WAIT_FOR_BET.

   int money;  // The amount of money that the user has.

   int bet;    // The amount of the user's bet.

   int point;  // The "point" -- the number that the user is trying
               //    to get if the state is ROLLING_FOR_POINT.


   public void init() {
         // Create components, lay out the applet, initialize variables,
         // and set up event listening.
   }
   

   public Insets getInsets() {
         // A really stupid method that is necessary just to leave a
         // a border around the edges of the applet where the background
         // color will show through.  (Why do they make be do this??)
      return new Insets(3,3,3,3);
   }


   public void actionPerformed(ActionEvent evt) {
         // This is called when the user clicks one of the buttons.
         // It handles the event by calling ond of the methods
         // doPlaceBet(), doFirstRoll(), or doRollForPoint()
         // depending on the state of the applet and on which
         // button was pressed.
      Object src = evt.getSource();
      if (state == WAIT_FOR_BET && src == betButton)
         doPlaceBet();
      else if (state == WAIT_FOR_FIRST_ROLL && src == rollButton)
         doFirstRoll();
      else if (state == ROLLING_FOR_POINT && src == rollButton)
         doRollForPoint();
   }
   
   
   void doPlaceBet() {
         // If we get here, we know that the state is WAIT_FOR_BET and
         // that the user has just pressed the "Place Bet" button.
   }
   
   
   void doFirstRoll() {
         // If we get here, we know that the state is WAIT_FOR_FIRST_ROLL
         // and the user has just pressed the "Roll" button.
   }
   

   void doRollForPoint() {
         // If we get here, we know that the state is ROLLING_FOR_POINT
         // and the user has just pressed the "Roll" button.
   }
   

} // end class Craps

