Advertisement
MeehoweCK

Untitled

May 9th, 2023
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. enum class Pole
  8. {
  9.     puste, poszukiwacz, mur, wrog, skarb
  10. };
  11.  
  12. const short N = 30;
  13. const short W = 10;
  14.  
  15. Pole plansza[N][N];
  16.  
  17. struct Wspolrzedne
  18. {
  19.     short x;
  20.     short y;
  21. };
  22.  
  23. Wspolrzedne poszukiwacz, skarb;
  24. Wspolrzedne wrogowie[W];
  25.  
  26. void wypelnij_plansze()
  27. {
  28.     for(short i = 0; i < N; ++i)
  29.         for(short j = 0; j < N; ++j)
  30.         {
  31.             if(i == 0 || j == 0 || i == N - 1 || j == N - 1)
  32.                 plansza[i][j] = Pole::mur;
  33.             else
  34.                 plansza[i][j] = Pole::puste;
  35.         }
  36.  
  37.     poszukiwacz.x = 1 + rand() % 28;
  38.     poszukiwacz.y = 1 + rand() % 28;
  39.     plansza[poszukiwacz.x][poszukiwacz.y] = Pole::poszukiwacz;
  40.  
  41.     do
  42.     {
  43.         skarb.x = 1 + rand() % 28;
  44.         skarb.y = 1 + rand() % 28;
  45.     }
  46.     while(plansza[skarb.x][skarb.y] != Pole::puste);
  47.     plansza[skarb.x][skarb.y] = Pole::skarb;
  48.  
  49.     for(short i = 0; i < W; ++i)
  50.     {
  51.         do
  52.         {
  53.             wrogowie[i].x = 1 + rand() % 28;
  54.             wrogowie[i].y = 1 + rand() % 28;
  55.         }
  56.         while(plansza[wrogowie[i].x][wrogowie[i].y] != Pole::puste);
  57.         plansza[wrogowie[i].x][wrogowie[i].y] = Pole::wrog;
  58.     }
  59. }
  60.  
  61. void wypisz_plansze()
  62. {
  63.     for(short i = 0; i < N; ++i)
  64.     {
  65.         for(short j = 0; j < N; ++j)
  66.             switch(plansza[i][j])
  67.             {
  68.             case Pole::puste:
  69.                 cout << ' ';
  70.                 break;
  71.             case Pole::mur:
  72.                 cout << '#';
  73.                 break;
  74.             case Pole::poszukiwacz:
  75.                 cout << '@';
  76.                 break;
  77.             case Pole::skarb:
  78.                 cout << '$';
  79.                 break;
  80.             case Pole::wrog:
  81.                 cout << '!';
  82.             }
  83.         cout << endl;
  84.     }
  85. }
  86.  
  87. int main()
  88. {
  89.     srand(time(nullptr));
  90.     wypelnij_plansze();
  91.     wypisz_plansze();
  92.  
  93.     return 0;
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement