CS 6452 Homework 8
Due: Tuesday, November 29 at 1:30 pm

Assignment 8: One-armed Bandit

Now, we are not advocating gambling in any way...

In this HW, you will create a slot machine or one-armed bandit simulation. A slot machine is a gambling machine commonly found in Las Vegas, but here we will just be building one for fun. A slot machine consists of three spinning circular drums which each have many different symbols around them. The user pulls down a handle and the drums start spinning. They each then stop randomly on a symbol and if certain combinations of symbols come up, then the player wins. Just think of it like 3 random number generators.

In our game, each of the three positions have four different possible symbols: bell, grape, cherry and a dash or line. Each drum has one of the bell, grape, and cherry, and five of the lines. Thus, each of the eight different possibilities (bell, grape, cherry, line, line, line, line, line) should come up with equal probability on each spin. The user can bet round dollar amounts of one dollar or more. The machine pays out combinations as shown below (multiples of the bet amount).

  Combo   Payoff
Bell Bell Bell     10
Grape Grape Grape     7
Cherry Cherry Cherry     5
Cherry Cherry ******     3
Cherry ****** Cherry     3
****** Cherry Cherry     3
Cherry ****** ******     1
****** Cherry ******     1
****** ****** Cherry     1

The ****** can be any character including the lines.

You should implement a GUI application that has a cell for each of the 3 random symbols coming up and a button which starts a "spin". The interface should display the user's current money holdings (starts at $100). It also should have a text field where the user can enter his or her bet with a minimum bet of $1 (default) and a max up to the person's present holding. You can save the money as an int and assume the user will enter an int, but you still need to check that the bet is greater than the minimum $1 and less than or equal to the current money holdings. If the bet is invalid, give some kind of informative message to the user (for example, use JOptionPane and pop up a message box or have a label with a status message on your slot machine GUI, just make sure it's clearly visible).

Your application should also have a set of two radio buttons: Regular and Test. When the slot machine is in regular mode, the game should play as described above. When it is in Test mode, no Line symbols should ever come up on any of the drums. (The Bell, Grape, and Cherry should have equal likelihood of coming up.) This will allow us to test your game with more chances of winning combinations coming up.

The normal flow is for the user to enter a bet by typing it in and then pressing the spin button. The three windows on the drums then should show the random symbols that come up. From there, the program calculates the person's winnings (if any) and updates the current money holdings. If the user runs out of money (less than the minimum $1), pop up a message box or otherwise show a message informing the user. 

You should also provide a Reset button that will reset the user's current holdings back to the original $100. Since we don't want to reset the winnings by accident, clicking the button should first pop up a confirmation prompt and should only reset the money if the user clicks OK or Yes.

Use layout managers and try to make your user interface be as functional and look as good as possible, even when the panel is resized. Do a nice layout of the individual components. Feel free to embellish. For instance, go out and find an image file for the different symbols to use in your interface (remember that labels can take images).

Tips:
  • This program has two main aspects, the look of the user interface and the logic of how the program works. You can work on those piece-by-piece. That is, you could get the UI laid out and looking good, but nothing happens when the buttons are clicked, etc. You could independently be developing the logic for how the machine functions.
  • Remember that you can nest JPanels, so for example you might have a BorderLayout for the main outer panel, then put a panel inside that with a BoxLayout. Nesting JPanels with different layouts is a powerful way to make GUIs that resize well.
  • When designing methods and classes, keep in mind that one of the main ideas of object-oriented programming is that no class or method should do too much work. For instance, if you have a method with 100 lines, it would probably be better to split up the functionality into several smaller methods. Extra Credit:
    We will consider extra credit for programs that use some of the other Swing components and capabilities that we examined in class (eg, sliders, pull-down menus, animation, etc.) Feel free to be creative with your system and the machine's interface, as long as you follow the problem directions.

    Turn-in Procedures

    After you have finished your program, turn the files in via T-Square. You will be submitting multiple files. Please make sure they are named as shown below:

     

  • SlotMachine.java (holds main method)
  • Any other classes you created or files used in your program, including any image files