21
A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th , 2005 Software/Hardware Integration

A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

Embed Size (px)

Citation preview

Page 1: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

A Casino Simulator Program Using Advanced C++ Concepts

Thomas H. Hand

July 25th, 2005

Software/Hardware Integration

Page 2: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

Overview of Presentation

Background Concepts & Motivation Program Flowchart Advanced C++ Concepts Utilized Explanation of Program Conclusions and Questions

Page 3: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 4: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

Program Flowchart

- PLEASE SEE VISIO FLOWCHART -

Page 5: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

Advanced C++ Concepts Utilized

Classes Operator Overloading Polymorphism Inheritance File Processing Data Structures Some STL concepts

Page 6: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

Explanation of Program

Five Header Files contain the class definitions:

mainprogram.hblackjack.hcraps.hpoker.hslotmachine.h

Page 7: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

mainprogram.h:

Public Members:

Main source of control for program flow

Contains class mainprogram which is a base class to classes:

blackjack, craps, poker, and slotmachine

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.

Page 8: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 9: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 10: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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

Page 11: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

Private Data Members:

mainprogram is the heart of the casino simulation. At over 600 lines of code, it is the “brain” of the project

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

Page 12: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 13: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 14: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 15: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 16: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 17: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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 totalmoneyand returns a new value to be used for the currentamount of money the player has.

Page 18: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

virtual pokertimedelay(): This member function implements a time delay for

use in the poker game.

Page 19: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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.

Page 20: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

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

Page 21: A Casino Simulator Program Using Advanced C++ Concepts Thomas H. Hand July 25 th, 2005 Software/Hardware Integration

Conclusions and Questions

Any Questions?