Advertisement
ivanwidyan

Slot Machine Game

Oct 19th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.49 KB | None | 0 0
  1. /* This code is originally written by me for the example of my tutorials
  2. which you can check on my website. If you ask why am I not using Array, Maps, Class
  3. or another functions in C++, it's because my tutorial hasn't reach that part. But if you
  4. want to change the code using other functions it's better! :)
  5.  
  6. Enjoy this simple Slot Machine Game
  7.  
  8. ivanwidyan.com
  9. */
  10.  
  11. #pragma once
  12.  
  13. #include <ctime>
  14. #include <cstdlib>
  15. #include <iostream>
  16. using namespace std;
  17.  
  18. int insertCoin = 0;
  19. int Coins = 25;
  20. bool exitGame = false;
  21.  
  22. int randRange(int, int);
  23. void PlayGame(), MenuGame(), RandomizingSlot(),
  24. PrintingItems(int), Combination(int, int, int);
  25.  
  26. enum menuLists {Play = 1, Help = 2, Exit = 3};
  27. enum slotItems {Cherry, Bell, Orange, Bar, Seven};
  28.  
  29. int main() {
  30.     srand(time(NULL));
  31.     MenuGame();
  32.     if (exitGame) {
  33.         return 0;
  34.     }
  35. }
  36.  
  37. void MenuGame() {
  38.     int input = 0;
  39.     Coins = 25;
  40.     insertCoin = 0;
  41.     cout << "WELCOME TO 777 SIMPLE SLOT GAME" << endl;
  42.     cout << "           .-------." << endl;
  43.     cout << "        oO{-  777  -}Oo" << endl;
  44.     cout << "        .=============. __" << endl;
  45.     cout << "        | [a] [X] [o] |(  )" << endl;
  46.     cout << "        | [$] [$] [$] | ||" << endl;
  47.     cout << "        | [X] [o] [$] | ||" << endl;
  48.     cout << "        |             |_||" << endl;
  49.     cout << "        | xxx ::::::: |--'" << endl;
  50.     cout << "        | ooo ::::::: |" << endl;
  51.     cout << "        | $$$ ::::::: |" << endl;
  52.     cout << "        |             |" << endl;
  53.     cout << "        |      __ === |" << endl;
  54.     cout << "        |_____/__\____|" << endl;
  55.     cout << "       /###############\\" << endl;
  56.     cout << "      /#################\\" << endl;
  57.     cout << "     |###################|" << endl;
  58.     cout << "1. PLAY" << endl;
  59.     cout << "2. EXIT" << endl;
  60.     cout << "Type your number: ";
  61.     cin >> input;
  62.     switch (input) {
  63.     case Play:
  64.         cout << endl;
  65.         PlayGame();
  66.         break;
  67.     case Exit:
  68.         exitGame = true;
  69.         break;
  70.     default:
  71.         cout << "Type the correct number" << endl;
  72.         break;
  73.     }
  74. }
  75.  
  76. void PlayGame() {
  77.     insertCoin = 0;
  78.     while (Coins > 0) {
  79.         cout << "You have " << Coins << " amount of coins" << endl;
  80.         cout << "Insert coin (1 - 3): ";
  81.         cin >> insertCoin;
  82.         if (insertCoin >= 1 && insertCoin <= 3) {
  83.             RandomizingSlot();
  84.             cout << endl;
  85.         }
  86.         else {
  87.             cout << "Type amount of coins between 1 - 3" << endl;
  88.             PlayGame();
  89.         }  
  90.     }
  91.     cout << "YOU LOSE! You don't have any coin to play" << endl;
  92.     cout << endl;
  93.     MenuGame();
  94. }
  95.  
  96. void RandomizingSlot() {
  97.     int firstSlot = randRange(0, 5);
  98.     int secondSlot = randRange(0, 5);
  99.     int thirdSlot = randRange(0, 5);
  100.     firstSlot = 2;
  101.     secondSlot = 2;
  102.     thirdSlot = 2;
  103.     PrintingItems(firstSlot);
  104.     PrintingItems(secondSlot);
  105.     PrintingItems(thirdSlot);
  106.     cout << endl;
  107.     Combination(firstSlot, secondSlot, thirdSlot);
  108.     cout << endl;
  109. }
  110.  
  111. void PrintingItems(int input) {
  112.     switch (input) {
  113.     case Cherry:
  114.         cout << "Cherry ";
  115.         break;
  116.     case Bell:
  117.         cout << "Bell ";
  118.         break;
  119.     case Orange:
  120.         cout << "Orange ";
  121.         break;
  122.     case Bar:
  123.         cout << "Bar ";
  124.         break;
  125.     case Seven:
  126.         cout << "7 ";
  127.         break;
  128.     default:
  129.         break;
  130.     }
  131. }
  132.  
  133. void Combination(int firstitems, int seconditems, int thirditems) {
  134.     bool tripleCherry = false;
  135.     if (firstitems == Seven && seconditems == Seven && thirditems == Seven) {
  136.         if (insertCoin == 1) {
  137.             cout << "You Get 100 coin!" << endl;
  138.             Coins += 100;
  139.         }
  140.         else if (insertCoin == 2) {
  141.             cout << "You Get 100 coin!" << endl;
  142.             Coins += 200;
  143.         }
  144.         else if (insertCoin == 3) {
  145.             cout << "JACKPOT! You Get 25000 coin!" << endl;
  146.             Coins += 25000;
  147.         }
  148.     }
  149.     else if ((firstitems == Bar && seconditems == Bell && thirditems == Bell) ||
  150.         (firstitems == Bell && seconditems == Bar && thirditems == Bell) ||
  151.         (firstitems == Bell && seconditems == Bell && thirditems == Bar)) {
  152.         if (firstitems)
  153.             if (insertCoin == 1) {
  154.                 cout << "You Get 15 coin!" << endl;
  155.                 Coins += 15;
  156.             }
  157.             else if (insertCoin == 2) {
  158.                 cout << "You Get 30 coin!" << endl;
  159.                 Coins += 30;
  160.             }
  161.             else if (insertCoin == 3) {
  162.                 cout << "You Get 45 coin!" << endl;
  163.                 Coins += 45;
  164.             }
  165.     }
  166.     else if ((firstitems == Bar && seconditems == Orange && thirditems == Orange) ||
  167.         (firstitems == Orange && seconditems == Bar && thirditems == Orange) ||
  168.         (firstitems == Orange && seconditems == Orange && thirditems == Bar)) {
  169.         if (firstitems)
  170.             if (insertCoin == 1) {
  171.                 cout << "You Get 15 coin!" << endl;
  172.                 Coins += 15;
  173.             }
  174.             else if (insertCoin == 2) {
  175.                 cout << "You Get 30 coin!" << endl;
  176.                 Coins += 30;
  177.             }
  178.             else if (insertCoin == 3) {
  179.                 cout << "You Get 45 coin!" << endl;
  180.                 Coins += 45;
  181.             }
  182.     }
  183.     else if (firstitems == Cherry && seconditems == Cherry && thirditems == Cherry) {
  184.         if (insertCoin == 1) {
  185.             cout << "You Get 10 coin!" << endl;
  186.             Coins += 10;
  187.         }
  188.         else if (insertCoin == 2) {
  189.             cout << "You Get 20 coin!" << endl;
  190.             Coins += 20;
  191.         }
  192.         else if (insertCoin == 3) {
  193.             cout << "You Get 30 coin!" << endl;
  194.             Coins += 30;
  195.         }
  196.         tripleCherry = true;
  197.     }
  198.     else if (firstitems == Bar && seconditems == Bar && thirditems == Bar) {
  199.         if (insertCoin == 1) {
  200.             cout << "You Get 5 coin!" << endl;
  201.             Coins += 5;
  202.         }
  203.         else if (insertCoin == 2) {
  204.             cout << "You Get 10 coin!" << endl;
  205.             Coins += 10;
  206.         }
  207.         else if (insertCoin == 3) {
  208.             cout << "You Get 15 coin!" << endl;
  209.             Coins += 15;
  210.         }
  211.     }
  212.     else if (firstitems == Orange && seconditems == Orange && thirditems == Orange) {
  213.         if (insertCoin == 1) {
  214.             cout << "You Get 5 coin!" << endl;
  215.             Coins += 5;
  216.         }
  217.         else if (insertCoin == 2) {
  218.             cout << "You Get 10 coin!" << endl;
  219.             Coins += 10;
  220.         }
  221.         else if (insertCoin == 3) {
  222.             cout << "You Get 15 coin!" << endl;
  223.             Coins += 15;
  224.         }
  225.     }
  226.     else if (firstitems == Bell && seconditems == Bell && thirditems == Bell) {
  227.         if (insertCoin == 1) {
  228.             cout << "You Get 5 coin!" << endl;
  229.             Coins += 5;
  230.         }
  231.         else if (insertCoin == 2) {
  232.             cout << "You Get 10 coin!" << endl;
  233.             Coins += 10;
  234.         }
  235.         else if (insertCoin == 3) {
  236.             cout << "You Get 15 coin!" << endl;
  237.             Coins += 15;
  238.         }
  239.     }
  240.     else if ((firstitems == Orange || seconditems == Orange || thirditems == Orange) &&
  241.         tripleCherry == false) {
  242.         if (firstitems)
  243.             if (insertCoin == 1) {
  244.                 cout << "You Get 2 coin!" << endl;
  245.                 Coins += 2;
  246.             }
  247.             else if (insertCoin == 2) {
  248.                 cout << "You Get 4 coin!" << endl;
  249.                 Coins += 4;
  250.             }
  251.             else if (insertCoin == 3) {
  252.                 cout << "You Get 6 coin!" << endl;
  253.                 Coins += 6;
  254.             }
  255.     }
  256.     tripleCherry = false;
  257. }
  258.  
  259. int randRange(int low, int high) {
  260.     return rand() % (high - low) + low;
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement