-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
107 lines (97 loc) · 2.41 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aboncine <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 15:43:17 by aboncine #+# #+# */
/* Updated: 2023/02/23 13:17:11 by aboncine ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int ft_atoi_check_char(const char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] != '+' && str[i] != '-' && (str[i] < '0' || str[i] > '9'))
return (256);
i++;
}
return (0);
}
long ft_atoi(const char *nptr)
{
int i;
long result;
int sign;
i = 0;
result = 0;
sign = 1;
if (ft_atoi_check_char(nptr) == 256)
return (256);
while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13))
i++;
if (nptr[i] == '+' || nptr[i] == '-')
{
if (nptr[i] == '-')
sign *= -1;
i++;
}
while (nptr[i] >= '0' && nptr[i] <= '9')
{
result = result * 10 + nptr[i] - '0';
i++;
}
return (result * sign);
}
void ft_start_game(char **argv)
{
t_cub3d box;
ft_init_struct(&box);
ft_create_map(&box, argv[1]);
ft_check_map(&box);
ft_where_to_start(&box);
ft_create_window(&box);
ft_create_image(&box.img, box);
ft_init_text(&box);
ft_raycasting(&box);
mlx_put_image_to_window(box.mlx_ptr, box.win_ptr, box.img.img_ptr, 0, 0);
mlx_hook(box.win_ptr, 17, 0, ft_free_n_exit, &box);
mlx_key_hook(box.win_ptr, ft_handlekeys, &box);
mlx_loop(box.mlx_ptr);
}
void check_cub(char *argv)
{
int i;
i = ft_strlen(argv);
i--;
if (argv[i] != 'b')
{
printf("Error\nMappa non valida\n");
exit(0);
}
i--;
if (argv[i] != 'u')
{
printf("Error\nMappa non valida\n");
exit(0);
}
i--;
if (argv[i] != 'c')
{
printf("Error\nMappa non valida\n");
exit(0);
}
}
int main(int argc, char **argv)
{
if (argc == 2)
{
check_cub(argv[1]);
ft_start_game(argv);
}
write(2, "Error\nparametri non validi\n", 28);
}