For this assignment, you are to write a program that models a Slot
Machine. Since the dimensions of your slot machine are not physically
constrained, your machine will be able to have any kind and number of
pictures spinning when the player "pulls" the handle.
To understand some of the terminology used in this handout specific to Slot Machines, please read howstuffwork's description of How Slot Machines Work. We suggest you pay particular attention to the Section on Electronic machines.
To start, check out the program files using Ambient as Assignment/02_Slots.
In addition to the Java files, there are two data files used to configure classes within this program. The first file contains information about the gambler using the slot machine. The second file contains information for a particular instance of a slot machine. You can add additional examples of these data files to test and customize your slot machine. You can assume that all data files given will be formatted correctly so you do not need to include error checking for the values read from the file.
The code you are given runs, but makes a very poor version of a Slot Machine. You can see the output to the right. The Slot Machine does spin reels but it always lands on the first item, in this case an Ankylosaurus. It does not keep track of how much money has been won or lost or when the game is over. Furthermore, running the minimal number of tests in SlotsTest shows that the SlotMachine class has not been implemented correctly. There are many TODO comments listed in the code to guide you in completing the slot machine.
A Gambler is modeled as simply a name and an amount of money. The initial values of these variables will be read in from a data file. The format of the gambler file is the following:
<name> <bankroll>
where
An example of a data file for the gambler is gambler.txt. In this example, the player will start out with a 100 dollar bankroll and be named Jeffrey.
You should complete the class started for you that reads these types of data files to construct the gambler and then keeps track of the total amount of money the gambler has (over all wins and losses). You should not need to add any additional methods to this class, simply complete the ones that have been started from you.
The SlotMachine class determines the odds and governs the overall behavior of the machine.
The initial values of these variables will be read in from a data file. The format of the machine file is the following:
<reels> <symbols> <virtual-reels> <symbol 1> <multiplier 1> <symbol 2> <multiplier 2> . . . <symbol n> <multiplier n> <payout 0> <payout 1> . . . <payout k> <payout k+1> <virtual reel entry 1> . . . <virtual reel entry m>
where
So the values of <reels>, <symbols> and <virtual-reels> are k, n and m respectively.
An example of a data file for a machine is basic_machine.txt. In this example, the slot machine will have 3 reels, each of which cycles through 7 possible symbols. The symbols are created with the name of an image file (Java will recognize any GIF or JPEG image, note all images will be scaled to 75 by 75 pixels) and a payoff multiplier --- so it does no good to get the ankylosaurus and the stegasaurus pays out the most money when matched.
|
|
|
|
|
|
|
| ankylosaurus | dimetrodon | oviraptor | parasaurolophus | spinosaurus | trex | stegosaurus |
The next four lines indicate that there will be no payoff for matching zero or one symbol, while matching two pays twice as much and matching all three pays out ten times as much.
Finally, this machine has the same number of virtual and actual reels. Since each virtual reel refers one-to-one to an actual reel, all symbols are equally likely to be chosen when the machine stops spinning.
Each symbol contributes to the payout by the following formula.
symbol's payout = <symbol's multiplier> x <payout for number of occurrences of symbol>
The amount won will be the sum of the payouts for all of the symbols multiplied by the bet made.
Complete the calculateWinnings method in the SlotMachine class.
Write the spin methods in the SlotMachine class that returns an array of indices on the actual wheel. These determine on which symbols the spin will stop. The indices in the resulting array should be chosen by randomly generating indices for the virtual wheel mappings.
Test your SlotMachine functions using the SlotsTest methods that you have written earlier.
After you have created and tested your SlotMachine, you need to implement the placeBet and reportWinnings methods in the SlotsGame class to keep track of winnings, print messages, and determine when the game is over. Instead of using System.out.println to print messages, you should use the showMessage method of the SlotViewer class.
In your README file, you should answer the following question:
Submit your project as 02_slots, using the Ambient menu within Eclipse. Always be sure to submit all java files, even if you did not modify them. You must also submit a README too according to the directions given on the assignment page.