-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathso_long_mvp_utils.c
More file actions
105 lines (100 loc) · 3.19 KB
/
Copy pathso_long_mvp_utils.c
File metadata and controls
105 lines (100 loc) · 3.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long_mvp_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mobouifr <mobouifr@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/13 16:56:41 by mobouifr #+# #+# */
/* Updated: 2024/05/20 14:15:34 by mobouifr ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void move_player_up(t_game *game)
{
if (game->map[game->py - 1][game->px] == 'E' && game->col_count == 0)
{
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
close_window(game);
}
if (game->map[game->py - 1][game->px] == '0' || game->map[game->py
- 1][game->px] == 'C')
{
if (game->map[game->py - 1][game->px] == 'C')
game->col_count--;
game->map[game->py - 1][game->px] = 'P';
game->map[game->py][game->px] = '0';
game->py--;
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
}
}
void move_player_down(t_game *game)
{
if (game->map[game->py + 1][game->px] == 'E' && game->col_count == 0)
{
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
close_window(game);
}
if (game->map[game->py + 1][game->px] == '0' || game->map[game->py
+ 1][game->px] == 'C')
{
if (game->map[game->py + 1][game->px] == 'C')
game->col_count--;
game->map[game->py + 1][game->px] = 'P';
game->map[game->py][game->px] = '0';
game->py++;
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
}
}
void move_player_left(t_game *game)
{
if (game->map[game->py][game->px - 1] == 'E' && game->col_count == 0)
{
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
close_window(game);
}
if (game->map[game->py][game->px - 1] == '0' || game->map[game->py][game->px
- 1] == 'C')
{
if (game->map[game->py][game->px - 1] == 'C')
game->col_count--;
game->map[game->py][game->px - 1] = 'P';
game->map[game->py][game->px] = '0';
game->px--;
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
}
}
void move_player_right(t_game *game)
{
if (game->map[game->py][game->px + 1] == 'E' && game->col_count == 0)
{
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
close_window(game);
}
if (game->map[game->py][game->px + 1] == '0' || game->map[game->py][game->px
+ 1] == 'C')
{
if (game->map[game->py][game->px + 1] == 'C')
game->col_count--;
game->map[game->py][game->px + 1] = 'P';
game->map[game->py][game->px] = '0';
game->px++;
game->moves_count++;
write(1, "moves count : ", 15);
ft_putnbr_nl(game->moves_count);
}
}