-
Notifications
You must be signed in to change notification settings - Fork 1
/
manualMd.c
273 lines (249 loc) · 6.34 KB
/
manualMd.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "mapping.h"
#include "guilib.h"
#include "strlib.h"
#include "manualMd.h"
#include "offline.h"
#include "labyrinthAPI.h"
/*! \file manualMd.c
\brief Manual mode related functions.
\author Maeva Arlandis et Alexis Devillard
\version 6.2
\date 10 janvier 2017
*/
void manualMode(Map* L)
{
t_return_code ret = MOVE_OK; /* indicates the status of the previous move */
t_move* myMove=(t_move*) malloc(sizeof(t_move));
if (myMove==NULL) //test if the allocation is a success
exit(EXIT_FAILURE);
myMove->type = DO_NOTHING;
myMove->value = 0;
t_move* opMove=(t_move*) malloc(sizeof(t_move));
if (opMove==NULL) //test if the allocation is a success
exit(EXIT_FAILURE);
opMove->type = DO_NOTHING;
opMove->value = 0;
dispMap(L);
while(ret==MOVE_OK)
{
if (L->players[0]->turn==1)//op turn
{
addStr(L->infoP2[5]," ","");
if(L->players[1]->mode!=1&&L->offline==0)
{
ret = getMove(opMove);
movement(L,1,opMove);
}
else
{
getMoveOff(L,1,opMove);
ret = movement(L,1,opMove);
}
}
else
{
if(L->players[1]->mode!=1&&L->offline==0)
{
manualMv(L,0,myMove);
movement(L,0,myMove);
sendComment(L->comments[rand()%5]);
ret = sendMove(*myMove);
}
else
{
manualMv(L,0,myMove);
ret = movement(L,0,myMove);
}
}
//endwin();
//printLabyrinth();
dispInfo(L);
dispMap(L);
dispPath(L);
}
if ((L->players[0]->turn==1 && ret == MOVE_WIN) || (L->players[0]->turn==0 && ret == MOVE_LOSE))
{
addStr(L->infoP1[4]," ","");
addStr(L->infoP2[6]," YOU LOOSE","");
addStr(L->infoP1[6]," YOU WIN","");
addStr(L->cases[L->heigth/2]," YOU WIN","");
}
else
{
addStr(L->infoP1[4]," ","");
addStr(L->infoP1[6]," YOU LOOSE","");
addStr(L->infoP2[6]," YOU WIN","");
addStr(L->cases[L->heigth/2]," YOU LOOSE","");
}
if(L->offline==0&&L->players[1]->mode!=1)
/* end the connection, because we are polite */
closeConnection();
free(myMove);
free(opMove);
}
void manualMv(Map* L, int P,t_move* move)
{
int choice=40;
if(P==0)
{
addStr(L->infoP1[4]," ","");
addStr(L->infoP1[4],"It's your turn, select a move.","");
}
else if(P==1)
{
addStr(L->infoP2[4]," ","");
addStr(L->infoP2[4],"It's your turn, select a move.","");
}
choice=GUI(L,choice);
switch(choice)
{
/*MANUAL MOVES*/
case 40:
move->type=MOVE_LEFT;
break;
case 41:
move->type=MOVE_UP;
break;
case 42:
move->type=MOVE_DOWN;
break;
case 43:
move->type=MOVE_RIGHT;
break;
case 46:
move->type=DO_NOTHING;
break;
/*MAP MOVES*/
case 44:
L->mvC=0;
while(choice!=45)
{
dispMap(L);
if(P==0)
{
addStr(L->infoP1[3]," Select OK to confirm the line","");
addStr(L->infoP1[4]," or the column to move.","");
}
else if(P==1)
{
addStr(L->infoP2[3]," Select OK to confirm the line","");
addStr(L->infoP2[4]," or the column to move.","");
}
dispInfo(L);
choice=GUI(L,choice);
switch(choice)
{
/*COLUMN MOVES*/
case 40:
L->mvL=-1;
if(L->mvC>0)
L->mvC--;
else
L->mvC=L->width-1;
break;
case 43:
L->mvL=-1;
if(L->mvC+1<L->width)
L->mvC++;
else
L->mvC=0;
break;
/*LINE MOVES*/
case 41:
L->mvC=-1;
if(L->mvL>0)
L->mvL--;
else
L->mvL=L->heigth-1;
break;
case 42:
L->mvC=-1;
if(L->mvL+1<L->heigth)
L->mvL++;
else
L->mvL=0;
break;
}
}
choice=40;
addStr(L->infoP1[3]," ","");
addStr(L->infoP1[4]," ","");
addStr(L->infoP2[3]," ","");
addStr(L->infoP2[4]," ","");
int selected=0;
while(choice!=45|| selected!=1)
{
dispMap(L);
if(P==0)
{
addStr(L->infoP1[3]," Select the direction of the rotation.","");
addStr(L->infoP1[4]," Then select OK to confirm.","");
}
else if(P==1)
{
addStr(L->infoP2[3]," Select the direction of the rotation.","");
addStr(L->infoP2[4]," Then select OK to confirm.","");
}
dispInfo(L);
choice=GUI(L,choice);
switch(choice)
{
/*ROTATIONS MOVES*/
case 40:
if(L->mvL!=-1)
{
move->type=ROTATE_LINE_LEFT;
move->value=L->mvL;
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2+L->mvL+1, 18+L->width/2+3, " ");
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2+L->mvL+1, 18-L->width/2-2, "<<");
selected=1;
}
break;
case 43:
if(L->mvL!=-1)
{
move->type=ROTATE_LINE_RIGHT;
move->value=L->mvL;
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2+L->mvL+1, 18-L->width/2-2, " ");
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2+L->mvL+1, 18+L->width/2+3, ">>");
selected=1;
}
break;
case 41:
if(L->mvC!=-1)
{
move->type=ROTATE_COLUMN_UP;
move->value=L->mvC;
mvwprintw(L->guiWins[0]->win, 12+L->heigth/2+3, 18-L->width/2+L->mvC+1, " ");
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2-1, 18-L->width/2+L->mvC+1, "^");
selected=1;
}
break;
case 42:
if(L->mvC!=-1)
{
move->type=ROTATE_COLUMN_DOWN;
move->value=L->mvC;
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2-1, 18-L->width/2+L->mvC+1, " ");
mvwprintw(L->guiWins[0]->win, 12+L->heigth/2+3, 18-L->width/2+L->mvC+1, "v");
selected=1;
}
break;
}
}
mvwprintw(L->guiWins[0]->win, 12+L->heigth/2+3, 18-L->width/2+L->mvC+1, " ");
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2-1, 18-L->width/2+L->mvC+1, " ");
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2+L->mvL+1, 18-L->width/2-2, " ");
mvwprintw(L->guiWins[0]->win, 12-L->heigth/2+L->mvL+1, 18+L->width/2+3, " ");
L->mvL=-1;
L->mvC=-1;
addStr(L->infoP1[3]," ","");
addStr(L->infoP1[4]," ","");
addStr(L->infoP2[3]," ","");
addStr(L->infoP2[4]," ","");
break;
}
}