-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouv.c
113 lines (106 loc) · 2.42 KB
/
mouv.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
/*
** mouv.c for mouv.c in /home/pierre/work/Unix_System/PSU_2016_my_sokoban/
**
** Made by Pierre Narcisi
** Login <[email protected]>
**
** Started on Wed Dec 14 15:18:28 2016 Pierre Narcisi
** Last update Fri Dec 16 16:25:09 2016 Pierre Narcisi
*/
#include "my.h"
void mouv(char **tab, t_var *p, int index, char **tab2)
{
int i;
int pos;
i = 0;
pos = my_strlen(tab[i]);
if (index == KEY_LEFT)
my_mouv_LEFT(tab, p, tab2);
if (index == KEY_RIGHT)
my_mouv_RIGHT(tab, p, tab2);
if (index == KEY_UP)
my_mouv_UP(tab, p, tab2);
if (index == KEY_DOWN)
my_mouv_DOWN(tab, p, tab2);
while (tab[i] != NULL)
{
mvprintw(LINES / 2 + i, COLS / 2 - (pos / 2), "%s", tab[i]);
i++;
}
}
void my_mouv_UP(char **tab, t_var *p, char **tab2)
{
if (tab[p->y - 1][p->x] != '#')
{
if (tab[p->y - 1][p->x] != 'X' ||
(tab[p->y - 2][p->x] != 'X' && tab[p->y - 2][p->x] != '#'))
{
if (tab[p->y - 1][p->x] == 'X')
tab[p->y - 2][p->x] = 'X';
tab[p->y - 1][p->x] = 'P';
if (tab2[p->y][p->x] == 'O')
tab[p->y][p->x] = 'O';
else
tab[p->y][p->x] = ' ';
p->y = p->y - 1;
}
}
}
void my_mouv_DOWN(char **tab, t_var *p, char **tab2)
{
if (tab[p->y + 1][p->x] != '#')
{
if (tab[p->y + 1][p->x] != 'X' ||
(tab[p->y + 2][p->x] != 'X' && tab[p->y + 2][p->x] != '#'))
{
if (tab[p->y + 1][p->x] == 'X')
{
tab[p->y + 2][p->x] = 'X';
}
tab[p->y + 1][p->x] = 'P';
if (tab2[p->y][p->x] == 'O')
tab[p->y][p->x] = 'O';
else
tab[p->y][p->x] = ' ';
p->y = p->y + 1;
}
}
}
void my_mouv_RIGHT(char **tab, t_var *p, char **tab2)
{
if (tab[p->y][p->x + 1] != '#')
{
if (tab[p->y][p->x + 1] != 'X' ||
(tab[p->y][p->x + 2] != 'X' && tab[p->y][p->x + 2] != '#'))
{
if (tab[p->y][p->x + 1] == 'X')
{
tab[p->y][p->x + 2] = 'X';
}
tab[p->y][p->x + 1] = 'P';
if (tab2[p->y][p->x] == 'O')
tab[p->y][p->x] = 'O';
else
tab[p->y][p->x] = ' ';
p->x = p->x + 1;
}
}
}
void my_mouv_LEFT(char **tab, t_var *p, char **tab2)
{
if (tab[p->y][p->x - 1] != '#')
{
if (tab[p->y][p->x - 1] != 'X' ||
(tab[p->y][p->x - 2] != 'X' && tab[p->y][p->x - 2] != '#'))
{
if (tab[p->y][p->x - 1] == 'X')
tab[p->y][p->x - 2] = 'X';
tab[p->y][p->x - 1] = 'P';
if (tab2[p->y][p->x] == 'O')
tab[p->y][p->x] = 'O';
else
tab[p->y][p->x] = ' ';
p->x = p->x - 1;
}
}
}