-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFox.cpp
More file actions
49 lines (44 loc) · 1.02 KB
/
Fox.cpp
File metadata and controls
49 lines (44 loc) · 1.02 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
41
42
43
44
45
46
47
48
49
#include "Fox.h"
#include "World.h"
#include "config.h"
Fox::Fox(int power, int activity, World *world, int x, int y)
:Animal(power, activity, world, x, y)
{
image = 'f';
}
void Fox::action(int a, int b)
{
int dx[] = { MOVE_RANGE_X };
int dy[] = { MOVE_RANGE_Y };
bool findPlace = false;
int move_num = (sizeof(dx) / sizeof(dx[0]));
int *move = new int[move_num];
int rand_int;
char place;
for (int i = 0; i < move_num; i++)
{
move[i] = i;
}
while (move_num >= 0 && !findPlace)
{
rand_int = world->randInt(0, move_num--);
place = world->checkPlace(x + dx[move[rand_int]], y + dy[move[rand_int]]);
if (place == '!')
{
move[rand_int] = move[move_num];
continue;
}
if (place != ' ')
{
if (world->checkOrganismPower(x + dx[move[rand_int]], y + dy[move[rand_int]]) > power)
{
move[rand_int] = move[move_num];
world->addComment(string(1, image), "hissed", string(1,place));
continue;
}
}
findPlace = true;
Animal::action(dx[move[rand_int]], dy[move[rand_int]]);
}
delete(move);
}