MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / play

Function play

CPP/Problems/maze_game.c:174–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174void play(char maze[l][w], int snk[2], int ply[2], int dst[2])
175{
176 char ch;
177 int win = 0, lose = 0;
178 head mem;
179 mem.cnt = 0;
180 mem.start = mem.end = NULL;
181 record(&mem, ply, snk, '^');
182 while (!win && !lose)
183 {
184 system("cls");
185 printf("RULES OF GAME\n");
186 printf("-------------\n");
187 printf("Press \'w\' to move up\n");
188 printf("Press \'a\' to move left\n");
189 printf("Press \'s\' to move down\n");
190 printf("Press \'d\' to move right\n");
191 printf("Press \'u\' to undo\n");
192 printf("Press \'q\' to quit\n\n");
193 print_maze(maze);
194 printf("\n");
195 fflush(stdin);
196 ch = _getch();
197 switch (ch)
198 {
199 case 'w':
200 {
201 if (maze[ply[0] - 1][ply[1]] == ' ' || maze[ply[0] - 1][ply[1]] == 'X')
202 {
203 if (maze[ply[0] - 1][ply[1]] == 'X')
204 win = 1;
205 maze[ply[0]][ply[1]] = ' ';
206 maze[ply[0] - 1][ply[1]] = '^';
207 ply[0]--;
208 record(&mem, ply, snk, '^');
209 }
210 break;
211 }
212 case 'a':
213 {
214 if (maze[ply[0]][ply[1] - 1] == ' ' || maze[ply[0]][ply[1] - 1] == 'X')
215 {
216 if (maze[ply[0]][ply[1] - 1] == 'X')
217 win = 1;
218 maze[ply[0]][ply[1]] = ' ';
219 maze[ply[0]][ply[1] - 1] = '<';
220 ply[1]--;
221 record(&mem, ply, snk, '<');
222 }
223 break;
224 }
225 case 's':
226 {
227 if (maze[ply[0] + 1][ply[1]] == ' ' || maze[ply[0] + 1][ply[1]] == 'X')
228 {
229 if (maze[ply[0] + 1][ply[1]] == 'X')
230 win = 1;
231 maze[ply[0]][ply[1]] = ' ';

Callers 1

start_gameFunction · 0.85

Calls 6

recordFunction · 0.85
print_mazeFunction · 0.85
undoFunction · 0.85
del_memoryFunction · 0.85
move_snakeFunction · 0.85
check_statusFunction · 0.85

Tested by

no test coverage detected