1 / 46

GGHY Casino

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: Craps Roulette Blackjack 4. Slot machine 5. Video Poker

Télécharger la présentation

GGHY Casino

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GGHY Casino Ron Gicka Jeremy Gillow Rolando Herrera Matt Yourek

  2. Original Mission Our idea for spring 2005 Final project is a Multi-game Casino. The games included will be: • Craps • Roulette • 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

  3. 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

  4. Benefits from Changes • We got to see how the GUI and text based programs interact with one another

  5. Craps • Casino and Craps classes • Craps publicly inherits from Casino • Developed by Matt • Text-Based • Menu driven

  6. Craps Main #include "casino.h" #include "craps.h" int main() { casino visit; Craps dice; dice.crapsDriver(); return 0; }

  7. #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(); } Casino Class

  8. #include "casino.h" class Craps : public casino { public: Craps(); //Constructor void crapsDriver(); //Acts like a main function, but located in the class void setCrapsBalance(); //Move money from casino balance to craps table void displayCrapsBalance(); //Show the current craps table balance void firstBet(); //Make a pass/don’t pass bet void rollDice(); //randomly generate two numbers between 1&6 void establishSum(); //adds the two dice void playCraps(); //determines if the user rolled winning dice, crap dice, or point void displayDie(int); //displays a die based on the parameter sent to it void statusAction(); //determines if the user wins money based on their roll and bet void rollType(); //determines if the roll is a ‘hard way’ private: int dieOne; //holds value of one die int dieTwo; //holds value of second die int sum; //holds the sum of the dice int myPoint; //holds the roller’s current point char gameStatus; //c: continue, w: win, l: lost double crapsBalance; //holds the amount the roller has at the table bool passType; //true for pass bet, false for don’t pass double passBet; //amount of the current bet }; Craps Class

  9. In crapsDriver(), making sure the user has money at the table. …if ( choice == 2 ) { if(crapsBalance == 0) { cout << "You don't have any chips to play with. You have to go get chips \n” continue; } In playCraps: switch( sum ) { case 7: case 11: gameStatus = 'w'; break; case 2: case 3: case 12: gameStatus = 'l'; break; default: gameStatus = 'c'; myPoint = sum; break; } // end switch while ( gameStatus == 'c' ) { cout << "Point is " << myPoint << endl; rollDice(); if ( sum == myPoint ) gameStatus = 'w'; else if ( sum == 7 ) gameStatus = 'l'; } statusAction(); Craps Highlights Appropriate call to parent’s constructor: Craps::Craps() casino() {…

  10. 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(); }

  11. 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 onepublic play function

  12. 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

  13. General Functions • void betTypes(); Display the types of bets available • void displayBalance(); Display account balance • void addFunds(); Add funds to balance • void remFunds(); Remove funds from balance • void placeBet(); Betting menu for a spin • void login(); Gets/Creates balance info • void menu(); Displays main menu choices • void writeBalance(); Writes the account balance to a file • int displayNum(int) Display and return the roulette spin number in correct sequence • void clrscr(); Clear the screen

  14. Bet-Specific Functions • void getBet(int) Ask what numbers to bet on • int getAmt(); Ask what amount to bet • int getType(); Ask what type of bet to be placed • void getSingle(); Ask what single number to bet on • void getColumn(); Ask what column to bet on • void getCorner(); Ask what corner to bet on • void getDozen(); Ask what dozen to bet on • void getFive(); Ask what five numbers to bet on • void getLine(); Ask what line to bet on • void getTrio(); Ask what three numbers to bet on • void getSplit(); Ask what two numbers to bet on • bool isWinner(int); Determine whether bet was a winner • bool isRed(int); Determine whether number is red

  15. Colored Console Text • HANDLE Console; • Console = GetStdHandle(STD_OUTPUT_HANDLE); • Color = 10; Bright Green Color • SetConsoleTextAttribute(Console, color); • 0 Black 9 Bright Blue • 1 Dark Blue 10 Bright Green • 2 Dark Green 11 Bright Aqua • 3 Dark Aqua 12 Bright Red • 4 Dark Red 13 Pink • 5 Purple 14 Yellow • 6 Tan 15 Bright White • 7 White 240 Black on White Background • 8 Grey 242 Green on White Background • 252 Red on White Background

  16. 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(); • }

  17. 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"; }

  18. 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; …

  19. 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

  20. 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) • };

  21. Member Function Definitions 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; } • //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;

  22. 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; • }

  23. Setting It All Up //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 = " "; • //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);

  24. 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(); • }

  25. 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 (!(h2->isChecked())) • { • pixcard2.load(seventh); • card2->setPixmap(pixcard2); • finalhand[1] = val7; • } • else • finalhand[1] = val2; • if (!(h3->isChecked())) • { • pixcard3.load(eigth); • card3->setPixmap(pixcard3); • finalhand[2] = val8; • } • else • finalhand[2] = val3; 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;

  26. 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; • } • } • }

  27. 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)); • } • }

  28. 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()); • } • }

  29. 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() • { • }

  30. Blackjack • Programmed by Rolando Herrera • The GUI was developed in QT by Trolltech • The program uses classes and functions set by the QT library

  31. 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()

  32. 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

  33. 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

  34. 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 } }

  35. 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;

  36. 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

  37. 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; //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; } The CodeDeal Function //This is the shuffle function it uses the class blackjackDialogImpl and member function card retrictions // to set random numbers of 1-53 to into the displaying cards, the values are also copied to the cardvalue strings while (bj.cardrestrictions(dcard1,dcard2,dcard3,dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5)) {while (bj.cardrestrictions(dcard2,dcard3,dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e)) {while (bj.cardrestrictions(dcard3,dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e,e)) {while (bj.cardrestrictions(dcard4,dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e,e,e)) {while (bj.cardrestrictions(dcard5,pcard1,pcard2,pcard3,pcard4,pcard5,e,e,e,e)) {while (bj.cardrestrictions(pcard1,pcard2,pcard3,pcard4,pcard5,e,e,e,e,e)) {while (bj.cardrestrictions(pcard2,pcard3,pcard4,pcard5,e,e,e,e,e,e)) {while (bj.cardrestrictions(pcard3,pcard4,pcard5,e,e,e,e,e,e,e)) // {while (bj.cardrestrictions(pcard4,pcard5,e,e,e,e,e,e,e,e))// {while (bj.cardrestrictions(pcard5,e,e,e,e,e,e,e,e,e)) { pcard5 = pcard5value = bj.shuffle(pcard5); } pcard4 = pcard4value = bj.shuffle(pcard4); } pcard3 = pcard3value = bj.shuffle(pcard3); } pcard2 = pcard2value = bj.shuffle(pcard2); } pcard1 = pcard1value = bj.shuffle(pcard1); } dcard5 = dcard5value = bj.shuffle(dcard5); } dcard4 = dcard4value = bj.shuffle(dcard4); } dcard3 = dcard3value = bj.shuffle(dcard3); } dcard2 = dcard2value = bj.shuffle(dcard2); } dcard1 = dcard1value = bj.shuffle(dcard1); } QString blackjackDialogImpl::shuffle(QString card) { card[0]= 48+ rand()%5; card[1]= 48+ rand()%9; return card; }

  38. The Code - hitme function 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); 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

  39. 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(); } }

  40. The Code:Status function 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(); } } }

  41. 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(); }

  42. 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

  43. 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; }

  44. 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

  45. 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

  46. So, the question is….ARE YOU IMPRESSED?

More Related