Advertisement
Papuger95

Labirynt w C++ #2

Mar 17th, 2018
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <tchar.h>
  3. #include <conio.h>
  4. #include <iostream>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int plansza[23][77] =
  11. { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  12.   { 1, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
  13.   { 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1},
  14.   { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1},
  32.   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
  33.   { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} };
  34.  
  35. int wyb = 1;
  36. int wybN;
  37. int wybMenu = 1;            // ktora pozycja w menu
  38. int gracz_x = 1;
  39. int gracz_y = 1;
  40. int gracz_nx;
  41. int gracz_ny;
  42. int introCzas = 400;        //odstepy intro /ms
  43. bool wMenu = true;          //warunek P menu
  44. bool wGrze = false;         //warunek P gra
  45. bool koniec = false;        //warunek P calosc
  46. bool wlasciwa_decyzja = false;
  47. int postac = 254;
  48. int kolorTekst = 6;
  49. int kolorPostac = 12;
  50. int kolorCel = 14;
  51. int kolorSciana = 2;
  52.  
  53. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);   // kolorki
  54.  
  55. void intro()
  56. {
  57.     SetConsoleTextAttribute(hConsole, 10);
  58.     cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
  59.     Sleep(introCzas);
  60.     cout << "                " << (char)(219) << (char)(219) << "     " << " " << " " << (char)(219) << " " << "  " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << "  " << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << endl;
  61.     Sleep(introCzas);
  62.     cout << "                " << (char)(219) << (char)(219) << "     " << " " << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << "    " << (char)(219) << (char)(219) << " " << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << " " << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  63.     Sleep(introCzas);
  64.     cout << "                " << (char)(219) << (char)(219) << "     " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << "   " << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  65.     Sleep(introCzas);
  66.     cout << "                " << (char)(219) << (char)(219) << "     " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << "   " << (char)(219) << "   " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  67.     Sleep(introCzas);
  68.     cout << "                " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << "   " << (char)(219) << "   " << (char)(219) << (char)(219) << "  " << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  69. }
  70. void logoD()
  71. {
  72.     cout << endl << endl;
  73.     cout << "                " <<(char)(219) << (char)(219) << "     " << " " << " " << (char)(219) << " " << "  " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << "  " << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << endl;
  74.     cout << "                " <<(char)(219) << (char)(219) << "     " << " " << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << "    " << (char)(219) << (char)(219) << " " << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << " " << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  75.     cout << "                " <<(char)(219) << (char)(219) << "     " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << "   " << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  76.     cout << "                " <<(char)(219) << (char)(219) << "     " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << "   " << (char)(219) << "   " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  77.     cout << "                " <<(char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << " " << (char)(219) << (char)(219) << (char)(219) << (char)(219) << "  " << (char)(219) << (char)(219)<< " " << (char)(219) << (char)(219) << " " << (char)(219) << "   " << (char)(219) << "   " << (char)(219) << (char)(219) << "  " << (char)(219) << "   " << (char)(219) << (char)(219) << endl;
  78. }
  79.  
  80. void zakonczenie()
  81. {
  82.     system("cls");
  83.     cout << endl << endl << endl << endl;
  84.     cout << "                               Do zobaczenia!" << endl << endl;
  85.     logoD();
  86.     cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << "                                 By Kamil M.";
  87.     Sleep(2500);
  88. }
  89.  
  90. void rysujPlansza()
  91. {
  92.     system("cls");
  93.     cout << "                          Powodzenia, znajdz : "; SetConsoleTextAttribute(hConsole, kolorCel); cout << (char)(207) << endl;
  94.     for (int i = 0; i < 23; ++i)
  95.     {
  96.         cout << " ";
  97.         for (int j = 0; j < 78; ++j)
  98.             switch (plansza[i][j])
  99.             {
  100.             case 0: cout << " "; break;
  101.             case 1: SetConsoleTextAttribute(hConsole, kolorSciana); cout << (char)(219); break;         //█
  102.             case 2: SetConsoleTextAttribute(hConsole, kolorPostac); cout << (char)(postac); break;      //■       248 °
  103.             case 3: SetConsoleTextAttribute(hConsole, kolorCel); cout << (char)(207); break;            //¤
  104.  
  105.             }
  106.        
  107.         cout << endl;
  108.     }
  109. }
  110.  
  111. void menu1()
  112. {
  113.     SetConsoleTextAttribute(hConsole, kolorTekst);
  114.     system("cls");
  115.     logoD();
  116.     cout << endl << endl << endl << endl;
  117.     cout << "                             Witaj w Labiryncie      " << endl << endl;
  118.     cout << "                                   Menu:" << endl << endl;
  119.     cout << "                           " << (char)(175) << "   Rozpocznij gre" << endl;
  120.     cout << "                               Wybierz postac" << endl;
  121.     cout << "                                    Info" << endl << endl;
  122.     cout << "                                  Wyjscie" << endl;
  123. }
  124.  
  125. void menu2()
  126. {
  127.     SetConsoleTextAttribute(hConsole, kolorTekst);
  128.     system("cls");
  129.     logoD();
  130.     cout << endl << endl << endl << endl;
  131.     cout << "                             Witaj w Labiryncie      " << endl << endl;
  132.     cout << "                                   Menu:" << endl << endl;
  133.     cout << "                               Rozpocznij gre" << endl;
  134.     cout << "                           " << (char)(175) << "   Wybierz postac" << endl;
  135.     cout << "                                    Info" << endl << endl;
  136.     cout << "                                  Wyjscie" << endl;
  137. }
  138.  
  139. void menu3()
  140. {
  141.     SetConsoleTextAttribute(hConsole, kolorTekst);
  142.     system("cls");
  143.     logoD();
  144.     cout << endl << endl << endl << endl;
  145.     cout << "                             Witaj w Labiryncie      " << endl << endl;
  146.     cout << "                                   Menu:" << endl << endl;
  147.     cout << "                               Rozpocznij gre" << endl;
  148.     cout << "                               Wybierz postac" << endl;
  149.     cout << "                           " << (char)(175) << "        Info" << endl << endl;
  150.     cout << "                                  Wyjscie" << endl;
  151. }
  152.  
  153. void menu4()
  154. {
  155.     SetConsoleTextAttribute(hConsole, kolorTekst);
  156.     system("cls");
  157.     logoD();
  158.     cout << endl << endl << endl << endl;
  159.     cout << "                             Witaj w Labiryncie      " << endl << endl;
  160.     cout << "                                   Menu:" << endl << endl;
  161.     cout << "                               Rozpocznij gre" << endl;
  162.     cout << "                               Wybierz postac" << endl;
  163.     cout << "                                    Info" << endl << endl;
  164.     cout << "                           " << (char)(175) << "      Wyjscie" << endl;
  165. }
  166.  
  167. void czyWyjsc()
  168. {
  169.     SetConsoleTextAttribute(hConsole, kolorTekst);
  170.     system("cls");
  171.     cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
  172.     cout << "                              Czy chcesz wyjsc?" << endl << endl;
  173.     cout << "                           1 - tak        0 - nie" << endl;
  174.     int decyzja;
  175.     cout << "                                     ";
  176.     cin >> decyzja;
  177.     while (wlasciwa_decyzja == false)
  178.     {
  179.         switch (decyzja)
  180.         {
  181.         case 1:
  182.         {
  183.             system("cls");
  184.             wMenu = false;
  185.             wGrze = false;
  186.             koniec = true;
  187.             //Sleep(1500);
  188.             wlasciwa_decyzja = true;
  189.         }
  190.         break;
  191.         case 0:
  192.         {
  193.             wlasciwa_decyzja = true;
  194.             //if (wGrze == false)
  195.             //  menu1();
  196.         }
  197.         break;
  198.         default:
  199.         {
  200.             system("cls");
  201.             cout << "                    To nie jest wlasciwa dana!" << endl;
  202.             cout << "                      Czy chcesz wyjsc?" << endl << endl;
  203.             cout << "                      1 - tak        0 - nie" << endl;
  204.             cin >> decyzja;
  205.         }
  206.         break;
  207.         }
  208.     }
  209. }
  210.  
  211. void wygrana()
  212. {
  213.     SetConsoleTextAttribute(hConsole, kolorTekst);
  214.     cout << endl << endl << endl << endl << endl;
  215.     cout << "                                 GRATULACJE" << endl << endl;
  216.     cout << "                           Czy chcesz jeszcze raz?" << endl << endl;
  217.     cout << "                           1 - tak        0 - nie" << endl;
  218.     int decyzja;
  219.     cin >> decyzja;
  220.     bool wlasciwa_decyzja = false;
  221.     while (wlasciwa_decyzja == false)
  222.     {
  223.         switch (decyzja)
  224.         {
  225.         case 0:
  226.         {
  227.             plansza[gracz_x][gracz_y] = 0;
  228.             plansza[1][1] = 2;
  229.             gracz_x = 1;
  230.             gracz_nx = 1;
  231.             gracz_y = 1;
  232.             gracz_ny = 1;
  233.             wGrze = false;
  234.  
  235.             wlasciwa_decyzja = true;
  236.         }
  237.         break;
  238.         case 1:
  239.         {
  240.             plansza[gracz_x][gracz_y] = 0;
  241.             plansza[1][1] = 2;
  242.             gracz_x = 1;
  243.             gracz_nx = 1;
  244.             gracz_y = 1;
  245.             gracz_ny = 1;
  246.             wlasciwa_decyzja = true;
  247.         }
  248.         break;
  249.         default:
  250.         {
  251.             system("cls");
  252.             cout << "                    To nie jest wlasciwa dana!" << endl;
  253.             cout << "                      Czy chcesz jeszcze raz?" << endl << endl;
  254.             cout << "                      1 - tak        0 - nie" << endl;
  255.             cin >> decyzja;
  256.         }
  257.         break;
  258.         }
  259.     }
  260. }
  261.  
  262. int rusz(int pozycja_x, int pozycja_y) //int
  263. {
  264.  
  265.     unsigned char znak = _getch();
  266.     switch (znak)
  267.     {
  268.     case 0: //klawisze specjalne (czasem zero czasem 224 - zależne od pc'ta chyba)
  269.     case 224: //klawisze specjalne
  270.         znak = _getch();
  271.         switch (znak)
  272.         {
  273.         case 72:
  274.             //strzałka w górę
  275.             if (plansza[pozycja_x - 1][pozycja_y] == 3)
  276.             {
  277.                 wygrana();
  278.             }
  279.             else
  280.             {
  281.                 if (plansza[pozycja_x - 1][pozycja_y] == 0)
  282.                 {
  283.                     plansza[pozycja_x][pozycja_y] = 0;
  284.                     plansza[pozycja_x - 1][pozycja_y] = 2;
  285.                     gracz_nx = pozycja_x - 1;
  286.                     gracz_ny = pozycja_y;
  287.                 }
  288.             }
  289.             break;
  290.         case 80: //strzałka w dół
  291.             if (plansza[pozycja_x + 1][pozycja_y] == 3)
  292.             {
  293.                 wygrana();
  294.             }
  295.             else
  296.             {
  297.                 if (plansza[pozycja_x + 1][pozycja_y] == 0)
  298.                 {
  299.                     plansza[pozycja_x][pozycja_y] = 0;
  300.                     plansza[pozycja_x + 1][pozycja_y] = 2;
  301.                     gracz_nx = pozycja_x + 1;
  302.                     gracz_ny = pozycja_y;
  303.                 }
  304.             }
  305.             break;
  306.         case 75: //strzałka w lewo
  307.             if (plansza[pozycja_x][pozycja_y - 1] == 3)
  308.             {
  309.                 wygrana();
  310.             }
  311.             else
  312.             {
  313.                 if (plansza[pozycja_x][pozycja_y - 1] == 0)
  314.                 {
  315.                     plansza[pozycja_x][pozycja_y] = 0;
  316.                     plansza[pozycja_x][pozycja_y - 1] = 2;
  317.                     gracz_nx = pozycja_x;
  318.                     gracz_ny = pozycja_y - 1;
  319.                 }
  320.             }
  321.             break;
  322.         case 77: //strzałka w prawo
  323.             if (plansza[pozycja_x][pozycja_y + 1] == 3)
  324.             {
  325.                 wygrana();
  326.             }
  327.             else
  328.             {
  329.                 if (plansza[pozycja_x][pozycja_y + 1] == 0)
  330.                 {
  331.                     plansza[pozycja_x][pozycja_y] = 0;
  332.                     plansza[pozycja_x][pozycja_y + 1] = 2;
  333.                     gracz_nx = pozycja_x;
  334.                     gracz_ny = pozycja_y + 1;
  335.                 }
  336.             }
  337.             break;
  338.         }
  339.         znak = 0;
  340.         break;
  341.         //case 13: //ENTER
  342.         //  break;
  343.     case 27: //ESC
  344.     {
  345.         czyWyjsc();
  346.     }
  347.     break;
  348.     }
  349.     return 0;
  350.  
  351. }
  352.  
  353.  
  354. void info()
  355. {
  356.     system("cls");
  357.     logoD();
  358.     cout << endl << endl << endl;
  359.     cout << "                             Witaj w Labiryncie      " << endl << endl;
  360.     cout << "                     Gra zostala napisana w jezyku C++" << endl;
  361.     cout << "               Jestem poczatkujacym programista i samoukiem" << endl;
  362.     cout << "                          Mozliwe sa wiec bledy" << endl;
  363.     cout << "                  Plan jest, ze bede to dalej rozwijal" << endl;
  364.     cout << "                               Milej gry" << endl << endl << endl << endl;
  365.     cout << "                Dowolny przycisk aby powrocic do menu :) " << endl;
  366.     _getch();
  367.     menu3();
  368. }
  369.  
  370. void wyborPostaci()
  371. {
  372.     int wybierzPostac;
  373.     system("cls");
  374.     logoD();
  375.     cout << endl << endl << endl;
  376.     cout << "                            Witaj w Labiryncie      " << endl << endl << endl;
  377.     cout << "                              Wybierz postac:" << endl << endl;
  378.     cout << "                                  1 -> "; SetConsoleTextAttribute(hConsole, kolorPostac); cout << (char)(248) << endl; SetConsoleTextAttribute(hConsole, kolorTekst);          //°
  379.     cout << "                                  2 -> "; SetConsoleTextAttribute(hConsole, kolorPostac); cout << (char)(254) << endl; SetConsoleTextAttribute(hConsole, kolorTekst);          //■
  380.     cout << "                                  3 -> "; SetConsoleTextAttribute(hConsole, kolorPostac); cout << (char)(1)   << endl; SetConsoleTextAttribute(hConsole, kolorTekst);          //☺
  381.     cout << "                                  4 -> "; SetConsoleTextAttribute(hConsole, kolorPostac); cout << (char)(2)   << endl; SetConsoleTextAttribute(hConsole, kolorTekst);          //☻
  382.     cout << "                                  5 -> "; SetConsoleTextAttribute(hConsole, kolorPostac); cout << (char)(4)   << endl << endl; SetConsoleTextAttribute(hConsole, kolorTekst);      //♦
  383.     cout << "                             Co wybierasz?    : ";; SetConsoleTextAttribute(hConsole, kolorPostac); cin >> wybierzPostac; SetConsoleTextAttribute(hConsole, kolorTekst);
  384.    
  385.     switch (wybierzPostac)
  386.     {
  387.     case 1:
  388.         postac = 248;
  389.         break;
  390.     case 2:
  391.         postac = 254;
  392.         break;
  393.     case 3:
  394.         postac = 1;
  395.         break;
  396.     case 4:
  397.         postac = 2;
  398.         break;
  399.     case 5:
  400.         postac = 4;
  401.         break;
  402.     }
  403.     cout << "            Wybrales : "; SetConsoleTextAttribute(hConsole, kolorPostac); cout << (char)(postac); SetConsoleTextAttribute(hConsole, kolorTekst); cout << "   Dwolny przycik by kontynuowac";
  404.     _getch();
  405.     menu2();
  406. }
  407.  
  408. void menuNowe()
  409. {
  410.     unsigned char wyb1 = _getch();  //wyb1 - sterowanie gora/dol menu
  411.     switch (wyb1)
  412.     {
  413.     case 0:
  414.     case 224:
  415.         wyb1 = _getch();
  416.         switch (wyb1)
  417.         {
  418.         case 72:                    //strzalka w gore
  419.             if (wybMenu > 1) wybMenu--;
  420.             //else wybMenu = 4;
  421.  
  422.             switch (wybMenu)
  423.             {
  424.             case 1:
  425.                 menu1();
  426.                 //cout << wybMenu;
  427.                 break;
  428.             case 2:
  429.                 menu2();
  430.                 //cout << wybMenu;
  431.                 break;
  432.             case 3:
  433.                 menu3();
  434.                 //cout << wybMenu;
  435.                 break;
  436.             case 4:
  437.                 menu4();
  438.                 //cout << wybMenu;
  439.                 break;
  440.             }
  441.             break;
  442.         case 80:                    //strzałka w dół
  443.             if (wybMenu < 4) wybMenu++;
  444.             //else wybMenu = 1;
  445.  
  446.             switch (wybMenu)
  447.             {
  448.             case 1:
  449.                 menu1();
  450.                 //cout << wybMenu;
  451.                 break;
  452.             case 2:
  453.                 menu2();
  454.                 //cout << wybMenu;
  455.                 break;
  456.             case 3:
  457.                 menu3();
  458.                 //cout << wybMenu;
  459.                 break;
  460.             case 4:
  461.                 menu4();
  462.                 //cout << wybMenu;
  463.                 break;
  464.             }
  465.             break;
  466.         //case 75: //strzałka w lewo
  467.         //  break;
  468.         //case 77: //strzałka w prawo
  469.         //  break;
  470.         }
  471.         wyb1 = 0;
  472.         break;
  473.     case 13: //ENTER
  474.         switch (wybMenu)
  475.         {
  476.         case 1:
  477.             //cout << wybMenu;
  478.             //cout << "graj";
  479.             //Sleep(2000);
  480.             wMenu = false;
  481.             wGrze = true;
  482.             break;
  483.         case 2:
  484.             wyborPostaci();
  485.             break;
  486.         case 3:
  487.             info();
  488.             break;
  489.         case 4:
  490.             czyWyjsc();
  491.             break;
  492.         }
  493.         break;
  494.     case 27: //ESC
  495.         czyWyjsc();
  496.         break;
  497.     }
  498.     //return 0;
  499. }
  500.  
  501.  
  502. int main()
  503. {
  504.     intro();
  505.     SetConsoleTextAttribute(hConsole, kolorTekst);
  506.     Sleep(2000);
  507.     while (koniec == false)
  508.     {
  509.         wMenu = true;
  510.         menu1();
  511.         while (wMenu == true)
  512.         {
  513.             menuNowe();
  514.         }
  515.         while (wGrze == true)
  516.         {
  517.             rysujPlansza();
  518.             rusz(gracz_x, gracz_y);
  519.             gracz_x = gracz_nx;
  520.             gracz_y = gracz_ny;
  521.         }
  522.     }
  523.     zakonczenie();
  524.     return 0;
  525. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement