-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAntelope.cpp
More file actions
44 lines (41 loc) · 812 Bytes
/
Antelope.cpp
File metadata and controls
44 lines (41 loc) · 812 Bytes
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
#include "Antelope.h"
#include"World.h"
Antelope::Antelope(int power, int activity, World *world, int x, int y)
:Animal(power, activity, world, x, y)
{
image = 'a';
}
void Antelope::action(int dx = 0, int dy = 0)
{
randMove(&dx, &dy, 2);
Animal::action(dx, dy);
}
void Antelope::collision(Organism *attacker)
{
if (attacker->getImage() != image)
{
if (world->randInt(0, 100) <= 50)
{
int dx = x, dy = y;
if (world->findFreeSpace(&dx, &dy, 2))
{
int a = x, b = y;
Animal::action(dx - x, dy - y);
world->moveOrganism(attacker, a, b);
world->addComment(string(1, image), "run away from", string(1, attacker->getImage()));
}
else
{
Animal::collision(attacker);
}
}
else
{
Animal::collision(attacker);
}
}
else
{
Animal::collision(attacker);
}
}