blackjack, craps, poker, and slotmachine virtual

A Casino Simulator Program
Using Advanced C++ Concepts
Thomas H. Hand
July 25th, 2005
Software/Hardware Integration
Overview of Presentation





Background Concepts & Motivation
Program Flowchart
Advanced C++ Concepts Utilized
Explanation of Program
Conclusions and Questions
Background Concepts & Motivation
The purpose of this project was to create a
program that would simulate several casino
games, while giving the player the ability to save
and load data. In addition, the program
incorporates just about every concept learned in
the Advanced C++ course. As these concepts
arise during the program explanation, I will
inform you of them.
Program Flowchart
- PLEASE SEE VISIO FLOWCHART -
Advanced C++ Concepts Utilized







Classes
Operator Overloading
Polymorphism
Inheritance
File Processing
Data Structures
Some STL concepts
Explanation of Program
 Five Header Files contain the class definitions:
mainprogram.h
blackjack.h
craps.h
poker.h
slotmachine.h
mainprogram.h:
 Main source of control for program flow
 Contains class mainprogram which is a base class to classes:
blackjack, craps, poker, and slotmachine
Public Members:
virtual void menu() const:
This member function displays the opening screen with the menu
selection, and is const because it is not to modify any data.
virtual int play():
In mainprogram, this member function does nothing. It is declared
virtual because all of the classes derived from class mainprogram use
function play to initialize the corresponding games. Therefore, play must
be overridden in each derived class. This is how “Polymorphism” is
used in my program.
void newgamedisplay() const:
This member function displays the game selection screen, and is called
when the player selects “new game” from the main menu display.
int decision():
This member function returns a value that corresponds to the player’s
input. It returns either 1,2,3,4, or 5, which corresponds to starting a new
game, saving the current game, loading a game, viewing the high
scores, or quitting.
void loadgame():
This member function allows the player to load one of five saved
games.
void savegame():
This member function allows the player to save the current game into
one of five save files.
void highscores():
This member function allows the player to view the scores of each save
file in descending order.
void quit() const:
This member function is used to quit the program completely.
int getchoice():
This member function allows user to select which game they want to
play
int getwins():
This member function accesses private data member totalwins and
returns the current number of wins.
int getlosses():
This member function accesses private data member totallosses and
returns the current number of losses.
int getmoney():
This member function accesses private data member totalmoney and
returns the current amount of money.
int setwins():
This member function is used to increment the number of wins in the
current game (modifies private member totalwins).
int setlosses():
This member function is used to increment the number of losses in the
current game (modifies private member totallosses).
int setmoney(int):
This member function is used to change private data member
totalmoney
void timedelay():
This member function is used for a time delay
Private Data Members:
int totalwins: used to keep track of the total number of wins.
int totallosses: used to keep track of the total number of losses.
int totalmoney: used to keep track of the total amount of money
 mainprogram is the heart of the casino simulation. At
over 600 lines of code, it is the “brain” of the project
blackjack.h
 Contains black jack game class definition
 Publicly Inherits from class mainprogram
Public Data Members:
virtual int play():
This member function is used to load the game menu and get
input from player. It is declared virtual so that it can override
mainprogram’s play() function.
int init():
This member function is used to start a new game of blackjack.
void shuffle():
This member function shuffles the card arrays into a random
order.
void shuffle2():
This member function is used to fill the 52-card array with cards.
void display():
This member function is used to display the current dealer and
player hands.
void input():
This member function is used to ask the player if they want a card.
int process():
This member function checks for the outcome of the game and
returns a value dependent on if the player won or lost.
 Blackjack simulates a standard blackjack game,
where 21 is a blackjack. A natural blackjack is when
the player is dealt a blackjack from the start.
craps.h:
 Contains craps game class definition
 Publicly Inherits from class mainprogram
Public Data Members:
virtual void menu() const:
This member function displays the craps opening menu. It is
declared virtual because c-menu() must override mainprogram’s
menu() function.
virtual int play():
This member function starts the craps game simulation. It is
declared virtual so that it overrides mainprogram’s play() function.
int rolldice():
This member function simulates the roll of two die and returns their
sum.
void timedelaycraps():
This member function causes a time delay used by the
craps game.
poker.h
 Contains poker class definition
 Publicly Inherits from class mainprogram
Public Data Members:
virtual void menu() const:
This member function displays the poker opening
menu. It is declared virtual because p->menu() must
override mainprogram’s menu() function.
virtual int play(int):
This member function handles the game logic of five
card stud poker. It takes the current value of totalmoney
and returns a new value to be used for the current
amount of money the player has.
virtual pokertimedelay():
This member function implements a time delay for
use in the poker game.
slotmachine.h
 Contains slotmachine class definition
 Publicly inherits from class mainprogram
Public Data Members:
virtual void menu() const:
This member function displays the slotmachine opening
menu. It is declared virtual because sm-menu() must
override mainprogram’s menu() function.
virtual int play(int):
This member function starts the slotmachine game and
returns the new “totalmoney” value.
void slottimedelay():
This member function implements a time delay used by
the slotmachine game.
Source Files
The Source Files are too detailed to explain here. Please see the
code comments for an in-depth explanation. The following source files
are utilized in my program:
main.cpp
blackjack.cpp
craps.cpp
poker.cpp
slotmachine.cpp
Conclusions and Questions
Any Questions?