-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_p2.c
113 lines (104 loc) · 2.85 KB
/
control_p2.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
103
104
105
106
107
108
109
110
111
112
113
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* control_p2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: welim <welim@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/06 19:44:59 by welim #+# #+# */
/* Updated: 2022/07/07 17:45:07 by welim ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void move_pw2(t_data *data)
{
char **map;
map = data->map.map;
if (map[data->img.p_x - 1][data->img.p_y] == 'C')
{
map[data->img.p_x][data->img.p_y] = '0';
map[data->img.p_x - 1][data->img.p_y] = 'P';
data->img.coin.count--;
data->moves++;
}
else if (map[data->img.p_x - 1][data->img.p_y] == 'E')
{
if (data->img.coin.count == 0)
{
ft_putstr_fd("You won with just ", 1);
ft_putnbr_fd(data->moves + 1, 1);
ft_putstr_fd(" steps", 1);
exit_game(data);
}
}
return ;
}
void move_ps2(t_data *data)
{
char **map;
map = data->map.map;
if (map[data->img.p_x + 1][data->img.p_y] == 'C')
{
map[data->img.p_x][data->img.p_y] = '0';
map[data->img.p_x + 1][data->img.p_y] = 'P';
data->img.coin.count--;
data->moves++;
}
else if (map[data->img.p_x + 1][data->img.p_y] == 'E')
{
if (data->img.coin.count == 0)
{
ft_putstr_fd("You won with just ", 1);
ft_putnbr_fd(data->moves + 1, 1);
ft_putstr_fd(" steps", 1);
exit_game(data);
}
}
return ;
}
void move_pd2(t_data *data)
{
char **map;
map = data->map.map;
if (map[data->img.p_x][data->img.p_y + 1] == 'C')
{
map[data->img.p_x][data->img.p_y] = '0';
map[data->img.p_x][data->img.p_y + 1] = 'P';
data->img.coin.count--;
data->moves++;
}
else if (map[data->img.p_x][data->img.p_y + 1] == 'E')
{
if (data->img.coin.count == 0)
{
ft_putstr_fd("You won with just ", 1);
ft_putnbr_fd(data->moves + 1, 1);
ft_putstr_fd(" steps", 1);
exit_game(data);
}
}
return ;
}
void move_pa2(t_data *data)
{
char **map;
map = data->map.map;
if (map[data->img.p_x][data->img.p_y - 1] == 'C')
{
map[data->img.p_x][data->img.p_y] = '0';
map[data->img.p_x][data->img.p_y - 1] = 'P';
data->img.coin.count--;
data->moves++;
}
else if (map[data->img.p_x][data->img.p_y - 1] == 'E')
{
if (data->img.coin.count == 0)
{
ft_putstr_fd("You won with just ", 1);
ft_putnbr_fd(data->moves + 1, 1);
ft_putstr_fd(" steps", 1);
exit_game(data);
}
}
return ;
}