Advertisement
pjobro

casino luk

Mar 25th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.37 KB | None | 0 0
  1. // Casino.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. /* BAZA U OBLIKU baza.txt
  5.  
  6. NICK IGRA DOBITAK
  7.  
  8. npr:
  9. luka 1 34252
  10. marko 2 4823
  11. pero 3 1234
  12. */
  13.  
  14. #include "stdafx.h"
  15. #include <iostream>
  16. #include <string>
  17. #include <fstream>
  18. #include <ctime>
  19. #include <cstdlib>
  20. #include <vector>
  21.  
  22. #define PSTAT_MENU 0
  23. #define PSTAT_REGI 1
  24.  
  25. using namespace std;
  26.  
  27. void resetPlayer();
  28. void registerPlayer();
  29. void showLogo();
  30. int showMenu();
  31. void uplataChipova();
  32. void isplataNovaca();
  33. void loadScores();
  34. void saveScores();
  35. void showScores();
  36. int showGames();
  37. bool checkChips(int amount);
  38. void playingDuplo();
  39. string cardName(int card);
  40. int cardValue(int card);
  41. void playingKockice();
  42. void playingJednoruki();
  43. void printMachine(int a, int b, int c, int d);
  44. void printPoints(int ulog);
  45. string gameName(int game);
  46.  
  47. struct Player
  48. {
  49.     int state;
  50.     int cash;
  51.     int chips;
  52.     string name;
  53. };
  54.  
  55. struct Game
  56. {
  57.     string name;
  58.     int game;
  59.     int score;
  60. };
  61.  
  62. Player pInfo;
  63.  
  64. vector<Game> gInfo;
  65.  
  66. int main()
  67. {
  68.     // Ucitavanje funkcija
  69.     srand(time(NULL));
  70.     resetPlayer();
  71.     loadScores();
  72.  
  73.     // Postavljanje memorije
  74.     bool exitProgram = false;
  75.  
  76.     // Izvodenje programa
  77.     while (!exitProgram)
  78.     {
  79.         showLogo();
  80.  
  81.         if ((pInfo.cash < 10 && pInfo.chips == 0) && pInfo.state != PSTAT_REGI)
  82.         {
  83.             cout << "Ostao si bez novaca i nemozes vise igrati !" << endl;
  84.             cout << "STANJE NOVACA: " << pInfo.cash << endl;
  85.             cout << "STANJE CHIPOVA: " << pInfo.chips << endl << endl;
  86.             cout << "MOLIMO TE NAPUSTI KASINO KLIKOM..." << endl;
  87.  
  88.             system("pause>nul");
  89.             break;
  90.         }
  91.  
  92.         switch (pInfo.state)
  93.         {
  94.         case PSTAT_REGI: // Upis imena i kolicine novca
  95.             registerPlayer();
  96.             break;
  97.  
  98.         case PSTAT_MENU: // Bira igru
  99.  
  100.             switch (showMenu())
  101.             {
  102.             case 1: // Izabere uplatu chipova
  103.                 uplataChipova();
  104.                 break;
  105.  
  106.             case 2: // Izabere isplatu novaca
  107.                 isplataNovaca();
  108.                 break;
  109.  
  110.             case 3: // Izabire igru
  111.  
  112.                 showLogo();
  113.  
  114.                 switch (showGames())
  115.                 {
  116.                 case 1: // Izabire jednoruki jack
  117.                     if (!checkChips(10))
  118.                     {
  119.                         break;
  120.                     }
  121.                     playingJednoruki();
  122.                     break;
  123.                 case 2: // Izabire bacanje kockica
  124.                     if (!checkChips(10))
  125.                     {
  126.                         break;
  127.                     }
  128.                     playingKockice();
  129.                     break;
  130.                 case 3: // Izabire duplo ili nista
  131.                     if (!checkChips(5))
  132.                     {
  133.                         break;
  134.                     }
  135.                     playingDuplo();
  136.                     break;
  137.                 case 4: // Izabire povratak
  138.                     break;
  139.                 default:
  140.                     break;
  141.                 }
  142.                 break;
  143.  
  144.             case 4: // Izabere prikaz High score-a
  145.                 showScores();
  146.                 break;
  147.  
  148.             case 5: // Izlaz iz programa
  149.                 exitProgram = true;
  150.                 break;
  151.  
  152.             default: // Krivi izbor
  153.                 break;
  154.             }
  155.  
  156.             break;
  157.         }
  158.     }
  159.  
  160.     cout << "KLIKNI ZA IZLAZ IZ PROGRAMA..." << endl;
  161.     system("pause>nul");
  162.     saveScores();
  163.  
  164.     return 0;
  165. }
  166.  
  167. void resetPlayer()
  168. {
  169.     pInfo.state = PSTAT_REGI;
  170.     pInfo.cash = 0;
  171.     pInfo.chips = 0;
  172.     pInfo.name = "username";
  173. }
  174.  
  175. void registerPlayer()
  176. {
  177.     cout << "Pozdrav novi korisnice, upisi svoje podatke kako" << endl;
  178.     cout << "bi krenuo sa igrom u BootCampIT Casinu !" << endl;
  179.     cout << endl;
  180.     cout << "INFO: Svi igraci imaju pristup otvorenom sanku ! :)" << endl;
  181.     cout << endl << endl;
  182.  
  183.     cout << "Upisi svoje ime: " << endl;
  184.     cin >> pInfo.name;
  185.     cout << endl;
  186.  
  187.     cout << "Upisi koliko novaca imas: " << endl;
  188.     cin >> pInfo.cash;
  189.     cout << endl << endl;;
  190.  
  191.     cout << pInfo.name << " dobrodosao u BootCampIT Casino !" << endl;
  192.     cout << "KLIKNI ZA NASTAVAK..." << endl;
  193.     system("pause>nul");
  194.  
  195.     pInfo.state = PSTAT_MENU;
  196. }
  197.  
  198. void showLogo()
  199. {
  200.     system("cls");
  201.     cout << "|---------------------------------------------------|" << endl;
  202.     cout << "|               BootCampIT Casino                   |" << endl;
  203.     cout << "|---------------------------------------------------|" << endl;
  204.     cout << endl;
  205. }
  206.  
  207. int showMenu()
  208. {
  209.     int temp = -1;
  210.  
  211.     cout << "IZBORNIK: " << endl << endl;
  212.     cout << "\t1\tUplata novaca (novci za chipove)" << endl;
  213.     cout << "\t2\tIsplata novaca (chipovi za novce)" << endl;
  214.     cout << "\t3\tOdabir igre" << endl;
  215.     cout << "\t4\tHigh score" << endl;
  216.     cout << "\t5\tIzlaz iz programa" << endl << endl;
  217.     cout << "UPISI BROJ ZA IZBOR: " << endl;
  218.  
  219.     cin >> temp;
  220.  
  221.     return temp;
  222. }
  223.  
  224. void uplataChipova()
  225. {
  226.     bool odabir = false;
  227.    
  228.     int temp = 0;
  229.  
  230.     while (!odabir)
  231.     {
  232.         while (temp < 1 || temp > pInfo.cash / 5)
  233.         {
  234.             showLogo();
  235.  
  236.             cout << "STANJE NOVACA: " << pInfo.cash << endl;
  237.             cout << "STANJE CHIPOVA: " << pInfo.chips << endl << endl;
  238.             cout << "MIN BROJ CHIPOVA ZA KUPIT: 1" << endl;
  239.             cout << "MAX BROJ CHIPOVA ZA KUPIT: " << pInfo.cash / 5 << endl << endl;
  240.             cout << "Upisi kolicinu chipova koju zelis kupit (0 = IZLAZ): " << endl;
  241.  
  242.             cin >> temp;
  243.  
  244.             if (temp == 0)
  245.             {
  246.                 showLogo();
  247.  
  248.                 cout << endl << "ODUSTAO SI OD UNOSA !\nKLIKNI ZA POVRATAK...";
  249.                 system("pause>nul");
  250.                 return;
  251.             }
  252.             if (temp < 1)
  253.             {
  254.                 showLogo();
  255.  
  256.                 cout << endl << "IZNOS NEMOZE BITI MANJI OD 0 !\nKLIKNI ZA NOVI UNOS...";
  257.                 system("pause>nul");
  258.             }
  259.             if (temp > pInfo.cash / 5)
  260.             {
  261.                 showLogo();
  262.  
  263.                 cout << endl << "NEMAS TOLIKO NOVCA !\nKLIKNI ZA NOVI UNOS...";
  264.                 system("pause>nul");
  265.             }
  266.  
  267.         }
  268.  
  269.         cout << endl<< "Zamjeni " << temp * 5 << " novaca za " << temp << " chipova ? (DA/NE)" << endl;
  270.  
  271.         string dane;
  272.         cin >> dane;
  273.  
  274.         if (dane == "DA" || dane == "da")
  275.         {
  276.             pInfo.chips += temp;
  277.             pInfo.cash -= temp * 5;
  278.  
  279.             showLogo();
  280.  
  281.             cout << "NOVO STANJE NOVACA: " << pInfo.cash << endl;
  282.             cout << "NOVO STANJE CHIPOVA: " << pInfo.chips << endl << endl;
  283.             cout << endl << "CESTITAMO NA KUPOVINI !\nKLIKNI ZA NASTAVAK...";
  284.             system("pause>nul");
  285.             odabir = true;
  286.         }
  287.         else
  288.         {
  289.             cout << "ODUSTAO SI OD ZAMJENE !\n\nKLIKNI ZA POVRATAK..." << endl;
  290.             system("pause>nul");
  291.             return;
  292.         }
  293.     }
  294. }
  295.  
  296. void isplataNovaca()
  297. {
  298.     bool odabir = false;
  299.  
  300.     int temp = 0;
  301.  
  302.     while (!odabir)
  303.     {
  304.         while (temp < 1 || temp > pInfo.chips)
  305.         {
  306.             showLogo();
  307.  
  308.             cout << "STANJE NOVACA: " << pInfo.cash << endl;
  309.             cout << "STANJE CHIPOVA: " << pInfo.chips << endl << endl;
  310.             cout << "MIN BROJ CHIPOVA ZA PRODAT: 1" << endl;
  311.             cout << "MAX BROJ CHIPOVA ZA PRODAT: " << pInfo.chips << endl << endl;
  312.             cout << "Upisi kolicinu chipova koju zelis prodat (0 = IZLAZ): " << endl;
  313.  
  314.             cin >> temp;
  315.  
  316.             if (temp == 0)
  317.             {
  318.                 showLogo();
  319.  
  320.                 cout << endl << "ODUSTAO SI OD UNOSA !\nKLIKNI ZA POVRATAK...";
  321.                 system("pause>nul");
  322.                 return;
  323.             }
  324.             if (temp < 1)
  325.             {
  326.                 showLogo();
  327.  
  328.                 cout << endl << "IZNOS NEMOZE BITI MANJI OD 0 !\nKLIKNI ZA NOVI UNOS...";
  329.                 system("pause>nul");
  330.             }
  331.             if (temp > pInfo.chips)
  332.             {
  333.                 showLogo();
  334.  
  335.                 cout << endl << "NEMAS TOLIKO CHIPOVA !\nKLIKNI ZA NOVI UNOS...";
  336.                 system("pause>nul");
  337.             }
  338.  
  339.         }
  340.  
  341.         cout << endl << "Zamjeni " << temp << " chipova za " << temp * 5 << " novaca ? (DA/NE)" << endl;
  342.  
  343.         string dane;
  344.         cin >> dane;
  345.  
  346.         if (dane == "DA" || dane == "da")
  347.         {
  348.             pInfo.chips -= temp;
  349.             pInfo.cash += temp * 5;
  350.  
  351.             showLogo();
  352.  
  353.             cout << "NOVO STANJE NOVACA: " << pInfo.cash << endl;
  354.             cout << "NOVO STANJE CHIPOVA: " << pInfo.chips << endl << endl;
  355.             cout << endl << "CESTITAMO NA KUPOVINI !\nKLIKNI ZA NASTAVAK...";
  356.             system("pause>nul");
  357.             odabir = true;
  358.         }
  359.         else
  360.         {
  361.             cout << "ODUSTAO SI OD ZAMJENE !\n\nKLIKNI ZA POVRATAK..." << endl;
  362.             system("pause>nul");
  363.             return;
  364.         }
  365.     }
  366. }
  367.  
  368. void loadScores()
  369. {
  370.     ifstream input("baza.txt");
  371.  
  372.     string line;
  373.  
  374.     while (input)
  375.     {
  376.         Game nesto;
  377.  
  378.         getline(input, line, ' ');
  379.         nesto.name = line;
  380.         getline(input, line, ' ');
  381.         nesto.game = stoi(line);
  382.         getline(input, line);
  383.         nesto.score = stoi(line);
  384.  
  385.         gInfo.push_back(nesto);
  386.     }
  387.     input.close();
  388.     gInfo.pop_back();
  389. }
  390.  
  391. void saveScores()
  392. {
  393.     string za_spremanje;
  394.  
  395.     if (gInfo.size() == 0)
  396.     {
  397.         return;
  398.     }
  399.  
  400.     for (int i = 0; i < gInfo.size(); i++)
  401.     {
  402.         if (i != 0)
  403.         {
  404.             za_spremanje += "\n";
  405.         }
  406.  
  407.         za_spremanje += gInfo[i].name + " " + to_string(gInfo[i].game) + " " + to_string(gInfo[i].score);
  408.     }
  409.  
  410.     ofstream output;
  411.     output.open("baza.txt", ios::out);
  412.  
  413.     output << za_spremanje;
  414.     output.close();
  415. }
  416.  
  417. void showScores()
  418. {
  419.     if (gInfo.size() < 1)
  420.     {
  421.         showLogo();
  422.         cout << "NEMA REZULTATA ZA PRIKAZ !" << endl << endl;
  423.         cout << "KLIKNI ZA POVRATAK..." << endl;
  424.         system("pause>nul");
  425.         return;
  426.     }
  427.    
  428.     int best[4][5];
  429.     int temp;
  430.     int *temp2 = new int[gInfo.size()];
  431.     int *temp4 = new int[gInfo.size()];
  432.     int temp3;
  433.  
  434.     // Resetamo
  435.     for (int i = 0; i < 4; i++)
  436.     {
  437.         for (int j = 0; j < 5; j++)
  438.         {
  439.             best[i][j] = 0;
  440.         }
  441.     }
  442.  
  443.  
  444.     // Prvo preslazemo sve scoreove za svaku igru
  445.     for (int game = 0; game < 3; game++)
  446.     {
  447.         for (int i = 0; i < gInfo.size(); i++)
  448.         {
  449.             if (i == 5)
  450.             {
  451.                 break;
  452.             }
  453.  
  454.             temp = 0;
  455.             temp3 = 0;
  456.  
  457.             for (int j = 0; j < gInfo.size(); j++)
  458.             {
  459.                 if (gInfo[j].score > temp && gInfo[j].game == game + 1 && temp2[j] != 1)
  460.                 {
  461.                     temp = gInfo[j].score;
  462.                     temp3 = j;
  463.                 }
  464.             }
  465.  
  466.             if (temp3 != -1)
  467.             {
  468.                 temp2[temp3] = 1;
  469.                 best[game][i] = temp3;
  470.             }
  471.         }
  472.     }
  473.    
  474.    
  475.     // Trazimo 5 najvecih score-a
  476.     for (int i = 0; i < gInfo.size(); i++)
  477.     {
  478.         if (i == 5)
  479.         {
  480.             break;
  481.         }
  482.  
  483.         temp = 0;
  484.         temp3 = 0;
  485.  
  486.         for (int j = 0; j < gInfo.size(); j++)
  487.         {
  488.             if (gInfo[j].score > temp && temp4[j] != 1)
  489.             {
  490.                 temp = gInfo[j].score;
  491.                 temp3 = j;
  492.             }
  493.         }
  494.  
  495.         if (temp3 != -1)
  496.         {
  497.             temp4[temp3] = 1;
  498.             best[3][i] = temp3;
  499.         }
  500.     }
  501.  
  502.     // Ispis scorea za svaku igru
  503.     showLogo();
  504.  
  505.     for (int i = 0; i < 3; i++)
  506.     {
  507.         switch (i)
  508.         {
  509.         case 0:
  510.             cout << "\t\tJEDNORUKI JACK" << endl;
  511.             break;
  512.         case 1:
  513.             cout << "\t\tBACANJE KOCKICA" << endl;
  514.             break;
  515.         case 2:
  516.             cout << "\t\tDUPLO ILI NISTA" << endl;
  517.             break;
  518.         }
  519.  
  520.         for (int j = 0; j < 3; j++)
  521.         {
  522.             int id = best[i][j];
  523.  
  524.             cout << "\t" << j + 1 << ".\t" << gInfo[id].name << "\t" << gInfo[id].score << endl;
  525.         }
  526.  
  527.         cout << endl;
  528.     }
  529.  
  530.     cout << "\t\tNAJBOLJIH 5 IKADA" << endl;
  531.  
  532.     for (int j = 0; j < 5; j++)
  533.     {
  534.         int id = best[3][j];
  535.  
  536.         cout << "\t" << j + 1 << ".\t" << gInfo[id].name << "\t" << gInfo[id].score << "\t" << gameName(gInfo[id].game) << endl;
  537.     }
  538.  
  539.     cout << endl << "KLIKNI ZA POVRATAK..." << endl;
  540.     system("pause>nul");
  541. }
  542.  
  543. int showGames()
  544. {
  545.     int temp = -1;
  546.  
  547.     cout << "IZBORNIK IGRA: " << endl << endl;
  548.     cout << "\t1\tJednoruki Jack" << endl;
  549.     cout << "\t2\tBacanje kockica" << endl;
  550.     cout << "\t3\tDuplo ili nista" << endl;
  551.     cout << "\t4\tPovratak" << endl << endl;
  552.     cout << "UPISI BROJ ZA IZBOR: " << endl;
  553.  
  554.     cin >> temp;
  555.  
  556.     return temp;
  557. }
  558.  
  559. bool checkChips(int amount)
  560. {
  561.     if (pInfo.chips < amount)
  562.     {
  563.         showLogo();
  564.  
  565.         cout << "Nemas dovoljno chipova !" << endl;
  566.         cout << "STANJE: " << pInfo.chips << endl;
  567.         cout << "Potrebno ti je minimalno " << amount << " chipova za nastavak igre !" << endl << endl;
  568.         cout << "KLIKNI ZA NASTAVAK !" << endl;
  569.         system("pause>nul");
  570.         return false;
  571.     }
  572.     return true;
  573. }
  574.  
  575. void playingDuplo()
  576. {
  577.     int exitDuplo = false;
  578.     int ulog = 0;
  579.     int unos = 1;
  580.     int count = 0;
  581.  
  582.     showLogo();
  583.     cout << "\tDUPLO ILI NISTA" << endl << endl;
  584.  
  585.     cout << "UPUTE:" << endl;
  586.     cout << "\tNakon uloga i kretanja u igru kompjuter izvlaci" << endl;
  587.     cout << "\tkartu za sebe i kartu za igraca. Ukoliko imas" << endl;
  588.     cout << "\tjacu kartu od kompjutera mozes podignuti dobitak." << endl;
  589.     cout << "\tUkoliko dobijes manju kartu mozes odustati ili" << endl;
  590.     cout << "\tpovecati ulog da duplo." << endl << endl;
  591.  
  592.     cout << "KLIKNI ZA NASTAVAK..." << endl;
  593.     system("pause>nul");
  594.  
  595.     while (!exitDuplo)
  596.     {
  597.         bool kInfo[52];
  598.         int card1 = rand() % 52,
  599.             card2 = rand() % 52;
  600.         bool winner;
  601.         string winstr;
  602.         Game nesto;
  603.  
  604.         showLogo();
  605.         cout << "\tDUPLO ILI NISTA" << endl << endl;
  606.  
  607.         cout << "KOMANDE: " << endl;
  608.         cout << "\t1\tPlati" << endl;
  609.         cout << "\t2\tPodigni" << endl;
  610.         cout << "\t3\tIzlaz" << endl << endl;;
  611.  
  612.         cout << "POCETNI ULOG: 5 CHIPS" << endl << endl;
  613.  
  614.         cout << "\tSTANJE\tULOG\tSTANJE\tTVOJE KARTE\tKOMP. KARTE\tPOBJEDNIK" << endl;
  615.  
  616.         while (unos != 0)
  617.         {
  618.             cin >> unos;
  619.  
  620.             switch (unos)
  621.             {
  622.             case 1: // Izvlacenje karata
  623.  
  624.                 count++;
  625.                 if (count > 26)
  626.                 {
  627.                     cout << "SPIL KARATA JE POTROSEN !\nIGRA JE ZAVRSILA !" << endl << endl;
  628.                     cout << "KLIKNI ZA POVRATAK..." << endl;
  629.                     system("pause>nul");
  630.                     return;
  631.                 }
  632.                 if (ulog == 0)
  633.                 {
  634.                     ulog = 5;
  635.                 }
  636.                 else
  637.                 {
  638.                     ulog *= 2;
  639.                 }
  640.  
  641.                 if (!checkChips(ulog))
  642.                 {
  643.                     return;
  644.                 }
  645.  
  646.                 while (kInfo[card1] == true)
  647.                 {
  648.                     card1 = rand() % 52;
  649.                 }
  650.                 kInfo[card1] = true;
  651.                 while (kInfo[card2] == true)
  652.                 {
  653.                     card2 = rand() % 52;
  654.                 }
  655.                 kInfo[card2] = true;
  656.  
  657.                 if (cardValue(card1) > cardValue(card2))
  658.                 {
  659.                     winner = true;
  660.                     winstr = "COVJEK";
  661.                 }
  662.                 else
  663.                 {
  664.                     winner = false;
  665.                     winstr = "KOMPJ.";
  666.                 }
  667.  
  668.                 cout << "\t" << pInfo.chips << "\t" << ulog << "\t" << pInfo.chips - ulog << "\t" << cardName(card1) << "\t\t" << cardName(card2) << "\t\t" << winstr;
  669.  
  670.                 cout << "\t 1 (PLATI " << ulog << " ) ";
  671.  
  672.                 if (winner)
  673.                 {
  674.                     cout << "\t2 (PODIGNI " << 2 * ulog << " ) " << endl;
  675.                 }
  676.  
  677.                 pInfo.chips -= ulog;
  678.  
  679.                 break;
  680.             case 2:
  681.                 if (!winner || count == 0)
  682.                 {
  683.                     cout << "Nemozes podignuti chipove !" << endl;
  684.                     break;
  685.                 }
  686.  
  687.                 pInfo.chips += ulog*2;
  688.                 cout << "Podignuo si " << ulog * 2 << " chipova !" << endl << endl;
  689.  
  690.                 nesto.name = pInfo.name;
  691.                 nesto.game = 3;
  692.                 nesto.score = ulog *2;
  693.                 gInfo.push_back(nesto);
  694.                 saveScores();
  695.  
  696.                 cout << "KLIKNI ZA NASTAVAK...";
  697.                 system("pause>nul");
  698.                 return;
  699.             case 3:
  700.                 exitDuplo = true;
  701.                 cout << "KLIKNI ZA IZLAZ IZ IGRE..." << endl;
  702.                 system("pause>nul");
  703.                 break;
  704.             default:
  705.                 break;
  706.             }
  707.         }
  708.     }
  709. }
  710.  
  711. string cardName(int card)
  712. {
  713.     string temp;
  714.     int znak = card % 13;
  715.  
  716.     if (card <= 12)
  717.     {
  718.         temp += "TREF ";
  719.     }
  720.     else if (card >= 13 && card <= 25)
  721.     {
  722.         temp += "PIK ";
  723.     }
  724.     else if (card >= 26 && card <= 38)
  725.     {
  726.         temp += "SRCE ";
  727.     }
  728.     else if (card >= 39)
  729.     {
  730.         temp += "KARO ";
  731.     }
  732.  
  733.     switch (znak)
  734.     {
  735.     case 0:
  736.         temp += "2";
  737.         break;
  738.     case 1:
  739.         temp += "3";
  740.         break;
  741.     case 2:
  742.         temp += "4";
  743.         break;
  744.     case 3:
  745.         temp += "5";
  746.         break;
  747.     case 4:
  748.         temp += "6";
  749.         break;
  750.     case 5:
  751.         temp += "7";
  752.         break;
  753.     case 6:
  754.         temp += "8";
  755.         break;
  756.     case 7:
  757.         temp += "9";
  758.         break;
  759.     case 8:
  760.         temp += "10";
  761.         break;
  762.     case 9:
  763.         temp += "J";
  764.         break;
  765.     case 10:
  766.         temp += "Q";
  767.         break;
  768.     case 11:
  769.         temp += "K";
  770.         break;
  771.     case 12:
  772.         temp += "A";
  773.         break;
  774.     }
  775.  
  776.     return temp;
  777. }
  778.  
  779. int cardValue(int card)
  780. {
  781.     return card % 13;
  782. }
  783.  
  784. void playingKockice()
  785. {
  786.     int zbroj1,
  787.         zbroj2,
  788.         zbroja,
  789.         zbrojb,
  790.         ulog;
  791.  
  792.     showLogo();
  793.     cout << "\tBACANJE KOCKICA" << endl << endl;
  794.  
  795.     cout << "UPUTE:" << endl;
  796.     cout << "\tPrvo izaberes ulog koji zelis uloziti." << endl;
  797.     cout << "\tNakon toga 2 puta bacas kockice naizmjenicno" << endl;
  798.     cout << "\tprotiv kompjutera. Veci zbroj vrijednosti" << endl;
  799.     cout << "\tpobjeduje. Nerjesena igra nema pobjednika." << endl << endl;
  800.  
  801.     cout << "KLIKNI ZA NASTAVAK..." << endl;
  802.     system("pause>nul");
  803.  
  804.     while (pInfo.chips > 0)
  805.     {
  806.         zbroj1 = 0;
  807.         zbroj2 = 0;
  808.         zbroja = 0;
  809.         zbrojb = 0;
  810.  
  811.         showLogo();
  812.         cout << "\tBACANJE KOCKICA" << endl << endl;
  813.  
  814.         cout << "Upisi iznos koji zelis uloziti (0 = IZLAZ): " << endl;
  815.         cout << "STANJE CHIPOVA: " << pInfo.chips << endl;
  816.         cin >> ulog;
  817.  
  818.         if (ulog == 0)
  819.         {
  820.             cout << "NAPUSTIO SI IGRU !" << endl;
  821.             cout << "KLIKNI ZA IZLAZ..." << endl;
  822.             system("pause>nul");
  823.             return;
  824.         }
  825.  
  826.         while (ulog < 1 || ulog > pInfo.chips)
  827.         {
  828.             cout << "Iznos nemoze biti manji od 1 ili veci od " << pInfo.chips << " ! (0 = IZLAZ)" << endl;
  829.             cin >> ulog;
  830.         }
  831.  
  832.         cout << "KLIKNI ZA BACENJE KOCKICA:" << endl;
  833.         system("pause>nul");
  834.         pInfo.chips -= ulog;
  835.  
  836.         zbroj1 = rand() % 6 + 1;
  837.         zbroj2 = rand() % 6 + 1;
  838.  
  839.         cout << "\tCOVJEK\tKOMPJUTER" << endl;
  840.         cout << "\t" << zbroj1 << "\t" << zbroj2 << endl << endl;
  841.  
  842.         cout << "KLIKNI ZA BACENJE KOCKICA:" << endl;
  843.         system("pause>nul");
  844.  
  845.         cout << "\tCOVJEK\tKOMPJUTER" << endl;
  846.         cout << "\t" << zbroj1 << "\t" << zbroj2 << endl;
  847.         zbroja += rand() % 6 + 1;
  848.         zbrojb += rand() % 6 + 1;
  849.         zbroj1 += zbroja;
  850.         zbroj2 += zbrojb;
  851.         cout << "\t" << zbroja << "\t" << zbrojb << endl << endl;
  852.         cout << "UKUPNO\t" << zbroj1 << "\t" << zbroj2 << endl << endl;
  853.  
  854.         if (zbroj1 > zbroj2)
  855.         {
  856.             cout << "POBJEDNIK: " << pInfo.name << endl;
  857.             cout << "STANJE CHIPOVA: " << pInfo.chips << endl;
  858.             cout << "DOBITAK: " << ulog * 2 << endl;
  859.             cout << "NOVO STANJE: " << pInfo.chips + (ulog * 2) << endl << endl;
  860.  
  861.             pInfo.chips += ulog * 2;
  862.  
  863.             Game nesto;
  864.             nesto.name = pInfo.name;
  865.             nesto.game = 2;
  866.             nesto.score = ulog * 2;
  867.             gInfo.push_back(nesto);
  868.             saveScores();
  869.         }
  870.         else if (zbroj1 < zbroj2)
  871.         {
  872.             cout << "POBJEDNIK: KOMPJUTER" << endl;
  873.             cout << "DOBITAK: " << ulog * 2 << endl;
  874.         }
  875.         else
  876.         {
  877.             cout << "POBJEDNIK: NEMA DOBITNIKA" << endl;
  878.             cout << "STANJE CHIPOVA: " << pInfo.chips << endl;
  879.             cout << "DOBITAK: ULOG ( " << ulog << " )" << endl;
  880.             cout << "NOVO STANJE: " << pInfo.chips + ulog << endl << endl;
  881.         }
  882.  
  883.         cout << "KLIKNI ZA NASTAVAK..." << endl;
  884.         system("pause>nul");
  885.     }
  886. }
  887.  
  888. void playingJednoruki()
  889. {
  890.     showLogo();
  891.     cout << "\tJEDNORUKI JACK" << endl << endl;
  892.  
  893.     cout << "UPUTE:" << endl;
  894.     cout << "\tPrvo izaberes ulog koji zelis uloziti." << endl;
  895.     cout << "\tNakon toga kliknes da pokrenes masinu. " << endl;
  896.     cout << "\tKarte se moraju slagati slijeva nadesno !" << endl;
  897.     cout << "\tUlog 0 = IZLAZ !" << endl << endl;
  898.  
  899.     cout << "KLIKNI ZA NASTAVAK..." << endl;
  900.     system("pause>nul");
  901.  
  902.     while (pInfo.chips > 0)
  903.     {
  904.         int ulog;
  905.         int machine[4];
  906.         int multi = 0;
  907.  
  908.         showLogo();
  909.         cout << "\tJEDNORUKI JACK" << endl << endl;
  910.  
  911.         cout << "Upisi iznos koji zelis uloziti (0 = IZLAZ): " << endl;
  912.         cout << "STANJE CHIPOVA: " << pInfo.chips << endl;
  913.         cin >> ulog;
  914.  
  915.         if (ulog == 0)
  916.         {
  917.             cout << "NAPUSTIO SI IGRU !" << endl;
  918.             cout << "KLIKNI ZA IZLAZ..." << endl;
  919.             system("pause>nul");
  920.             return;
  921.         }
  922.  
  923.         while (ulog < 1 || ulog > pInfo.chips)
  924.         {
  925.             cout << "Iznos nemoze biti manji od 1 ili veci od " << pInfo.chips << " ! (0 = IZLAZ)" << endl;
  926.             cin >> ulog;
  927.         }
  928.         pInfo.chips -= ulog;
  929.  
  930.         cout << "KLIKNI ZA POKRETANJE MASINE:" << endl;
  931.         system("pause>nul");
  932.  
  933.         showLogo();
  934.         cout << "\tJEDNORUKI JACK" << endl << endl;
  935.  
  936.         machine[0] = rand() % 4;
  937.         machine[1] = rand() % 4;
  938.         machine[2] = rand() % 4;
  939.         machine[3] = rand() % 4;
  940.  
  941.         printMachine(machine[0], machine[1], machine[2], machine[3]);
  942.         printPoints(ulog);
  943.  
  944.         if (machine[0] == machine[1] && machine[1] == machine[2] && machine[2] == machine[3])
  945.         {
  946.             multi = 32;
  947.         }
  948.         else if (machine[0] == machine[1] && machine[1] == machine[2])
  949.         {
  950.             multi = 8;
  951.         }
  952.         else if (machine[0] == machine[1])
  953.         {
  954.             multi = 4;
  955.         }
  956.  
  957.         if (multi == 0)
  958.         {
  959.             cout << "DOBITAK: NEMA DOBITKA !" << endl << endl;
  960.             cout << "KLIKNI ZA NOVU IGRU..." << endl;
  961.             system("pause>cin");
  962.         }
  963.         else
  964.         {
  965.             cout << "DOBITAK: x" << multi << endl;
  966.             cout << "STANJE CHIPOVA: " << pInfo.chips << endl;
  967.             cout << "DOBITAK: " << ulog * multi << endl;
  968.             cout << "NOVO STANJE: " << pInfo.chips + (ulog * multi) << endl << endl;
  969.  
  970.             pInfo.chips += ulog * multi;
  971.  
  972.             Game nesto;
  973.             nesto.name = pInfo.name;
  974.             nesto.game = 1;
  975.             nesto.score = ulog * multi;
  976.             gInfo.push_back(nesto);
  977.             saveScores();
  978.  
  979.             cout << "KLIKNI ZA NOVU IGRU..." << endl;
  980.             system("pause>nul");
  981.         }
  982.     }
  983. }
  984.  
  985. void printMachine(int a, int b, int c, int d)
  986. {
  987.     char nes[4];
  988.  
  989.     if (a == 0)
  990.     {
  991.         nes[0] = 'X';
  992.     }
  993.     else if (a == 1)
  994.     {
  995.         nes[0] = 'Y';
  996.     }
  997.     else if (a == 2)
  998.     {
  999.         nes[0] = 'Z';
  1000.     }
  1001.     else if (a == 3)
  1002.     {
  1003.         nes[0] = 'A';
  1004.     }
  1005.  
  1006.     if (b == 0)
  1007.     {
  1008.         nes[1] = 'X';
  1009.     }
  1010.     else if (b == 1)
  1011.     {
  1012.         nes[1] = 'Y';
  1013.     }
  1014.     else if (b == 2)
  1015.     {
  1016.         nes[1] = 'Z';
  1017.     }
  1018.     else if (b == 3)
  1019.     {
  1020.         nes[1] = 'A';
  1021.     }
  1022.  
  1023.     if (c == 0)
  1024.     {
  1025.         nes[2] = 'X';
  1026.     }
  1027.     else if (c == 1)
  1028.     {
  1029.         nes[2] = 'Y';
  1030.     }
  1031.     else if (c == 2)
  1032.     {
  1033.         nes[2] = 'Z';
  1034.     }
  1035.     else if (c == 3)
  1036.     {
  1037.         nes[2] = 'A';
  1038.     }
  1039.  
  1040.     if (d == 0)
  1041.     {
  1042.         nes[3] = 'X';
  1043.     }
  1044.     else if (d == 1)
  1045.     {
  1046.         nes[3] = 'Y';
  1047.     }
  1048.     else if (d == 2)
  1049.     {
  1050.         nes[3] = 'Z';
  1051.     }
  1052.     else if (d == 3)
  1053.     {
  1054.         nes[3] = 'A';
  1055.     }
  1056.  
  1057.     for (int i = 0; i < 3; i++)
  1058.     {
  1059.         cout << "\t" << nes[0] << nes[0] << nes[0]
  1060.             << "\t" << nes[1] << nes[1] << nes[1]
  1061.             << "\t" << nes[2] << nes[2] << nes[2]
  1062.             << "\t" << nes[3] << nes[3] << nes[3] << endl;
  1063.     }
  1064. }
  1065.  
  1066. void printPoints(int ulog)
  1067. {
  1068.     cout << endl;
  1069.     cout << "\t2 ISTE\t4 x  ULOG (" << ulog << ") = " << ulog * 4 <<endl;
  1070.     cout << "\t3 ISTE\t8 x  ULOG (" << ulog << ") = " << ulog * 8 << endl;
  1071.     cout << "\t4 ISTE\t32 x ULOG (" << ulog << ") = " << ulog * 32 << endl;
  1072.     cout << endl;
  1073. }
  1074.  
  1075. string gameName(int game)
  1076. {
  1077.     string temp;
  1078.  
  1079.     switch (game)
  1080.     {
  1081.     case 1:
  1082.         temp = "JEDNORUKI JACK";
  1083.         break;
  1084.     case 2:
  1085.         temp = "BACANJE KOCKICA";
  1086.         break;
  1087.     case 3:
  1088.         temp = "DUPLO ILI NISTA";
  1089.         break;
  1090.     }
  1091.     return temp;
  1092. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement