This program will roll a pair of pair of dice and simulate a craps
game.
Craps is a dice rolling game using a pair of six-sided dice. On each
roll of a
pair of dice, the player (the user of this program), may either win the
game, lose the game or have an inconclusive roll. A game could possibly
go one forever, but that is unlikely. The outcome of the game is
determined according to the following rules: Only the sum of the two
dice matters, the particular pattern is not relevant. Thus, (3,6),
(4,5), (5,4) and (6,3) all have the same value, 9.
(Mar 20, 2006) I have increased the documentation in this section.
The instance method init creates the display, and the instance
method action listener causes the class to
play by calling the instance method play(). The method play() plays the
game by calling the instance method rollDice(), then updating the state
of the dice and, if appropriate, noting
wins, loses and points. The method rollDice uses a random number
generator to get values for the two dice, change the GUI display
fields, then return the sum of the values on the dice to the caller
(play()). The current status of the game is shown using the Applet
method showStatus (String), which changes the display in the
bottom-left text field of the applet window.
The class instance variables describe the state of the screen and the state of the game. A game status indicator is used to save the information about whether the game has been won or lost is still continuing. If the game is won or lost, pressing "roll" will start a new game.
To run the program, click the "run applet" link on the main
documentation
page. Apparently some browsers do not update the status window on the
bottom left for the game, so you may need to open the applet in a new
tab or new window.
Click "roll" to roll the dice. The values in the various fields correspond to a game of craps.
If the game is won or lost, a new game is automatically started.
To exit the program, hit "back" in your browser.
This program has been test with Netscape Navigator 4.7, Java 1.3 plugin, in Win95, and seems to work fine.
Start the application, press the "roll" button and play often enough to check to see:
- if 2, 3, 12 on first roll, then lose
- if 7 on first roll then win
- else
- roll until point achieved and win or
- roll until 7 rolled and lose.
1. How to run a java swing applet using Netscape and the latest java plug-in.2. How to use javadoc to create links to the source code and to get the applet running.
This is an extra section, but I leave it for historical interest.See the p4 example for inserting links to documentation, the html file that will run your applet and the author flag.
If your project is, say, p4, then put all of the relevant files into /class/cs305b/98/www/p4 directory. Note that your default directory is /class/cs305b/98 if you are student number 98.
Run the following command:
> javadoc -author *.java
This will produce the documentation set, starting with index.html
To make swing applets work with the latest version of the java plugin, you need to modify the test.html file, the file that you use to start the java applet. To do this, enter the following command:
> htmlc test.html
(or whatever you have called the
appropriate
html file.) Note that D&D seem to have chosen to use lower case
html
files to test their classes, as in craps.html will test the craps
program,
while
Craps.html is the file produced by the javadoc
command. This may be a reasonable approach. The actual command is:
> java -classpath /users/faculty/duchon/converter/classes HTMLConverterI suggest that you make an entry in your .cshrc file aliasing the first part of the command as, say, "htmlc".
Next, make sure that the files are readable through the net using:
> chmod a+rx *
or something similar.