-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNinja.cc
More file actions
40 lines (34 loc) · 1.08 KB
/
Ninja.cc
File metadata and controls
40 lines (34 loc) · 1.08 KB
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
#include "Ninja.h"
Ninja::Ninja(int row, int col) : Participant('N', row, col, new RescuerBehaviour()), strength(0), poisoned(false) {}
void Ninja::incurDamage(Participant* p) {
if (poisoned) {
return; // Ninja is a giant snorc, does not suffer any damage
}
int damage = p->causeDamage();
if (damage == RESCUE) {
return; // Other participant is also a Ninja, do nothing
} else if (damage == 0) {
delete moveBehaviour;
moveBehaviour = new RescuedBehaviour();
} else {
poisoned = true;
avatar = 'S'; // Ninja becomes a giant snorc
strength = random(3) + 6; // Random strength between 6 and 8
delete moveBehaviour;
moveBehaviour = new VillainBehaviour();
}
}
int Ninja::causeDamage() const {
if (poisoned) {
return strength; // Ninja is a giant snorc, return its strength
} else {
return RESCUE;
}
}
bool Ninja::isSafe() const {
if (poisoned) {
return false; // Giant snorcs never leave the Pit
} else{
return row == 0; // Ninja is at the top
}
}