-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovement.c
More file actions
109 lines (100 loc) · 2.71 KB
/
movement.c
File metadata and controls
109 lines (100 loc) · 2.71 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* movement.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamir <mamir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/05 22:02:24 by mamir #+# #+# */
/* Updated: 2024/05/19 15:21:47 by mamir ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_move_right(t_data *data)
{
int px;
int py;
px = data->px;
py = data->py;
if (data->map[py][px + 1] == 'E' && all_collected(data))
{
data->moves++;
printf("moves: %d\n", data->moves);
write(1, "You Win!\n", 10);
exit(0);
}
if ((data->map[py][px + 1] == '0') || (data->map[py][px + 1] == 'C'))
{
data->map[py][px] = '0';
data->map[py][px + 1] = 'P';
ft_player_position(data);
data->moves++;
printf("moves: %d\n", data->moves);
}
}
void ft_move_left(t_data *data)
{
int px;
int py;
px = data->px;
py = data->py;
if (data->map[py][px - 1] == 'E' && all_collected(data))
{
data->moves++;
printf("moves: %d\n", data->moves);
write(1, "You Win!\n", 10);
exit(0);
}
if ((data->map[py][px - 1] == '0') || (data->map[py][px - 1] == 'C'))
{
data->map[py][px] = '0';
data->map[py][px - 1] = 'P';
ft_player_position(data);
data->moves++;
printf("moves: %d\n", data->moves);
}
}
void ft_move_up(t_data *data)
{
int px;
int py;
px = data->px;
py = data->py;
if (data->map[py - 1][px] == 'E' && all_collected(data))
{
data->moves++;
printf("moves: %d\n", data->moves);
write(1, "You Win!\n", 10);
exit(0);
}
if ((data->map[py - 1][px] == '0') || (data->map[py - 1][px] == 'C'))
{
data->map[py][px] = '0';
data->map[py - 1][px] = 'P';
ft_player_position(data);
data->moves++;
printf("moves: %d\n", data->moves);
}
}
void ft_move_down(t_data *data)
{
int px;
int py;
px = data->px;
py = data->py;
if (data->map[py + 1][px] == 'E' && all_collected(data))
{
data->moves++;
printf("moves: %d\n", data->moves);
write(1, "You Win!\n", 10);
exit(0);
}
if ((data->map[py + 1][px] == '0') || (data->map[py + 1][px] == 'C'))
{
data->map[py][px] = '0';
data->map[py + 1][px] = 'P';
ft_player_position(data);
data->moves++;
printf("moves: %d\n", data->moves);
}
}