-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsapper.cpp
70 lines (60 loc) · 1.55 KB
/
sapper.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "sapper.h"
namespace planet{
Sapper::Sapper(std::vector<vectorItems>& ground,
planet::data& server): Robot(ground, server){}
Direction Sapper::randWay(){
Direction where;
u_char randCount = rand() % 4;
switch (randCount)
{
case 0:
return Direction::UP;
case 1:
return Direction::DOWN;
case 2:
return Direction::LEFT;
case 3:
return Direction::RIGHT;
default:
return Direction::NONE;
}
}
void Sapper::goInRandWay(){
Direction where = randWay();
for(u_char i = 0; i < 4; ++i)
if(server.availibleToGo(id, where, true)){
move(where);
break;
}
else
where = randWay();
}
void Sapper::work(){
goInRandWay();
}
void Sapper::on(){
isOn = true;
}
void Sapper::off(){
isOn = false;
}
void Sapper::func(){
if(server.isRobotLive[id] && isOn)
work();
}
void Sapper::changeMode(){
isOn = !isOn;
}
void vectorS::cmd(char* context){
server.readCmd(context);
if(server.cmd() == "add"){
this->push_back(Sapper(ground, server));
}
else if(server.cmd() == "change mode")
(*this)[server.getNum()].changeMode();
}
void vectorS::refresh(){
for(Sapper & elem : *this)
elem.func();
}
}