GGHY Casino - My FIT (my.fit.edu)

GGHY Casino
Ron Gicka
Jeremy Gillow
Rolando Herrera
Matt Yourek
Original Mission
Our idea for spring 2005 Final project is a Multi-game Casino.
The games included will be:
1. Craps
2. Roulette
3. Blackjack
4. Slot machine
5. Video Poker
Throughout the gaming the user will be able to move around from
game to game to achieve the high rollers status.
The program will be able to keep a record of wins, losses, and money
transactions.
A GUI will be used for the lobby and individual games
Changes
 Slots was dropped
 Time constraints & complexity
 A GUI was only used for Blackjack and
Video Poker




Difficulty getting it to compile
Additional complexity of craps & roulette
Time constraints
Trial Version
Benefits from Changes
 We got to see how the GUI and text
based programs interact with one
another
Craps
 Developed by Matt
 Text-Based
 Menu driven
•Casino and Craps classes
•Craps publicly inherits from
Casino
Craps Main
#include "casino.h"
#include "craps.h"
int main()
{ casino visit;
Craps dice;
dice.crapsDriver();
return 0;
}
Casino Class
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
using std::cout;
using std::cin;
using std::ios;
using std::endl;
using std::ifstream;
using std::ofstream;
class casino
{
public:
casino();
void displayBalance();
double getBalance();
void adjustBalance(double);
void writeBalance();
private:
double balance;
};
casino::casino()
{
balance=getBalance();
writeBalance();
}
void casino::displayBalance()
{
cout << "Your current casino balance is: " << balance << endl;
}
double casino::getBalance()
{
ifstream infile("balance.dat", ios::in);
infile >> balance;
return balance;
}
void casino::adjustBalance(double change)
{
balance += change;
writeBalance();
}
void casino::writeBalance()
{
ofstream outfile("balance.dat", ios::out);
outfile << balance;
outfile.close();
}
Craps Class
#include "casino.h"
class Craps : public casino
{
public:
Craps();
void crapsDriver();
void setCrapsBalance();
void displayCrapsBalance();
void firstBet();
void rollDice();
void establishSum();
void playCraps();
void displayDie(int);
void statusAction();
void rollType();
private:
int dieOne;
int dieTwo;
int sum;
int myPoint;
char gameStatus;
double crapsBalance;
bool passType;
double passBet;
};
//Constructor
//Acts like a main function, but located in the class
//Move money from casino balance to craps table
//Show the current craps table balance
//Make a pass/don’t pass bet
//randomly generate two numbers between 1&6
//adds the two dice
//determines if the user rolled winning dice, crap dice, or point
//displays a die based on the parameter sent to it
//determines if the user wins money based on their roll and bet
//determines if the roll is a ‘hard way’
//holds value of one die
//holds value of second die
//holds the sum of the dice
//holds the roller’s current point
//c: continue, w: win, l: lost
//holds the amount the roller has at the table
//true for pass bet, false for don’t pass
//amount of the current bet
Craps Highlights
In playCraps:
Appropriate call to parent’s constructor:
switch( sum ) {
case 7:
Craps::Craps()
case 11:
casino()
gameStatus = 'w';
{…
break;
2:
In crapsDriver(), making sure the case
case 3:
user has money at the table.
case 12:
gameStatus = 'l';
…if ( choice == 2 )
break;
default:
{ if(crapsBalance == 0)
gameStatus = 'c';
{ cout << "You don't have
myPoint = sum;
break;
any chips to play with. You
have to go get chips \n”
continue;
}
} // end switch
while ( gameStatus == 'c' )
{
cout << "Point is " << myPoint << endl;
rollDice();
if ( sum == myPoint ) gameStatus = 'w';
else if ( sum == 7 ) gameStatus = 'l';
}
statusAction();
Rolling the Dice
void Craps::rollDice()
{ int randTime = rand() % 1000;
for(int i = 0; i < randTime; i++)
i = i;
dieOne = 1 + rand() % 6;
displayDie(dieOne);
dieTwo = 1 + rand() % 6;
displayDie(dieTwo);
establishSum();
cout << "Player rolled a " << dieOne
<< " + " << dieTwo << " = " << sum;
rollType();
}
Roulette
 Designed by Jeremy
 Text-Based with menu, betting system,
and roulette spinner readout
 Able to read existing balance for casino
and update with winnings, withdrawals,
or deposits
 Self-contained class with only one
public play function
Roulette - Dependencies








#include <iostream> : used for console input/output
#include <fstream> : used for file input/output
#include <cstdlib> : used for random function
#include <cstring> : used for storing type of bet
#include <ctime> : used for seeding random generator
#include <vector> : used for storing bet numbers
#include <windows.h> : used for console coloring
#include <conio.h> : used for “Any Key” pause
 All in std namespace
General Functions








void betTypes();
void displayBalance();
void addFunds();
void remFunds();
void placeBet();
void login();
void menu();
void writeBalance();
Display the types of bets available
Display account balance
Add funds to balance
Remove funds from balance
Betting menu for a spin
Gets/Creates balance info
Displays main menu choices
Writes the account balance to a

int displayNum(int)

void clrscr();
Display and return the roulette
spin number in correct sequence
Clear the screen
file
Bet-Specific Functions













void getBet(int)
int getAmt();
int getType();
void getSingle();
void getColumn();
void getCorner();
void getDozen();
void getFive();
void getLine();
void getTrio();
void getSplit();
bool isWinner(int);
bool isRed(int);
Ask what numbers to bet on
Ask what amount to bet
Ask what type of bet to be placed
Ask what single number to bet on
Ask what column to bet on
Ask what corner to bet on
Ask what dozen to bet on
Ask what five numbers to bet on
Ask what line to bet on
Ask what three numbers to bet on
Ask what two numbers to bet on
Determine whether bet was a winner
Determine whether number is red
Colored Console Text














0
1
2
3
4
5
6
7
8
HANDLE Console;
Console = GetStdHandle(STD_OUTPUT_HANDLE);
Color = 10;
Bright Green Color
SetConsoleTextAttribute(Console, color);
Black
9
Bright Blue
Dark Blue
10
Bright Green
Dark Green
11
Bright Aqua
Dark Aqua
12
Bright Red
Dark Red
13
Pink
Purple
14
Yellow
Tan
15
Bright White
White
240
Black on White Background
Grey
242
Green on White Background
252
Red on White Background
Updating the Balance
 void Roulette::writeBalance()
 {

// Standard unencrypted text file output

ofstream outfile("balance.dat", ios::out);

if (!outfile)

{

cerr << "Write error. Aborting.\n";

exit(0);

}

outfile << balance;
// Private balance class member

outfile.close();
 }
Putting Numbers into Bets
Vector
 void Roulette::getFive() {

matches.resize(5);
// Vector storing bets

for (int matchCount=1; matchCount<6; matchCount++) {

bool valid = false;

int choice = 0;

cout << "Enter number " << matchCount << " to bet on.
(37 for 00, 0-36) ";

do {

cin >> choice;

if (choice < 0 || choice > 37)

cout << "Enter a valid number please.\n";

else

valid = true; }

while (valid == false);

matches.at(matchCount-1) = choice; } // Store element

matchType = "five"; }
Spinning the Wheel


















srand(time(NULL));
int duration = rand()%1000+500;
// Ball spins between 500 and 1500 positions
int winner = 0;
for (int t=0; t<duration; t++)
winner = displayNum(t);
// Sequences through wheel
if (winner < 37)
cout << "The winning number is: " << winner << endl;
else
cout << "The winning number is: 00\n"; …
-------------------------------------------int Roulette::displayNum(int i) {
int position = i%38;
int winner;
switch (position) {
case 0:
winner = 0;
color = 242;
break; …
Poker
 Designed by Ron
 Graphical User Interface via
QT by Trolltech
 Able to read existing balance
for casino and update with
winnings or losses




Uses libraries from QT
Object Oriented Design
Card Graphics!!
Intelligent Win Analysis
Header
 class PokerDialogImpl : public PokerDialog
 {

Q_OBJECT
 public:

PokerDialogImpl( QWidget* parent = 0, const char* name = 0,
bool modal = FALSE, WFlags f = 0 );




 };
QString shuffle( QString );//Random cards (1-59)
QString appendpng( QString); //Adds .png
bool cardrestrictions (QString, QString, QString,
QString, QString, QString, QString, QString,QString,
QString);//Makes card value 1-52
QString cardvalue(QString);//Returns value of a card (1-13)
Member Function
Definitions





//Picks a random card
QString PokerDialogImpl::shuffle(QString card)
{
card[0]= 48+ rand()%5;
card[1]= 48+ rand()%9;


return card;
}


//Restricts card values to 1-52
bool PokerDialogImpl::cardrestrictions (QString
card1,QString card2,QString card3 ,QString
card4, QString card5,QString card6,QString
card7,QString card8,QString card9,QString
card10)
{


bool one,two, three, four, five, six, seven, eight, nine,
ten;

one = two = three = four = five = six = seven = eight =
nine = ten = false;

//detects if the numberis zero or more then 52, the 53 is
5 in decimal and the 50 is 2
if( ((card1[0] == 53) && (card1[1] > 50)) ||
((card1[0] == 48) && (card1[1] == 48)))
one = true;
if (card1 == card2)
two = true;




if (card1 == card3)
three = true;
if (card1 == card4)
four = true;
if (card1 == card5)
five = true;
if (card1 == card6)
six = true;
if (card1 == card7)
seven = true;
if (card1 == card8)
eight = true;
if (card1 == card9)
nine = true;
if (card1 == card10)
ten = true;
if(
(one||two||three||four||five||six||seven||eight||nine||ten) == true)
return true;
else
return false;
}
Member Function
Definition (cont.)





//Changes card value from 1-52 to 1-13
QString PokerDialogImpl::cardvalue(QString value)
{
int intvalue1 = value.toInt();
int intvalue2 = intvalue1;
if(intvalue1 <= 52)//more than
{
intvalue2 = intvalue1 - 39;
if(intvalue1 <= 39)
{
intvalue2 = intvalue1 - 26;
if(intvalue1 <= 26)
{
intvalue2 = intvalue1 - 13
if(intvalue1 <=13);
{
intvalue2 = intvalue1;
}
}
}
}


value = value.setNum(intvalue2);
return value;
}
Setting It All Up
















//Gets the global balance
ifstream infile("balance.dat", ios::in);
infile >> bal;
//Sets display
balanceamount =
balanceamount.setNum(bal);
//Clears win box
whatchagot = " ";
win();
//No money, no play!
if (balanceamount.toInt() <= 0)
close();
balance();
//Makes sure that this is the first deal
dealcount++;
if ((dealcount%2) != 0)
{






//sets all hold buttons to clear
hold1->setChecked(false);
hold2->setChecked(false);
hold3->setChecked(false);
hold4->setChecked(false);
hold5->setChecked(false);
//Makes a poker object
PokerDialogImpl hand;
//Bal is the integer representation of balanceamount (QString)
bal = balanceamount.toInt();
//You can't bet more than you have
Wager->setMaxValue(balanceamount.toInt());
//The bet is converted to text
bet = Wager->text();
//Sets default card settings
first = second = third = fourth = fifth = sixth = seventh = eigth =
ninth = tenth = "53";
string empty = " ";
10 Cards Please









































while (hand.cardrestrictions(first, second, third, fourth, fifth, sixth, seventh, eigth, ninth, tenth))
{while (hand.cardrestrictions(second, third, fourth, fifth, sixth, seventh, eigth, ninth, tenth, empty))
{while (hand.cardrestrictions(third, fourth, fifth, sixth, seventh, eigth, ninth, tenth, empty, empty))
{while (hand.cardrestrictions(fourth, fifth, sixth, seventh, eigth, ninth, tenth, empty, empty, empty))
{while (hand.cardrestrictions(fifth, sixth, seventh, eigth, ninth, tenth, empty, empty, empty, empty))
{while (hand.cardrestrictions(sixth, seventh, eigth, ninth, tenth, empty, empty, empty, empty, empty))
{while (hand.cardrestrictions(seventh, eigth, ninth, tenth, empty, empty, empty, empty, empty, empty))
{while (hand.cardrestrictions(eigth, ninth, tenth, empty, empty, empty, empty, empty, empty, empty)) // or while pcard3 == pcard5 or pcard4
{while (hand.cardrestrictions(ninth, tenth, empty, empty, empty, empty, empty, empty, empty, empty))// or while pcard4 == pcard 5
{while (hand.cardrestrictions(tenth, empty, empty, empty, empty, empty, empty, empty, empty, empty))
{
tenth = hand.shuffle(tenth);
val10 = tenth.toInt();
}
ninth = hand.shuffle(ninth);
val9 = ninth.toInt();
}
eigth = hand.shuffle(eigth);
val8 = eigth.toInt();
}
seventh = hand.shuffle(seventh);
val7 = seventh.toInt();
}
sixth = hand.shuffle(sixth);
val6 = sixth.toInt();
}
fifth = hand.shuffle(fifth);
val5 = fifth.toInt();
}
fourth = hand.shuffle(fourth);
val4 = fourth.toInt();
}
third = hand.shuffle(third);
val3 = third.toInt();
}
second = hand.shuffle(second);
val2 = second.toInt();
}
first = hand.shuffle(first);
val1 = first.toInt();
}
Second Hand Anyone?


















//If the hold is checked, no new card is placed, otherwise new card is dealt
if (!(h1->isChecked()))
{
pixcard1.load (sixth);
card1->setPixmap(pixcard1);
finalhand[0] = val6;
}
else
finalhand[0] = val1;








if (!(h3->isChecked()))
{
pixcard3.load(eigth);
card3->setPixmap(pixcard3);
finalhand[2] = val8;
}
else
finalhand[2] = val3;
if (!(h2->isChecked()))
{
pixcard2.load(seventh);
card2->setPixmap(pixcard2);
finalhand[1] = val7;
}
else
finalhand[1] = val2;
if (!(h4->isChecked()))
{
pixcard4.load(ninth);
card4->setPixmap(pixcard4);
finalhand[3] = val9;
}
else
finalhand[3] = val4;
if (!(h5->isChecked()))
{
pixcard5.load(tenth);
card5->setPixmap(pixcard5);
finalhand[4] = val10;
}
else
finalhand[4] = val5;
An Old Friend (Bubble
Sort)













//Puts cards in increasing order (bubble sort)
for (int g = 0; g < 4; g++)
{
for (int h = 0; h < 4; h++)
{
if (finalhand[h] > finalhand[h+1])
{
temp = finalhand[h+1];
finalhand[h+1] = finalhand[h];
finalhand[h] = temp;
}
}
}
Flush and Straight Flush
 //Test for Flush
 if ((finalhand[4] <= 13) || ((finalhand[0] > 13) && (finalhand[4] <= 26)) ||
((finalhand[0] > 26) && (finalhand[4] <= 39)) ||

((finalhand[0] > 39) && (finalhand[4] <= 52)))
 {

whatchagot = "Flush";

balanceamount = balanceamount.setNum(bal + ((bet.toInt())*5));

winner = 1;

//Test for Straight Flush

if (((testfh[0]+1) == testfh[1]) && ((testfh[0]+2) == testfh[2]) &&

((testfh[0]+3) == testfh[3]) && ((testfh[0]+4) == testfh[4]) )

{

whatchagot = "Straight Flush";

balanceamount = balanceamount.setNum(bal +
((bet.toInt())*49));

}
 }
One Pair or Two?




























//Test for one pair
if ((testfh[0] == testfh[1]) || (testfh[1] == testfh[2]) || (testfh[2] == testfh[3]) || (testfh[3] == testfh[4]))
{
whatchagot = "One Pair";
balanceamount = balanceamount.setNum(bal);
winner = 1;
//Test for two pair
if ((testfh[0] == testfh[1]) && ((testfh[2] == testfh[3]) || (testfh[3] == testfh[4])))
{
whatchagot = "Two Pair";
balanceamount = balanceamount.setNum(bal + bet.toInt());
}
if ((testfh[1] == testfh[2]) && (testfh[3] == testfh[4]))
{
whatchagot = "Two Pair";
balanceamount = balanceamount.setNum(bal + bet.toInt());
}
if ((testfh[2] == testfh[3]) && (testfh[0] == testfh[1]))
{
whatchagot = "Two Pair";
balanceamount = balanceamount.setNum(bal + bet.toInt());
}
if ((testfh[3] == testfh[4]) && ((testfh[0] == testfh[1]) || (testfh[1] == testfh[2])))
{
whatchagot = "Two Pair";
balanceamount = balanceamount.setNum(bal + bet.toInt());
}
}
Finally Done








void PokerDialog::balance()
{
//Displays balance
balancedisp->setText(balanceamount);
ofstream outfile("balance.dat", ios::out);
//outfiles balance
outfile << balanceamount.toInt();
}





//Displays what hand you have
void PokerDialog::win()
{
windisp->setText(whatchagot);
}




//Sets bet
void PokerDialog::wager()
{
}




//Back to lobby
void PokerDialog::exit()
{
}
Blackjack
 Programmed by
Rolando Herrera
 The GUI was
developed in QT by
Trolltech
 The program uses
classes and
functions set by the
QT library
Getting it all started
•Initially we had problems getting QT to even work on our computers
•After getting it to work we had to learn some QT library functions we could use to
implement it with our code
The QT aspects which we ended up implementing include:
Data type: QString
QPixmap
QWidgets:
line edit box
spinbox
pushbutton
`
Functions: setText()
setNum()
Text()
setDisabled(bool)
setEnabled(bool)
l
load()
setPixmap()
toInt()
Making the Proper
Functions
The functions could be connected to the
widgets so whenever it received an input
such as a mouse click it would run the given
function connected to it
The Code- Global Variable
//The global variables
bool newgame = true;
bool standgame = false;
bool dealerwent = false;
//bool alreadywon = false;
//will be used to detect an Ace in the shown cards
bool d1shown = false;
bool d2shown = false;
bool d3shown = false;
bool d4shown = false;
bool d5shown = false;
bool p1shown = false;
bool p2shown = false;
bool p3shown = false;
bool p4shown = false;
bool p5shown = false;
int turn = 0; // keeps count of which turn it is so it can display the proper card
//These cards will have be shuffled and appended .png
QString dcard1, dcard2, dcard3, dcard4, dcard5;
QString pcard1, pcard2, pcard3, pcard4, pcard5;
//Will keep a count of the value of each card for each player
QString totaldealervalue;
QString totalplayervalue;
//will be changed to a number 1-11 in order to be added and manipulated
QString dcard1value, dcard2value, dcard3value, dcard4value, dcard5value;
QString pcard1value, pcard2value, pcard3value, pcard4value, pcard5value;
QString bets = "xxxxx";//the amount the player wants to bet
int intgamebalance;// game balance in type int so it can be loaded
QString gamebalance;//game balance, this one will be used in manipulations throughout the game
The Code- Balance
Function
void blackjackDialog::balance()
{
if (newgame == true)
{
gamebalance = " ";
ifstream infile("balance.dat", ios::in);
infile >> intgamebalance;
gamebalance = gamebalance.setNum(intgamebalance);
balanceamount->setText(gamebalance);
balanceload->setDisabled( true );//Disables the load button
betamount->setEnabled( true );//Enables the bet spinbox
dealbutton->setEnabled( true );//Enables the dealbutton
}
}
The Code- Deal Function
void blackjackDialog::deal() // Shuffles if new game, and deals the first cards
{
blackjackDialogImpl bj;
srand(time(0));
dcard1 = dcard2 = dcard3 = dcard4 = dcard5 = "53";//set to 53 so
pcard1 = pcard2 = pcard3 = pcard4 = pcard5 = "53";
string e = " "; // empty string used to compare later on
bets = betamount->text();// gets the value the player selects to be the betamount
if (bets.toInt() > gamebalance.toInt())// If the bet ismore than what is in the balance it
bets = gamebalance;
//set the bet to the balance
betamount->setDisabled( true );//bet spin box disabled
dealbutton->setDisabled( true );//disables deal button
hitmebutton->setEnabled( true );//enables hit button
standbutton->setEnabled( true );//enables stand button
//alreadywon = true;
turn=0; // keeps count of what turn so it can display the apppropriate card
dealerwent = false; // needed so the dealer value and player value can be compared only after the player stands
d1shown = false;// these 10 bools are needed to find an ace in the shown cards so it can change it to a value 1 if it goes over
d2shown = false;
d3shown = false;
d4shown = false;
d5shown = false;
p1shown = false;
p2shown = false;
p3shown = false;
p4shown = false;
p5shown = false;
The Code- Deal Function
if (newgame == true)
{
QPixmap colorcard;//qt data type for pictures
colorcard.load("redcard.jpg");//loads the red card background
dealercard1->setPixmap(colorcard);//these next ten load the red card into the
dealercard2->setPixmap(colorcard);
dealercard3->setPixmap(colorcard);
dealercard4->setPixmap(colorcard);
dealercard5->setPixmap(colorcard);
playercard1->setPixmap(colorcard);
playercard2->setPixmap(colorcard);
playercard3->setPixmap(colorcard);
playercard4->setPixmap(colorcard);
playercard5->setPixmap(colorcard);
newgame = false;// sets to false so it doesnt reshuffle later in the game
standgame = false;// if had already been playing it resets it to false
dealerwent = false;// also resets it
turn=0;//resets to 0
window->setText("Hit Or Stand");//displays into the bottom window
bool blackjackDialogImpl::cardrestrictions (QString card1,QString card2,QString card3,
QString card4, QString card5,QString card6,QString card7,QString card8,
QString card9,QString card10)
{
bool one,two, three, four, five, six, seven, eight, nine, ten;
one = two = three = four = five = six = seven = eight = nine = ten = false;
The Code
Deal Function
//detects if the numberis zero or more then 52, the 53 is 5 in decimal and the 50 is 2
if( ((card1[0] == 53) && (card1[1] > 50)) || ((card1[0] == 48) && (card1[1] == 48)))
one = true;
//This is the shuffle function it uses the class blackjackDialogImpl and member function card retrictions
if (card1 == card2)
// to set random numbers of 1-53 to into the displaying cards, the values are also copied to the cardvalue strings
two = true;
if (card1 == card3)
while (bj.cardrestrictions(dcard1,dcard2,dcard3,dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5))
three = true;
{while (bj.cardrestrictions(dcard2,dcard3,dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e))
if (card1 == card4)
{while (bj.cardrestrictions(dcard3,dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e,e))
four = true;
{while (bj.cardrestrictions(dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e,e,e))
if (card1 == card5)
{while (bj.cardrestrictions(dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e,e,e,e))
five = true;
{while (bj.cardrestrictions(pcard1,pcard2,pcard3,pcard4,pcard5,e,e,e,e,e))
if (card1 == card6)
{while (bj.cardrestrictions(pcard2,pcard3,pcard4,pcard5,e,e,e,e,e,e))
six = true;
{while (bj.cardrestrictions(pcard3,pcard4,pcard5,e,e,e,e,e,e,e)) //
if (card1 == card7)
{while (bj.cardrestrictions(pcard4,pcard5,e,e,e,e,e,e,e,e))//
seven = true;
{while (bj.cardrestrictions(pcard5,e,e,e,e,e,e,e,e,e))
if (card1 == card8)
{
eight = true;
pcard5 = pcard5value = bj.shuffle(pcard5);
if (card1 == card9)
}
nine = true;
pcard4
= pcard4value = bj.shuffle(pcard4);
if (card1 == card10)
}
ten = true;
pcard3 = pcard3value = bj.shuffle(pcard3);
}
if( (one||two||three||four||five||six||seven||eight||nine||ten) == true)
pcard2
= pcard2value = bj.shuffle(pcard2);
return true;
}
else
pcard1 = pcard1value = bj.shuffle(pcard1);
return false;
}
}
dcard5 = dcard5value = bj.shuffle(dcard5);
}
dcard4 = dcard4value = bj.shuffle(dcard4);
}
dcard3 = dcard3value = bj.shuffle(dcard3);
QString blackjackDialogImpl::shuffle(QString card)
}
{
dcard2 = dcard2value = bj.shuffle(dcard2);
card[0]= 48+ rand()%5;
}
card[1]= 48+ rand()%9;
dcard1 = dcard1value = bj.shuffle(dcard1);
return card;
}
}
void blackjackDialog::hitme()
{
if (newgame == false)
{
++turn;
if (turn == 1) // Displays first dealer card and 1st and 2nd player card
{
QPixmap turn1dcard;
turn1dcard.load(dcard1);
dealercard1->setPixmap(turn1dcard);
QPixmap turn1pcard;
turn1pcard.load(pcard1);
playercard1->setPixmap(turn1pcard);
The Code hitme function
QPixmap turn2pcard;
turn2pcard.load(pcard2);
playercard2->setPixmap(turn2pcard);
d1shown = p1shown = p2shown = true;
//sets the card total
totaldealervalue = totaldealervalue.setNum( dcard1value.toInt() );
totalplayervalue = totalplayervalue.setNum( pcard1value.toInt() + pcard2value.toInt() );
}
if (turn == 2)
{
if (standgame == true)
{
QPixmap turn2dcard;
turn2dcard.load(dcard2);
dealercard2->setPixmap(turn2dcard);
totaldealervalue = totaldealervalue.setNum( dcard1value.toInt() + dcard2value.toInt());
d2shown = true;
if (totaldealervalue.toInt() < 18)
++turn;
}
if(standgame == false)
{
QPixmap turn3pcard;
turn3pcard.load(pcard3);
playercard3->setPixmap(turn3pcard);
p3shown = true;
totalplayervalue = totalplayervalue.setNum( pcard1value.toInt() + pcard2value.toInt() + pcard3value.toInt());
}
}
Cardvalue();//at end of turn 5
The Code – Stand Function
and Player Status Function
void blackjackDialog::stand()
{
//allows for the stand function to work
dealerwent = true;
standgame = true;
turn = 1;
playerstatus(); // checks if the player busted, got 21 or went over
hitme();//Lets the dealer cards be seen
}
void blackjackDialog::playerstatus()
{
if ((p5shown == true ) && (totalplayervalue.toInt() <= 21) )
{
window->setText("5 Card Charlie - You Win!
Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() + bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
else if (totalplayervalue.toInt() > 21)
{
window->setText("You Busted - You Loose
Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() - bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
else if (totalplayervalue.toInt() == 21)
{
window->setText("21 You Win Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() + bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
}
void blackjackDialog::status()
{
if ( dealerwent == true)//(alreadywon == false)
{
if ((d5shown == true ) && (totaldealervalue.toInt() <= 21) )
{window->setText("Dealer got 5 Card Charlie - You Loose!
Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() + bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
else if(totaldealervalue.toInt() > 21)
{window->setText("Dealer Busted -You Win!
Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() + bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
else if (totaldealervalue.toInt() == totalplayervalue.toInt())
{window->setText("Draw
Place a bet for the next game");
resetbutton();
}
else if (totaldealervalue.toInt() == 21)
{window->setText("Dealer scored 21 - You Loose
Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() + bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
else if (totaldealervalue.toInt() > totalplayervalue.toInt())
{window->setText("You Loose! Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() - bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
else if (totaldealervalue.toInt() < totalplayervalue.toInt())
{window->setText("You Win!
Place a bet for the next game");
gamebalance = gamebalance.setNum(gamebalance.toInt() + bets.toInt());
balanceamount->setText(gamebalance);
resetbutton();
}
}
}
The
Code:
Status
function
The Code: Reset Function
void blackjackDialog::resetbutton()
{
newgame = true;
dealbutton->setEnabled(true);
betamount->setEnabled(true);
hitmebutton->setDisabled( true );
standbutton->setDisabled( true );
ofstream outfile("balance.dat", ios::out);
outfile << gamebalance.toInt();
if(gamebalance.toInt() == 0)
close();
}
The Code: Cardvalue function
void blackjackDialog::cardvalue()
{
blackjackDialogImpl bj;
dealervalue->setText(totaldealervalue);
playervalue->setText(totalplayervalue);
//Checks for aces
if( totaldealervalue.toInt() > 21)
{
if ( (d1shown == true) && (dcard1value.toInt() == 11) )
{
dcard1value = dcard1value.setNum(1);
totaldealervalue = bj.ace(turn, dcard1value, dcard2value, dcard3value, dcard4value, dcard5value);
}
if ( (d2shown == true) && (dcard2value.toInt() == 11) )
{
dcard2value = dcard2value.setNum(1);
totaldealervalue = bj.ace(turn, dcard1value, dcard2value, dcard3value, dcard4value, dcard5value);
}
if ( (d3shown == true) && (dcard3value.toInt() == 11) )
{
dcard3value = dcard3value.setNum(1);
totaldealervalue = bj.ace(turn, dcard1value, dcard2value, dcard3value, dcard4value, dcard5value);
}
if ( (d4shown == true) && (dcard4value.toInt() == 11) )
{
dcard4value = dcard4value.setNum(1);
totaldealervalue = bj.ace(turn, dcard1value, dcard2value, dcard3value, dcard4value, dcard5value);
}
if ( (d5shown == true) && (dcard5value.toInt() == 11) )
{
dcard5value = dcard5value.setNum(1);
totaldealervalue = bj.ace(turn, dcard1value, dcard2value, dcard3value, dcard4value, dcard5value);
}
dealervalue->setText(totaldealervalue); //show totaldealer here
The Code: Ace member
function
QString blackjackDialogImpl::ace(int turn, QString card1,QString card2,QString card3 ,QString
card4, QString card5 )
{
QString total;
if (turn == 1)
total = total.setNum( card1.toInt() + card2.toInt() );
if (turn == 2)
total = total.setNum( card1.toInt() + card2.toInt()+ card3.toInt() );
if (turn == 3)
total = total.setNum( card1.toInt() + card2.toInt() + card3.toInt() + card4.toInt());
if (turn == 4)
total = total.setNum( card1.toInt() + card2.toInt() + card3.toInt() + card4.toInt() + card5.toInt());
if (turn == 5)
total = total.setNum( card1.toInt() + card2.toInt() + card3.toInt() + card4.toInt() + card5.toInt() );
return total;
}
Summary
 Overall, program may be inefficient, but it works
 Not knowing the full structure of QT and its library
disabled us from making the programs better
 For the amount of time given, our project is very
successful because we were able to implement half our
programs into a GUI
If We Continued Working…
 The GUI would be implemented for all
the games
 Additional bet types could be
programmed, as well as multiple bets at
once
 Slots could be developed, as could other
games
So, the question is….
ARE YOU IMPRESSED?