-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_check_and_disply.c
146 lines (139 loc) · 4.38 KB
/
ft_check_and_disply.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check_and_disply.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahajji <ahajji@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/30 20:31:54 by ahajji #+# #+# */
/* Updated: 2022/11/30 20:31:56 by ahajji ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int go_right(t_data *data)
{
mlx_clear_window(data->data_2.mlx, data->w_n.mlx_win);
if (data->m_p.ptr[data->p_l.y][data->p_l.x + 1] == '0')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y][data->p_l.x + 1] = 'P';
}
else if (data->m_p.ptr[data->p_l.y][data->p_l.x + 1] == 'C')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y][data->p_l.x + 1] = 'P';
data->just_one_coin += 1;
}
else if (data->m_p.ptr[data->p_l.y][data->p_l.x + 1] == 'E'
&& data->just_one_coin == data->data_2.sum_coin)
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
return (1);
}
return (0);
}
int go_top(t_data *data)
{
mlx_clear_window(data->data_2.mlx, data->w_n.mlx_win);
if (data->m_p.ptr[data->p_l.y - 1][data->p_l.x] == '0')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y - 1][data->p_l.x] = 'P';
}
else if (data->m_p.ptr[data->p_l.y - 1][data->p_l.x] == 'C')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y - 1][data->p_l.x] = 'P';
data->just_one_coin += 1;
}
if (data->m_p.ptr[data->p_l.y - 1][data->p_l.x] == 'E'
&& data->just_one_coin == data->data_2.sum_coin)
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
return (1);
}
return (0);
}
int go_left(t_data *data)
{
mlx_clear_window(data->data_2.mlx, data->w_n.mlx_win);
if (data->m_p.ptr[data->p_l.y][data->p_l.x - 1] == '0')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y][data->p_l.x - 1] = 'P';
}
else if (data->m_p.ptr[data->p_l.y][data->p_l.x - 1] == 'C')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y][data->p_l.x - 1] = 'P';
data->just_one_coin += 1;
}
else if (data->m_p.ptr[data->p_l.y][data->p_l.x - 1] == 'E'
&& data->just_one_coin == data->data_2.sum_coin)
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
return (1);
}
return (0);
}
int go_down(t_data *data)
{
mlx_clear_window(data->data_2.mlx, data->w_n.mlx_win);
if (data->m_p.ptr[data->p_l.y + 1][data->p_l.x] == '0')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y + 1][data->p_l.x] = 'P';
}
else if (data->m_p.ptr[data->p_l.y + 1][data->p_l.x] == 'C')
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
data->m_p.ptr[data->p_l.y + 1][data->p_l.x] = 'P';
data->just_one_coin += 1;
}
else if (data->m_p.ptr[data->p_l.y + 1][data->p_l.x] == 'E'
&& data->just_one_coin == data->data_2.sum_coin)
{
data->p_l.count_move += 1;
data->m_p.ptr[data->p_l.y][data->p_l.x] = '0';
return (1);
}
return (0);
}
int ft_check_and_display(int keycode, t_data *data)
{
int k;
check_esp(keycode);
k = 0;
if (keycode == 2 && data->check != 2)
{
if (go_right(data))
k = 1;
display_all_window(keycode, data);
if (k == 1)
{
mlx_put_image_to_window(data->data_2.mlx, data->w_n.mlx_win,
data->win.new_door, ((data->m_p.x * 106) - 345) / 2,
((data->m_p.y * 106) - 220) / 2);
data->check = 2;
}
ft_printf("%d\n", data->p_l.count_move);
}
else if (keycode == 13 && data->check != 2)
{
ft_check_and_display_2(data, keycode, &k);
ft_printf("%d\n", data->p_l.count_move);
}
ft_check_and_display_3(data, keycode);
return (0);
}