-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.c
More file actions
59 lines (52 loc) · 1.65 KB
/
box.c
File metadata and controls
59 lines (52 loc) · 1.65 KB
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
#include <stdio.h>
#include <stdlib.h>
#include "box.h"
/* NAME: box
* PURPOSE: fills the map array with the values
* IMPORTS: myMap, f, car, player
* EXPORTS: NONE
* ASSERTIONS: structs have been created and file read in
*/
void box (Map* myMap, FILE * f, Car* car,Player* player){
int i,j, value;
for(i = 0; i < myMap->row + 2; i++){
for(j = 0; j < myMap->col+2; j++)
{
if( i == 0 || i == myMap->row+1){
myMap->map[i][j] = 5;
}
else if (j==0 || j == myMap->col+1){
myMap->map[i][j] = 5;
}
else{
if(fscanf(f,"%d", &value) !=1){
printf("Failed to read data from the file\n");
fclose(f);
}
else{
if(value== 2){
car->carRow=i;
car->carCol=j;
car->direction = 1;
myMap->map[i][j] = 1;
}
else if (value== 3)
{
player->row = i;
player->col = j;
myMap->map[i][j] = 0;
}
else if (value == 4)
{
myMap->goalrow =i;
myMap->goalcol =j;
myMap->map[i][j]= value;
}
else{
myMap->map[i][j]= value;
}
}
}
}
}
}