-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker_helper.c
140 lines (129 loc) · 3.1 KB
/
checker_helper.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker_helper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wboutzou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/25 21:35:15 by wboutzou #+# #+# */
/* Updated: 2022/06/26 00:41:25 by wboutzou ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int check_wall(t_game *game)
{
int i;
int j;
j = 0;
i = 0;
while (i < game->height)
{
if (i == 0 || i == game->height - 1)
{
j = 0;
while (game->map[i][j] != '\0')
{
if (game->map[i][j] != '1')
return (0);
j++;
}
}
else
if (game->map[i][0] != '1' || game->map[i][game->width - 1] != '1')
return (0);
i ++;
}
return (1);
}
int checkalpha(t_game *game)
{
int i;
int j;
i = 1;
while (i < game->height - 1)
{
j = 1;
while (j < game->width - 2)
{
if (game->map[i][j] == 'C')
game->count.coll++;
else if (game->map[i][j] == 'E')
game->count.exit++;
else if (game->map[i][j] == 'P')
game->count.start++;
else if (game->map[i][j] != '1' && game->map[i][j] != '0')
return (0);
j++;
}
i++;
}
if (game->count.coll < 1 || game->count.exit < 1 || game->count.start != 1)
return (0);
return (1);
}
int check_size(t_game *game)
{
int i;
i = 0;
if (game->map[i++] == '\0')
return (0);
while (game->map[i] != '\0')
{
if (ft_strlen(game->map[i - 1]) != ft_strlen(game->map[i]))
return (0);
i++;
}
game->width = ft_strlen(game->map[i - 1]);
game->height = i;
return (1);
}
int check_read(char *read)
{
int i;
int j;
int n;
int pos;
pos = 0;
i = 0;
j = 0;
n = 0;
if (read[0] == '\n')
return (0);
while (read[i] != '\0')
{
if (read[i] == '\n' && (read[i + 1] == '\n' || read[i + 1] == '\0'))
return (0);
i++;
}
return (1);
}
void check_move(t_game *game, int step_y, int step_x)
{
int x;
int y;
x = game->pos.player_x;
y = game->pos.player_y;
if (game->map[y + step_y][x + step_x] == 'C')
{
game->tmp = game->map[y + step_y][x + step_x];
game->map[y + step_y][x + step_x] = game->map[y][x];
game->map[y][x] = '0';
game->count.coll--;
game->count.moves++;
ft_printf("%d\n", game->count.moves);
}
else if (game->map[y + step_y][x + step_x] == 'E' && game->count.coll <= 0)
{
game->count.moves++;
ft_printf("%d\n", game->count.moves);
exit(1);
}
else if (game->map[y + step_y][x + step_x] == '0')
{
game->tmp = game->map[y + step_y][x + step_x];
game->map[y + step_y][x + step_x] = game->map[y][x];
game->map[y][x] = game->tmp;
game->count.moves++;
ft_printf("%d\n", game->count.moves);
}
}