-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_player.c
152 lines (145 loc) · 3.44 KB
/
move_player.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_player.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: azaher <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/13 09:29:05 by azaher #+# #+# */
/* Updated: 2023/01/18 11:01:34 by azaher ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int *find_player(t_game *g)
{
int *ar;
ar = malloc(2 * sizeof(int));
ar[0] = 0;
while (g->map[ar[0]])
{
ar[1] = 0;
while (g->map[ar[0]][ar[1]])
{
if (g->map[ar[0]][ar[1]] == 'P')
{
return (ar);
}
ar[1]++;
}
ar[0]++;
}
free(ar);
return (0);
}
void move_player_right(t_game *g, int i, int j)
{
if (g->map[i][j + 1] == '0')
{
g->map[i][j] = '0';
g->map[i][j + 1] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i][j + 1] == 'C')
{
g->map[i][j] = '0';
g->map[i][j + 1] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i][j + 1] == 'E')
{
if (count_rings(g->map) == 0)
exit (1);
else
display_map(g->map, g);
}
else if (g->map[i][j + 1] == '1')
display_map(g->map, g);
}
void move_player_left(t_game *g, int i, int j)
{
if (g->map[i][j - 1] == '0')
{
g->map[i][j] = '0';
g->map[i][j - 1] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i][j - 1] == 'C')
{
g->map[i][j] = '0';
g->map[i][j - 1] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i][j - 1] == 'E')
{
if (count_rings(g->map) == 0)
exit (1);
else
display_map(g->map, g);
}
else if (g->map[i][j - 1] == '1')
display_map(g->map, g);
}
void move_player_up(t_game *g, int i, int j)
{
if (g->map[i - 1][j] == '0')
{
g->map[i][j] = '0';
g->map[i - 1][j] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i - 1][j] == 'C')
{
g->map[i][j] = '0';
g->map[i - 1][j] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i - 1][j] == 'E')
{
if (count_rings(g->map) == 0)
exit (1);
else
display_map(g->map, g);
}
else if (g->map[i][j - 1] == '1')
display_map(g->map, g);
}
void move_player_down(t_game *g, int i, int j)
{
if (g->map[i + 1][j] == '0')
{
g->map[i][j] = '0';
g->map[i + 1][j] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i + 1][j] == 'C')
{
g->map[i][j] = '0';
g->map[i + 1][j] = 'P';
g->moves++;
ft_printf("You moved %d times!\n", g->moves);
display_map(g->map, g);
}
else if (g->map[i + 1][j] == 'E')
{
if (count_rings(g->map) == 0)
exit (1);
else
display_map(g->map, g);
}
else if (g->map[i][j + 1] == '1')
display_map(g->map, g);
}