-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrain.cpp
71 lines (65 loc) · 1.33 KB
/
Brain.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
#include "Brain.h"
#include "Ear.h"
#include "Eye.h"
#include "Face.h"
#include "Hand.h"
#include "Leg.h"
Brain::Brain()
{
createBodyParts();
}
void Brain::createBodyParts()
{
ear = new Ear(this);
eye = new Eye(this);
face = new Face(this);
hand = new Hand(this);
leg = new Leg(this);
}
void Brain::somethingHappenedToBodyPart(BodyPart* bodyPart)
{
// I'm so sorry, Barbara Liskov ;)
if (dynamic_cast<Ear*>(bodyPart) != nullptr)
{
string heardSounds = ((Ear*)bodyPart)->getSounds();
if (heardSounds.find("stupid") != std::string::npos)
{
// attacking offender
leg->stepForward();
hand->hitPersonNearYou();
leg->kick();
}
else if (heardSounds.find("cool") != std::string::npos)
{
face->smile();
}
else
{
cout << "OK, I give you another try\n";
}
}
else if (dynamic_cast<Eye*>(bodyPart) != nullptr)
{
cout << "brain can analyze what you see and can react appropriately using different body parts\n";
}
else if (dynamic_cast<Hand*>(bodyPart) != nullptr)
{
Hand* h = (Hand*)bodyPart;
if (hand->doesItHurt())
{
leg->stepBack();
}
else if (hand->isItNice()) {
leg->stepForward();
hand->embrace();
}
else
{
cout << "OK, you can touch this :)\n";
}
}
else if (dynamic_cast<Leg*>(bodyPart) != nullptr)
{
cout << "leg can also feel something if you would like it to\n";
}
}