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

Function start_game

CPP/Problems/maze_game.c:295–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293}
294
295void start_game(char *file_name)
296{
297 //Creating Maze by Reading File
298 FILE *fp;
299 fp = fopen(file_name, "r");
300 if (fp == NULL)
301 {
302 printf("%s file not found!!!\n");
303 return;
304 }
305 int snk[2], ply[2], dst[2];
306 int x;
307 fscanf(fp, "%d %d %d", &x, &l, &w);
308 int obs[x - 3][2], n = 0;
309 for (int i = 0; i < x; i++)
310 {
311 int t1, t2, t3;
312 fscanf(fp, "%d %d %d", &t1, &t2, &t3);
313 if (t3 == 0)
314 {
315 ply[0] = t1;
316 ply[1] = t2;
317 }
318 else if (t3 == 1)
319 {
320 snk[0] = t1;
321 snk[1] = t2;
322 }
323 else if (t3 == 2)
324 {
325 dst[0] = t1;
326 dst[1] = t2;
327 }
328 else
329 {
330 obs[n][0] = t1;
331 obs[n++][1] = t2;
332 }
333 }
334 fclose(fp);
335
336 //Preparing the Maze for the game
337 char maze[l][w];
338 maze[0][0] = maze[0][w - 1] = maze[l - 1][0] = maze[l - 1][w - 1] = '#';
339 for (int i = 1; i < w - 1; i++)
340 maze[0][i] = maze[l - 1][i] = '-';
341 for (int i = 1; i < l - 1; i++)
342 maze[i][0] = maze[i][w - 1] = '|';
343 for (int i = 1; i < l - 1; i++)
344 for (int j = 1; j < w - 1; j++)
345 maze[i][j] = ' ';
346 // positioning obstacles
347 for (int i = 0; i < n; i++)
348 maze[obs[i][0]][obs[i][1]] = 'O';
349 maze[dst[0]][dst[1]] = 'X'; //setting final position
350 maze[snk[0]][snk[1]] = '~'; //setting sanke position
351 maze[ply[0]][ply[1]] = '^'; //setting player position
352

Callers 1

mainFunction · 0.85

Calls 1

playFunction · 0.85

Tested by

no test coverage detected