steamengines

roulette#

Dec 4th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.26 KB | None | 0 0
  1. //Christian Ballard
  2. //COSC 1330 - 003
  3. //This will hopefully be a Roulette game.
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <ctime>
  7. #include <Windows.h>
  8. #include <string>
  9. #include <conio.h>
  10. using namespace std;
  11.  
  12. void welcome();
  13. double funBalance(double &);
  14. int funWinningIndex(int);
  15. void funTables(string tables[5][15]);
  16. double makeBet(double &);
  17. void numberBet(double &);
  18. void makeEvenMoneyBet(double &);
  19. void makeThirdBet(double &);
  20. void make2to1Bet(double &);
  21. void spin();
  22. void cashOutScreen(double);
  23. HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // For use of SetConsoleTextAttribute()
  24. void WaitKey();
  25.  
  26. int main()
  27. {
  28.     double balance = 0;
  29.     int random = 0;
  30.     string tables[5][15] =
  31.     { { "0", "3", "6", "9", "12", "15", "18", "21", "24", "27", "30", "33", "36", "2 to 1" },
  32.     { "2", "5", "8", "11", "14", "17", "20", "23", "26", "29", "32", "35", "2 to 1" },
  33.     { "1", "4", "7", "10", "13", "16", "19", "22", "25", "28", "31", "34", "2 to 1" },
  34.     { "1st 12", "2nd 12", "3rd 12" },
  35.     { "1-18", "Even", "Red", "Black", "Odd", "19-36" }};
  36.  
  37.     cout << fixed << setprecision(2);
  38.     srand(static_cast<int>(time(0)));
  39.  
  40.     welcome();
  41.     system("cls");
  42.     balance = funBalance(balance);
  43.     system("cls");
  44.     cout << "Your current balance is $" << balance << endl;
  45.  
  46.     funTables(tables);
  47.     cout << endl;
  48.     makeBet(balance);
  49.  
  50.    
  51.  
  52.  
  53.  
  54.  
  55.     system("pause");
  56.     return 0;
  57. }
  58.  
  59. void welcome()
  60. {
  61.     int len = 0, x, y = 240;
  62.  
  63.     string text = "ROULETTE";
  64.     len = text.length();
  65.     cout << endl << endl << endl << "\t\t\t\t";
  66.     for (x = 0; x<len; x++)
  67.     {
  68.         SetConsoleTextAttribute(console, y);
  69.         cout << text[x];
  70.         y++;
  71.         if (y >254)
  72.             y = 240;
  73.         Sleep(250);
  74.     }
  75.  
  76.     SetConsoleTextAttribute(console, 15);
  77.     WaitKey();
  78.    
  79. }
  80.  
  81. double funBalance(double &balance)
  82. {
  83.     cout << "How much money would you like to play at the table?" << endl << "$";
  84.     cin >> balance;
  85.     return balance;
  86. }
  87.  
  88. int funWinningIndex()
  89. {
  90.     int funWinningIndex = 0;
  91.  
  92.     funWinningIndex = 0 + rand() % (36 - 0 + 1);
  93.  
  94.     return funWinningIndex;
  95. }
  96.  
  97.  
  98. void funTables(string tables[5][15])
  99. {
  100.    
  101.     cout << "-==================================================================-" << endl;
  102.     cout << "|   || 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 || 2 |" << endl;
  103.     cout << "| 0  | 2 | 5 | 8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 32 | 35 | to |" << endl;
  104.     cout << "|   || 1 | 4 | 7 | 10 | 13 | 16 | 19 | 22 | 25 | 28 | 31 | 34 || 1 |" << endl;
  105.     cout << "-==================================================================-" << endl;
  106.     cout << "     |    First Twelve     |   Second Twelve   |    Third Twelve   |" << endl;
  107.     cout << "     |  1 - 18   |   Even  |   Red   |  Black  |   Odd   | 19 - 36 |" << endl;
  108.     cout << "     -=============================================================-" << endl;
  109.  
  110. }
  111.  
  112. double makeBet(double &balance)
  113. {
  114.  
  115.     double newBalance = 0.0;
  116.     int whatBet = 0;
  117.     char anotherBet = ' ';
  118.  
  119.     do
  120.     {
  121.         cout << "Which type of bet would you like to make?" << endl << "1.) Number" << endl << "2.) Even Money" << endl << "3.) Third" << endl << "4.) 2 to 1" << endl << "5.) No more bets" << endl;
  122.         cin >> whatBet;
  123.  
  124.         //switch for the bets
  125.         switch (whatBet)
  126.         {
  127.         case 1:
  128.             numberBet(balance);
  129.             break;
  130.         case 2:
  131.             makeEvenMoneyBet(balance);
  132.             break;
  133.         case 3:
  134.             makeThirdBet(balance);
  135.             break;
  136.         case 4:
  137.             make2to1Bet(balance);
  138.             break;
  139.         case 5:
  140.             system("cls");
  141.             break;
  142.         default:
  143.             cout << "Invalid Input, please enter a number 1-5.";
  144.         }
  145.         cout << "Would you like to make another bet? (Y/N) ";
  146.         cin >> anotherBet;
  147.         toupper(anotherBet);
  148.     } while (anotherBet == 'Y');
  149.     {
  150.         cout << "Thanks for playing!" << endl;
  151.         cashOutScreen(balance);
  152.     }
  153.  
  154.     return balance;
  155. }
  156.  
  157. void numberBet(double &balance)
  158. {
  159.     int selectedNumber = 0;
  160.     double betAmount = 0.0;
  161.  
  162.     do
  163.     {
  164.         cout << "Please enter the number you would like to bet on: ";
  165.         cin >> selectedNumber;
  166.         if (selectedNumber <= 36 && selectedNumber >= 0)
  167.         {
  168.             {
  169.                 cout << "Enter the bet amount: ";
  170.                 cin >> betAmount;
  171.             }
  172.         }
  173.         else
  174.         {
  175.             cout << "This number is not on the roulette table, please try again." << endl;
  176.         }
  177.    
  178.     } while (selectedNumber >= 36 || selectedNumber <= 0); {
  179.         if (balance > betAmount && balance == funWinningIndex())
  180.         {
  181.             balance = betAmount * 35;
  182.         }
  183.         else if (balance != funWinningIndex())
  184.         {
  185.             cout << "Sorry you're a LOSER." << endl;
  186.             balance = balance - betAmount;
  187.         }
  188.         else
  189.         {
  190.             cout << "Sorry, you don't have that much money." << endl;
  191.         }
  192.     }
  193. }
  194.  
  195. void makeEvenMoneyBet(double &balance)
  196. {
  197.     double betAmount = 0.0;
  198.     int typeOfEvenMoneyBet = 0;
  199.     cout << "Which even money bet would you like to make?" << endl << "1.) 1 to 18" << endl << "2.) 19 to 36" << endl << "3.) Even" << endl << "4.) Odd" << endl << "5.) Red" << endl << "6.) Black" << endl;
  200.     cin >> typeOfEvenMoneyBet;
  201.  
  202.     //Switch for the even money bets
  203.     switch (typeOfEvenMoneyBet)
  204.     {
  205.     case 1:
  206.         cout << "Please enter the bet amount: $";
  207.         cin >> betAmount;
  208.         if (balance > betAmount && balance == funWinningIndex())
  209.         {
  210.             balance = betAmount * 2;
  211.         }
  212.         else if (balance != funWinningIndex())
  213.         {
  214.             cout << "Sorry you're a LOSER." << endl;
  215.             balance = balance - betAmount;
  216.         }
  217.         else
  218.         {
  219.             cout << "Sorry, you don't have that much money." << endl;
  220.         }
  221.         break;
  222.     case 2:
  223.         cout << "Please enter the bet amount: $";
  224.         cin >> betAmount;
  225.         if (balance > betAmount && balance == funWinningIndex())
  226.         {
  227.             balance = betAmount * 2;
  228.         }
  229.         else if (balance != funWinningIndex())
  230.         {
  231.             cout << "Sorry you're a LOSER." << endl;
  232.             balance = balance - betAmount;
  233.         }
  234.         else
  235.         {
  236.             cout << "Sorry, you don't have that much money." << endl;
  237.         }
  238.         break;
  239.     case 3:
  240.         cout << "Please enter the bet amount: $";
  241.         cin >> betAmount;
  242.         if (balance > betAmount && balance == funWinningIndex())
  243.         {
  244.             balance = betAmount * 2;
  245.         }
  246.         else if (balance != funWinningIndex())
  247.         {
  248.             cout << "Sorry you're a LOSER." << endl;
  249.             balance = balance - betAmount;
  250.         }
  251.         else
  252.         {
  253.             cout << "Sorry, you don't have that much money." << endl;
  254.         }
  255.         break;
  256.     case 4:
  257.         cout << "Please enter the bet amount: $";
  258.         cin >> betAmount;
  259.         if (balance > betAmount && balance == funWinningIndex())
  260.         {
  261.             balance = betAmount * 2;
  262.         }
  263.         else if (balance != funWinningIndex())
  264.         {
  265.             cout << "Sorry you're a LOSER." << endl;
  266.             balance = balance - betAmount;
  267.         }
  268.         else
  269.         {
  270.             cout << "Sorry, you don't have that much money." << endl;
  271.         }
  272.         break;
  273.     case 5:
  274.         cout << "Please enter the bet amount: $";
  275.         cin >> betAmount;
  276.         if (balance > betAmount && balance == funWinningIndex())
  277.         {
  278.             balance = betAmount * 2;
  279.         }
  280.         else if (balance != funWinningIndex())
  281.         {
  282.             cout << "Sorry you're a LOSER." << endl;
  283.             balance = balance - betAmount;
  284.         }
  285.         else
  286.         {
  287.             cout << "Sorry, you don't have that much money." << endl;
  288.         }
  289.         break;
  290.     case 6:
  291.         cout << "Please enter the bet amount: $";
  292.         cin >> betAmount;
  293.         if (balance > betAmount && balance == funWinningIndex())
  294.         {
  295.             balance = betAmount * 2;
  296.         }
  297.         else if (balance != funWinningIndex())
  298.         {
  299.             cout << "Sorry you're a LOSER." << endl;
  300.             balance = balance - betAmount;
  301.         }
  302.         else
  303.         {
  304.             cout << "Sorry, you don't have that much money." << endl;
  305.         }
  306.         break;
  307.     default:
  308.         cout << "Invalid Input, please enter a number 1-6.";
  309.     }
  310. }
  311.  
  312. void makeThirdBet(double &balance)
  313. {
  314.     double betAmount = 0.0;
  315.     int typeOfThirdBet = 0;
  316.     cout << "Which third would you like to bet on?" << endl << "1.) First 12" << endl << "2.) Second 12" << endl << "3.) Third 12" << endl;
  317.     cin >> typeOfThirdBet;
  318.  
  319.     switch (typeOfThirdBet)
  320.     {
  321.     case 1:
  322.         cout << "Please enter the bet amount: $";
  323.         cin >> betAmount;
  324.         if (balance > betAmount && balance == funWinningIndex())
  325.         {
  326.             balance = betAmount * 3;
  327.         }
  328.         else if (balance != funWinningIndex())
  329.         {
  330.             cout << "Sorry you're a LOSER." << endl;
  331.             balance = balance - betAmount;
  332.         }
  333.         else
  334.         {
  335.             cout << "Sorry, you don't have that much money." << endl;
  336.         }
  337.         break;
  338.     case 2:
  339.         cout << "Please enter the bet amount: $";
  340.         cin >> betAmount;
  341.         if (balance > betAmount && balance == funWinningIndex())
  342.         {
  343.             balance = betAmount * 3;
  344.         }
  345.         else if (balance != funWinningIndex())
  346.         {
  347.             cout << "Sorry you're a LOSER." << endl;
  348.             balance = balance - betAmount;
  349.         }
  350.         else
  351.         {
  352.             cout << "Sorry, you don't have that much money." << endl;
  353.         }
  354.         break;
  355.     case 3:
  356.         cout << "Please enter the bet amount: $";
  357.         cin >> betAmount;
  358.         if (balance > betAmount && balance == funWinningIndex())
  359.         {
  360.             balance = betAmount * 3;
  361.         }
  362.         else if (balance != funWinningIndex())
  363.         {
  364.             cout << "Sorry you're a LOSER." << endl;
  365.             balance = balance - betAmount;
  366.         }
  367.         else
  368.         {
  369.             cout << "Sorry, you don't have that much money." << endl;
  370.         }
  371.         break;
  372.     default:
  373.         cout << "Invalid Input, please enter a number 1-3.";
  374.  
  375.     }
  376.  
  377. }
  378.  
  379. void make2to1Bet(double &balance)
  380. {
  381.     double betAmount = 0.0;
  382.     int typeOf2to1Bet = 0;
  383.     cout << "Which section would you like to bet on?" << endl << "1.) Top Row" << endl << "2.) Middle Row" << endl << "3.) Bottom Row" << endl;
  384.     cin >> typeOf2to1Bet;
  385.  
  386.     switch (typeOf2to1Bet)
  387.     {
  388.     case 1:
  389.         cout << "Please enter the bet amount: $";
  390.         cin >> betAmount;
  391.         if (balance > betAmount && balance == funWinningIndex())
  392.         {
  393.             balance = betAmount * 3;
  394.         }
  395.         else if (balance != funWinningIndex())
  396.         {
  397.             cout << "Sorry you're a LOSER." << endl;
  398.             balance = balance - betAmount;
  399.         }
  400.         else
  401.         {
  402.             cout << "Sorry, you don't have that much money." << endl;
  403.         }
  404.     case 2:
  405.         cout << "Please enter the bet amount: $";
  406.         cin >> betAmount;
  407.         if (balance > betAmount && balance == funWinningIndex())
  408.         {
  409.             balance = betAmount * 3;
  410.         }
  411.         else if (balance != funWinningIndex())
  412.         {
  413.             cout << "Sorry you're a LOSER." << endl;
  414.             balance = balance - betAmount;
  415.         }
  416.         else
  417.         {
  418.             cout << "Sorry, you don't have that much money." << endl;
  419.         }
  420.     case 3:
  421.         cout << "Please enter the bet amount: $";
  422.         cin >> betAmount;
  423.         if (balance > betAmount && balance == funWinningIndex())
  424.         {
  425.             balance = betAmount * 3;
  426.         }
  427.         else if (balance != funWinningIndex())
  428.         {
  429.             cout << "Sorry you're a LOSER." << endl;
  430.             balance = balance - betAmount;
  431.         }
  432.         else
  433.         {
  434.             cout << "Sorry, you don't have that much money." << endl;
  435.         }
  436.     default:
  437.         cout << "Invalid Input, please enter a number 1-3.";
  438.  
  439.     }
  440. }
  441.  
  442. void cashOutScreen(double balance)
  443. {
  444.     system("cls");
  445.     cout << "***************************************************" << endl;
  446.     cout << "*                                                 *" << endl;
  447.     cout << "*                                                 *" << endl;
  448.     cout << "*                                                 *" << endl;
  449.     cout << "*                                                 *" << endl;
  450.     cout << "*              Your payout is $" << balance << "             *" << endl;
  451.     cout << "*                                                 *" << endl;
  452.     cout << "*                                                 *" << endl;
  453.     cout << "*                                                 *" << endl;
  454.     cout << "*                                                 *" << endl;
  455.     cout << "***************************************************" << endl;
  456.  
  457.  
  458. }
  459.  
  460. void WaitKey()
  461. {
  462.     cout << endl << endl << endl << "\t\t\tPress any key";
  463.     while (_kbhit()) _getch();
  464.     _getch();
  465.     while (_kbhit()) _getch();
  466. }
Advertisement
Add Comment
Please, Sign In to add comment