-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_deal_key.c
102 lines (97 loc) · 2.44 KB
/
ft_deal_key.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_deal_key.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atabiti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/19 11:56:02 by atabiti #+# #+# */
/* Updated: 2022/03/25 11:50:12 by atabiti ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int deal_key3(struct s_s2 *a, int h)
{
if (a->exactarray[a->y_p][a->x_p - 1] == 'E' && h >= a->collectible)
{
write(1, "\n YOU WIN\n", 10);
ft_free(a->exactarray, a->to_free + 1);
exit(1);
}
if (a->exactarray[a->y_p][a->x_p - 1] == 'E' && h < a->collectible)
{
return (0);
}
else
{
ft_move_left(a);
a->ft_movements += 1;
a->x_p -= 1;
}
return (0);
}
int deal_key2(struct s_s2 *a, int h)
{
if (a->exactarray[a->y_p][a->x_p + 1] != '1')
{
if (a->exactarray[a->y_p][a->x_p + 1]
== 'E' && h >= a->collectible)
{
write(1, "\n YOU WIN\n", 10);
ft_free(a->exactarray, a-> to_free + 1);
exit(1);
}
if (a->exactarray[a->y_p][a->x_p + 1]
== 'E' && h < a->collectible)
{
return (0);
}
else
{
ft_move_right(a);
a->ft_movements += 1;
a->x_p += 1;
}
}
return (0);
}
int deal_key4(struct s_s2 *a, int h)
{
if (a->exactarray[a->y_p - 1][a->x_p] == 'E' && h >= a->collectible)
{
write(1, "\n YOU WIN\n", 10);
ft_free(a->exactarray, a->to_free + 1);
exit(1);
}
if (a->exactarray[a->y_p - 1][a->x_p] == 'E' && h < a->collectible)
{
return (0);
}
else
{
ft_move_up(a);
a->ft_movements += 1;
a->y_p -= 1;
}
return (1);
}
int deal_key5(struct s_s2 *a, int h)
{
if (a->exactarray[a->y_p + 1][a->x_p] == 'E' && h >= a->collectible)
{
write(1, "\n YOU WIN\n", 10);
ft_free(a->exactarray, a->to_free + 1);
exit(1);
}
if (a->exactarray[a->y_p + 1][a->x_p] == 'E' && h < a->collectible)
{
return (0);
}
else
{
ft_move_down(a);
a->ft_movements += 1;
a->y_p += 1;
}
return (1);
}