Advertisement
MeehoweCK

Untitled

Dec 3rd, 2020
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. const int N = 33;
  9.  
  10. struct koordynaty
  11. {
  12.     int x;
  13.     int y;
  14. };
  15.  
  16. enum class pole
  17. {
  18.     puste, mur, poszukiwacz, przeciwnik, skarb
  19. };
  20.  
  21. pole tablica[N][N];
  22. vector<koordynaty> przeciwnicy;
  23. koordynaty bohater;
  24. koordynaty cel;
  25.  
  26. void uzupelnienie(int ilosc_przeciwnikow)
  27. {
  28.     srand(time(NULL));
  29.  
  30.     vector<koordynaty> puste_pola;
  31.     koordynaty nowy;
  32.  
  33.     for(int i = 0; i < N ; i++)
  34.     {
  35.         for(int j = 0; j < N; j++)
  36.         {
  37.             if(i == 0 || i == N - 1 || j == 0 || j == N - 1)
  38.             {
  39.                 tablica[i][j] = pole::mur;
  40.                 continue;
  41.             }
  42.             if(i % 2 == 0 && j % 2 == 0)
  43.                 tablica[i][j] = pole::mur;
  44.             else
  45.             {
  46.                 tablica[i][j] = pole::puste;
  47.                 nowy.x = j;
  48.                 nowy.y = i;
  49.                 puste_pola.push_back(nowy);
  50.             }
  51.         }
  52.     }
  53.  
  54.     int liczba_pustych = puste_pola.size();
  55.     int numer = rand() % liczba_pustych;
  56.     nowy = puste_pola[numer];
  57.     cel = nowy;
  58.     tablica[nowy.y][nowy.x] = pole::skarb;
  59.     puste_pola.erase(puste_pola.begin() + numer);
  60.  
  61.     liczba_pustych = puste_pola.size();
  62.     numer = rand() % liczba_pustych;
  63.     nowy = puste_pola[numer];
  64.     bohater = nowy;
  65.     tablica[nowy.y][nowy.x] = pole::poszukiwacz;
  66.     puste_pola.erase(puste_pola.begin() + numer);
  67.  
  68.     while(ilosc_przeciwnikow >= 0)
  69.     {
  70.         liczba_pustych = puste_pola.size();
  71.         numer = rand() % liczba_pustych;
  72.         nowy = puste_pola[numer];
  73.         przeciwnicy.push_back(nowy);
  74.         tablica[nowy.y][nowy.x] = pole::przeciwnik;
  75.         puste_pola.erase(puste_pola.begin() + numer);
  76.  
  77.         ilosc_przeciwnikow--;
  78.     }
  79.  
  80. }
  81.  
  82. vector<koordynaty> dostepne_pola_przeciwnika(koordynaty przeciwnik)
  83. {
  84.    
  85. }
  86.  
  87. void poruszanie_poszukiwaczem()
  88. {
  89.  
  90. }
  91.  
  92. void wypisz_plansze()
  93. {
  94.     for(int i = 0; i < N; ++i)
  95.     {
  96.         for(int j = 0; j < N; ++j)
  97.             switch(tablica[i][j])
  98.             {
  99.             case pole::mur:
  100.                 cout << '#';
  101.                 break;
  102.             case pole::skarb:
  103.                 cout << 'X';
  104.                 break;
  105.             case pole::puste:
  106.                 cout << ' ';
  107.                 break;
  108.             case pole::poszukiwacz:
  109.                 cout << 'O';
  110.                 break;
  111.             case pole::przeciwnik:
  112.                 cout << '@';
  113.             }
  114.         cout << endl;
  115.     }
  116. }
  117.  
  118. int main()
  119. {
  120.     int ilosc_przeciwnikow;
  121.  
  122.     cout << "Podaj ilosc przeciwnikow: " << endl;
  123.     cin >> ilosc_przeciwnikow;
  124.  
  125.     uzupelnienie(ilosc_przeciwnikow);
  126.     wypisz_plansze();
  127.  
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement