-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.cpp
116 lines (91 loc) · 2.5 KB
/
state.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <bombsystem.h>
State::State() {
messages[0] = this->toString() + " is cut!";
messages[1] = "Cut next wire:";
String mess = "";
for (State* nextState : this->preferedNextStates) {
mess += nextState->toString() + " ";
}
messages[2] = mess;
//messages[3] = "Time: " + String(owner->countDownTime);
}
void State::addExpectedNextState(State* nextState) {
this->preferedNextStates[nbpreferedNextStates++] = nextState;
}
State* State::timeout() {
return new Explosion();
}
void State::copyProp(State* newInstance) {
newInstance->preferedNextStates = this->preferedNextStates;
}
/****** Idle *******/
Idle::Idle() {
messages[0] = "Rescue hostages!";
messages[1] = "Instruction:";
messages[2] = "Cut the ElectricWire:";
String mess = "";
for (State* nextState : this->preferedNextStates) {
mess += nextState->toString() + " ";
}
messages[3] = mess;
}
State* Idle::cutRedWire() {
State* newState = new RedWireCut();
newState->addExpectedNextState(new RedWireCut());
return newState;
}
String Idle::toString() {
return "Idle";
}
/****** Finish *******/
Finish::Finish() {
messages[0] = "";
messages[1] = " Congratulate! ";
messages[2] = "";
messages[3] = "";
}
String Finish::toString() {
return "Finish";
}
/****** Explosion *******/
Explosion::Explosion() {
messages[0] = "Too late, sorry";
messages[1] = " Boommm! ";
messages[2] = "";
messages[3] = "";
}
String Explosion::toString() {
return "Explosion";
}
/********************** Wire Cut State ***************************/
RedWireCut::RedWireCut() : WireCut() {}
State* RedWireCut::cutBlueWire() {
State* newState = new BlueWireCut();
newState->addExpectedNextState(new BlueWireCut());
return newState;
}
String RedWireCut::toString() {
return "Red wire";
}
BlueWireCut::BlueWireCut() : WireCut() {}
State* BlueWireCut::cutYellowWire() {
State* newState = new YellowWireCut();
newState->addExpectedNextState(new YellowWireCut());
return newState;
}
String BlueWireCut::toString() {
return "Blue wire";
}
YellowWireCut::YellowWireCut() : WireCut() {}
State* YellowWireCut::cutBlackWire() {
State* newState = new Finish();
newState->addExpectedNextState(new BlackWireCut());
return newState;
}
String YellowWireCut::toString() {
return "Yellow wire";
}
BlackWireCut::BlackWireCut() : WireCut() {}
String BlackWireCut::toString() {
return "Black wire";
}