-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.c
More file actions
87 lines (80 loc) · 2.19 KB
/
Copy pathmap.c
File metadata and controls
87 lines (80 loc) · 2.19 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
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
/*
* PURPOSE : Imlement of generate and print the map
* DATE : 5/4/23
* DATE MOD : 17/4/23
*/
#include <stdio.h>
#include "color.h"
#include "map.h"
#include "macro.h"
/* Function to print the map */
void mapPrint(char **arr, int *mRow, int *mCol, int* gRow, int* gCol, int *bRow, int *bCol)
{
int i, j;
char* emptyColor = "red";
char* fillColor = "green";
char* reset = "reset";
for (i = 0; i < *mRow; i++)
{
for (j = 0; j < *mCol; j++)
{
if ( arr[i][j] == 'B' && ISEQUAL(*gRow, *gCol, *bRow, *bCol) == TRUE )
{
setBackground(fillColor);
printf("%c", arr[i][j]);
setBackground(reset);
}
else if (arr[i][j] == 'G')
{
setBackground(emptyColor);
printf("%c", arr[i][j]);
setBackground(reset);
}
else
{
printf("%c", arr[i][j]);
}
}
printf("\n");
}
printf("Move the box to the goal to win the game!\n");
printf("Press w to move up\n");
printf("Press s to move down\n");
printf("Press a to move left\n");
printf("Press d to move right\n");
if ( ISEQUAL(*gRow, *gCol, *bRow, *bCol) == TRUE )
{
printf("\nCongratulation you have win the game!!\n\n");
}
}
/* Function that position all the variables into 2D array */
void map(char **arr, int *mRow, int *mCol, int *pRow, int *pCol, int *gRow, int *gCol, int *bRow, int *bCol)
{
int i, j;
for (i = 0; i < *mRow; i++)
{
for (j = 0; j < *mCol; j++)
{
if ((i == 0 || i == *mRow - 1) || (j == 0 || j == *mCol - 1))
{
arr[i][j] = '*';
}
else if ( ISEQUAL(i, j, *pRow, *pCol) == TRUE )
{
arr[i][j] = 'P';
}
else if ( ISEQUAL(i, j, *bRow, *bCol) == TRUE )
{
arr[i][j] = 'B';
}
else if ( ISEQUAL(i, j, *gRow, *gCol) == TRUE )
{
arr[i][j] = 'G';
}
else
{
arr[i][j] = ' ';
}
}
}
}