Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- enum class Pole
- {
- puste, poszukiwacz, mur, wrog, skarb
- };
- const short N = 30;
- const short W = 10;
- Pole plansza[N][N];
- struct Wspolrzedne
- {
- short x;
- short y;
- };
- Wspolrzedne poszukiwacz, skarb;
- Wspolrzedne wrogowie[W];
- void wypelnij_plansze()
- {
- for(short i = 0; i < N; ++i)
- for(short j = 0; j < N; ++j)
- {
- if(i == 0 || j == 0 || i == N - 1 || j == N - 1)
- plansza[i][j] = Pole::mur;
- else
- plansza[i][j] = Pole::puste;
- }
- poszukiwacz.x = 1 + rand() % 28;
- poszukiwacz.y = 1 + rand() % 28;
- plansza[poszukiwacz.x][poszukiwacz.y] = Pole::poszukiwacz;
- do
- {
- skarb.x = 1 + rand() % 28;
- skarb.y = 1 + rand() % 28;
- }
- while(plansza[skarb.x][skarb.y] != Pole::puste);
- plansza[skarb.x][skarb.y] = Pole::skarb;
- for(short i = 0; i < W; ++i)
- {
- do
- {
- wrogowie[i].x = 1 + rand() % 28;
- wrogowie[i].y = 1 + rand() % 28;
- }
- while(plansza[wrogowie[i].x][wrogowie[i].y] != Pole::puste);
- plansza[wrogowie[i].x][wrogowie[i].y] = Pole::wrog;
- }
- }
- void wypisz_plansze()
- {
- for(short i = 0; i < N; ++i)
- {
- for(short j = 0; j < N; ++j)
- switch(plansza[i][j])
- {
- case Pole::puste:
- cout << ' ';
- break;
- case Pole::mur:
- cout << '#';
- break;
- case Pole::poszukiwacz:
- cout << '@';
- break;
- case Pole::skarb:
- cout << '$';
- break;
- case Pole::wrog:
- cout << '!';
- }
- cout << endl;
- }
- }
- int main()
- {
- srand(time(nullptr));
- wypelnij_plansze();
- wypisz_plansze();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement