Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <ctime>
  5. #include <locale.h>
  6. #include <windows.h>
  7. using namespace std;
  8.  
  9. // Alla val i menyn:
  10. void meny();
  11. char val;
  12. void insattning();
  13. void satsning();
  14. void saldo();
  15. void banditen();
  16. void avslutaSpel();
  17. void vinstRegler();
  18. int tal1;       //Summa för insättning
  19. int tal2;       //Summma för satsning
  20. int saldo1 = 0;
  21. int vinster();
  22.  
  23. // Variabler för själv spelet:
  24.  
  25.  
  26. int main()
  27. {
  28.     srand(time(0));
  29.  
  30.     setlocale(LC_ALL, "swedish");
  31.     meny();
  32.     insattning();
  33.     saldo();
  34.     satsning();
  35.     banditen();
  36.  
  37.  
  38.  
  39.     return 0;
  40. }
  41.  
  42.  
  43. void meny() {
  44.  
  45.     while (true) {
  46.         system("cls");
  47.         cout << " Välkommen till Enarmade Banditen " << endl << endl;
  48.         cout << " För att sätt in pengar tryck K " << endl << endl;
  49.         cout << " För att kolla Saldo tryck S " << endl << endl;
  50.         cout << " För att satsa pengar tryck P " << endl << endl;
  51.         cout << " För att spela Enarmade Banditen tryck B " << endl << endl;
  52.         cout << " För att avsluta spelet tryck A " << endl << endl;
  53.         cout << " För att läsa vinstregler tryck R" << endl << endl;
  54.  
  55.         cin >> val;
  56.  
  57.  
  58.  
  59.         if (cin.fail()) {
  60.             cin.clear();
  61.             cin.ignore();
  62.  
  63.  
  64.             cout << "Du har valt ett ogiltigt alternativ!" << endl << endl;
  65.             system("pause");
  66.             system("cls");
  67.         }
  68.  
  69.         else if ((val == 'K' || val == 'k')) {
  70.             insattning();
  71.         }
  72.         else if ((val == 'S' || val == 's')) {
  73.             saldo();
  74.         }
  75.         else if ((val == 'P' || val == 'p')) {
  76.             satsning();
  77.         }
  78.         else if ((val == 'B' || val == 'b')) {
  79.             banditen();
  80.         }
  81.         else if ((val == 'R' || val == 'r')) {
  82.             vinstRegler();
  83.         }
  84.         else if ((val == 'A' || val == 'a')) {
  85.             avslutaSpel();
  86.         }
  87.  
  88.     }
  89. }
  90.  
  91.  
  92. void insattning() {
  93.     system("cls");
  94.     while (true) {
  95.         cout << " Mata in ett tal för insättning 100, 300 eller 500 " << endl;
  96.         cin >> tal1;
  97.         if (tal1 == 100 || tal1 == 300 || tal1 == 500) {
  98.             cout << " Din insättning är Godkänd! " << endl;
  99.             saldo1 = saldo1 + tal1;
  100.             break;
  101.         }
  102.         else {
  103.             cout << " Vänligen välj 100, 300 eller 500 " << endl;
  104.         }
  105.     }
  106. }
  107.  
  108. void saldo() {
  109.     while (val == 's' || val == 'S') {
  110.         cout << " Ditt saldo är nu: " << saldo1 << endl;
  111.         saldo1 = saldo1 + tal1;
  112.         system("pause");
  113.         break;
  114.     }
  115. }
  116.  
  117. void banditen() {
  118.     system("cls");
  119.     cout << "Välkommen till speler Enarmade banditen!" << endl << endl;
  120.     cout << " Din satsning är: " << tal2 << endl;
  121.  
  122.  
  123.     //Här sker spelet
  124.  
  125.     char spelplan[3][3];
  126.     for (int x = 0; x < 3;x++) {
  127.         for (int o = 0; o < 3;o++) {
  128.             int line = rand() % 3 + 1;
  129.             if (line == 1) {
  130.                 spelplan[x][o] = '!';
  131.  
  132.             }
  133.             else if (line == 2) {
  134.                 spelplan[x][o] = '*';
  135.                
  136.             }
  137.             else if (line == 3) {
  138.                 spelplan[x][o] = 'O';
  139.            
  140.             }
  141.             cout << " " << spelplan[x][o] << " ";
  142.         }
  143.        
  144.        
  145.         system("pause");
  146.     }
  147. }
  148.  
  149. int vinster() {
  150.     int vinst;
  151.     for (int vinst line ==1) {
  152.  
  153.     }
  154.     //if blabla
  155.     //vinst++
  156.  
  157.  
  158.  
  159.  
  160.     return vinst;
  161. }
  162.  
  163.  
  164.  
  165. void avslutaSpel() {
  166.     system("cls");
  167.     cout << " Du har valt att avsluta spelet" << endl << endl;
  168.     cout << " Hoppas vi ses igen!" << endl << endl;
  169.     Sleep(500);
  170.     exit(0);
  171.  
  172. }
  173.  
  174. void vinstRegler() {
  175.     system("cls");
  176.     while (val == 'r' || val == 'R') {
  177.         cout << " Vinstregler " << endl << endl;
  178.         cout << " Vinst = 3 lika symboler " << endl << endl;
  179.         cout << " En rad ger 2 * insatsen " << endl << endl;
  180.         cout << " Två rader ger 3 * insatsen " << endl << endl;
  181.         cout << " Tre rader ger 4 * insatsen " << endl << endl;
  182.         cout << " Fyra rader ger 5 * insatsen " << endl << endl;
  183.         cout << " Fem rader ger 7 * insatsen " << endl << endl;
  184.         cout << " Fullt spelfält ger 10 * insatsen " << endl << endl;
  185.         cout << "  " << endl << endl;
  186.         system("pause");
  187.         break;
  188.     }
  189.  
  190. }
  191.  
  192. void satsning() {
  193.     system("cls");
  194.     while (true) {
  195.         cout << " Mata in en summa du vill Satsa i spelet " << endl << endl;
  196.         cin >> tal2;
  197.         if (tal2 <= saldo1) {
  198.             saldo1 = saldo1 - tal2;
  199.             break;
  200.         }
  201.         else {
  202.             cout << "Ditt saldo matchar inte din satsning.." << endl << endl;
  203.         }
  204.     }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement