Fall Semester 2005


Lab Six: Games. Random number generators. Panels.

The assignment for today's lab will consist of only one problem:

Create an application that simulates playing the world-famous dice game "Craps". In this game, a player rolls two dice. Each die has six faces. Each face contains 1, 2, 3, 4, 5 or 6 spots. After the dice have come to rest, the sum of the spots on the two top faces is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3 or 12 on the first roll (called "craps"), the player loses (the "house" wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, that sum becomes the player's "point." To win, a player must continue rolling the dice until the player rolls the point value. The player loses by rolling a 7 bewfore rolling the point.

Here's the completed application, so you can test-drive it: labSix.jar

Remember, you have to develop it from scratch, the code provided is meant to clarify the requirements.

Download the contents of the link to your desktop, then run the program as follows from the command line:

java -classpath labSix.jar CrapsGame
Here's the way the application will look when you run it.

Your task is to provide an implementation that works exactly as the one you're test driving.

Remember, you have to develop it from scratch, the code provided is meant to clarify the requirements.

Actually you might have to unjar the Java archive first: jar xvf labSix.jar then run the game.

And here are the notes for this lab: First you need the images:

We then start with a simple program.

Getting the GUI going we add a JPanel, with a titled border.

All of the GUI is now in, except some of it is entirely invisible (four labels, to be precise).

We add the event listener and the two buttons toggle their active states. The game can start.

In this version we play ten times, then the game restarts. Changes are minor, basically.

And here's the last stage in this development (the rest is your responsibility).

In the interest of efficiency here are the next four steps:


Last updated on Aug 29, 2005, by Adrian German for A202/A598 and I211