Casino

Compiling the files

In order to run this, you need jdk or some java development environment on your machine.
Place the following files in your java bin or in a folder that has access to the JDK files:

Running the game

If you are on a Windows machine, at the command prompt, enter "java GameDriver" to start the program.

New or Restore?

This is the first screen of the game:

If this is your first time playing, enter "new" for a new game and you will be prompted to enter a player name, this is the name of your save file as well.

If you have a save file from before, you may enter "restore" and then the name to open a previous game.



Chosing a Game

After starting a new game or loading a previous one, entering "play" at the next prompt will show you the available games. Enter one of the game names to start.

General Play

You start with $100. You may leave any game by entering "leave." When you start to win big, it is advisable to walk away from a table by entering "leave" and then saving your game by typing "save." You may not save while sitting at a table or playing a game.

Your prompt will usually look like this:

[fred, 150]Action:
The information in the brackets are your player name and the amount in your bank([yourname, yourbank]). The word "Action" indicates the program is ready for your input.

Type "help" or "rules" while playing a game for information or assistance.

BlackJack


Enter a dollar amount bet to start the game

Cards are displayed by two character codes. Read the rules by typing "help."

Slots


Enter a dollar and pull the handle.

The wheels will spin and the three values will line up.

Roulette


Make sure to read the rules, the betting is slightly more complex than the other two games. The last 10 winning numbers are always displayed before a spin. Some people use this to decide what to bet on.

Enter "view" to see a layout of the table


Program Map

GameDriver.java
    methods
          |
          -------- ---------------- ---------------- ---------------- -------        
          |           |           |
Roulette.java
    methods
Slots.java
    methods
BlackJack.java
    methods
          |           |           |
Queue.java
    methods
LoopLL.java
    methods
Tree52.java
    methods

GameDriver.java

This is the main file for the program. The three games are accessed through here. Also this file controls access to the save files that can be generated by the game.

Methods

main() Sets up the initial input buffer for user interaction. Gives the user menu driven options for saving and restoring, and starting new games.

printStartMenu() Prints an intial menu of options
printMainMenu() Prints the general menu
makeSaveFile() Method for creating a save file
saveToFile() Method for storing user information
casinoStart() Prints "CASINO" in big letters, ascii art

Roulette.java

Methods

roulette() Main driver for this game. Uses a finite state machine to determine if the game is in the betting stage, spinning stage or payout stage. This method also accesses others for displaying helpful text.
spin() Returns the winning number
takeAction() processes user input, passes it to procBet if we are in the betting state.
procBet() works with procBet2() to process bets, also has some text output related to the game.
procBet2() Determines total bet amount, checks if it is more than the player has. Cuts up the bet string and determines if each individual bet is valid with help from isNum() and looksLike(). Then it determines which bet(s) win by accessing the booleans: isTrdCol(), isFstCol(), isEven(), isRed(), and isOneTo18().
isNum() Boolean to check if input is a number. Used for bets and bet amounts.
looksLike() Makes sure bet string is properly formatted(bet:amount, - example: odd:50,)

These booleans determine winning numbers:
isTrdCol() Boolean, is number in third column? Numbers in the third column are evenly divisible by 3.
isFstCol() Boolean, is number in first column? Numbers in the first column are evenly divisible by 3 after 1 has been subtracted. If it's not in col 1 or 3, it's in column 2.
isEven() Boolean, is number even? If it's not even it's odd.
isRed() Boolean, is number red? Done by checking an array of "red" values. Numbers that are not in this array are "black."
isOneTo18() Boolean, is number 1 to 18? If it's not 1 to 18 it's 19 to 36.

viewTable() shows table layout
howToBet() explains betting
rooStart() ascii art
help() general help

Queue.java

This Queue class stores the previous 10 winning numbers the same way that a board in a casino displays them. People use these numbers to calculate the next bet.

Methods

insert() Inserts new nodes in the queue. This method is called after each spin.
showQueue() Displays the queue. This method is called before each bet.

Slots.java

Methods

slots() main driver for game. "Loads" the slot wheels by calling loadFirstWheel() and loadOtherWheels(). The "wheels" are actually circulare linked lists with string values that represent what you might see on the wheels of a slot machine.
pullHandle() "Pulls" the handle by generating a random number of spins for the wheels. It can't be pulled if no money has been entered.
loadFirstWheel() load the first "wheel" circular linked list
loadOtherWheels() load the other two based on the first
calculateWin() Calculate winings by checking if any of the wheel values match and then figuing out what the payout is based on the type of win and the initial bet.
isNum() Boolean to see if entry is a number
introduction() Introduction script
slotStart() ascii art
help() General help

LoopLL.java

Class LoopLL is a linked list for setting up the slot wheels as circular lists

Methods

loopList() Changes the null at the end into a link to another item in the list
loadFromFirst() Loads the second and third wheel from the first. The wheels have the same values, but they are placed at different positions.
spin() "Spins" the wheels by going through the lists a random number of times.

BlackJack.java

Methods

blackjack() Main driver for game. Uses a finite state machine to control the flow of the game:
BET Can enter a bet amount
PLAY1 Intial deal of two cards
PLAY2 Hit or stay state
DBUST Dealer busts
PBUST Player busts
DWIN Dealer wins
PWIN Player wins
PUSH Dealer and player have same hand
SHUFFLE Deck is being shuffled

newDeck() creates a "deck" which is the array passed to shuffle()
shuffle() takes an inorder array and randomizes the order
isNum() boolean determines if entry is a number
showHand() displays a "hand" passed to it which is an array of card valeus
cleanHand() "clears" the hands at the table when a game is over, empties array
introduction() intro script calls bjStart()
bjStart() ascii art
help() general help

Tree52.java

Class Tree52 is a binary tree with each node holding a key value for the node, a string value that is the card, and the numerical value of the card. The key in this case is passed from BlackJack.java and represents the location of a card in a sorted deck.

Methods

insert() Places new nodes in the tree in a binary fashion
getval() Controls access to getVal()
getVal() returns the value of a card
getcard() Controls access to getCard()
getCard() returns the "face" of a card
makeCards() A small state machine is used to generate the four suits, one at a time