-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.c
70 lines (63 loc) · 1.67 KB
/
enemy.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* enemy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asarandi <asarandi@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/27 17:59:48 by asarandi #+# #+# */
/* Updated: 2017/12/27 18:38:25 by asarandi ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
int distance_calc(t_pos *position, int x, int y)
{
int a;
int b;
a = (position->x + g_piece_top_extra) - x;
a *= a;
b = (position->y + g_piece_left_extra) - y;
b *= b;
return (a + b);
}
int confirm_enemy(int i, int w, int j, char c)
{
char *pl;
char *plc;
pl = g_plateau;
plc = g_plateau_copy;
if (pl[(i * w) + j] != plc[(i * w) + j])
{
if ((plc[(i * w) + j] == '.') && (pl[(i * w) + j] == c))
{
g_enemy_x = i;
g_enemy_y = j;
return (1);
}
}
return (0);
}
void find_new_enemy(void)
{
int i;
int j;
int w;
char c;
w = g_plateau_width;
c = 'X';
if (g_player == '2')
c = 'O';
i = 0;
while (i < g_plateau_height)
{
j = 0;
while (j < g_plateau_width)
{
if (confirm_enemy(i, w, j, c) == 1)
return ;
j++;
}
i++;
}
return ;
}