Advertisement
MeehoweCK

Untitled

Dec 2nd, 2020
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. struct koordynaty
  9. {
  10.     int x;
  11.     int y;
  12. };
  13.  
  14. enum class pole
  15. {
  16.     puste, mur, poszukiwacz, przeciwnik, skarb
  17. };
  18.  
  19. pole tablica[30][30];
  20.  
  21. void uzupelnienie()
  22. {
  23.     srand(time(NULL));
  24.  
  25.     vector<koordynaty> puste_pola;
  26.     koordynaty nowy;
  27.  
  28.     for(int i = 0; i < 30; i++)
  29.     {
  30.         for(int j = 0; j < 30; j++)
  31.         {
  32.             if(i % 2 == 0 && j % 2 == 0)
  33.                 tablica[i][j] = pole::mur;
  34.             else
  35.             {
  36.                 tablica[i][j] = pole::puste;
  37.                 nowy.x = j;
  38.                 nowy.y = i;
  39.                 puste_pola.push_back(nowy);
  40.             }
  41.         }
  42.     }
  43.  
  44.     int liczba_pustych = puste_pola.size();
  45.     int numer = rand() % liczba_pustych;
  46.     nowy = puste_pola[numer];
  47.     tablica[nowy.y][nowy.x] = pole::skarb;
  48. }
  49.  
  50. void wypisz_plansze()
  51. {
  52.     for(int i = 0; i < 30; ++i)
  53.     {
  54.         for(int j = 0; j < 30; ++j)
  55.             switch(tablica[i][j])
  56.         {
  57.         case pole::mur:
  58.             cout << '#';
  59.             break;
  60.         case pole::skarb:
  61.             cout << 'X';
  62.             break;
  63.         case pole::puste:
  64.             cout << ' ';
  65.             break;
  66.         }
  67.         cout << endl;
  68.     }
  69. }
  70.  
  71. int main()
  72. {
  73.     uzupelnienie();
  74.     wypisz_plansze();
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement