-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeleportEvent.cpp
37 lines (30 loc) · 969 Bytes
/
TeleportEvent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "TeleportEvent.h"
#include "vector"
#include "Cell.h"
#include <random>
TeleportEvent::TeleportEvent(Field* field) {
this->field = field;
}
void TeleportEvent::execute(InfoLog* text) {
std::vector<std::vector<Cell>>* cells = field->GetField();
int x = field->GetX();
int y = field->GetY();
(*cells)[x][y].SetActive(false);
distrubution:
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dist_x(0, field->GetHeight() - 1); //ðàâíîìåðíîå ðàñïðåäåëåíèå ñ âêëþ÷åíèåì ãðàíèö
std::uniform_int_distribution<> dist_y(0, field->GetWidth() - 1);
int i = dist_x(gen);
int j = dist_y(gen);
if ((*cells)[i][j].GetObject() == Cell::WALL)
goto distrubution;
field->SetX(i);
field->SetY(j);
(*cells)[i][j].SetActive(true);
if ((*cells)[i][j].GetObject() != Cell::WIN)
(*cells)[i][j].SetObject(Cell::COMMON);
(*cells)[i][j].UseEvent(text);
Message message(GAME, "player has been teleported", text);
Notify(message);
}