-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.c
More file actions
107 lines (100 loc) · 2.55 KB
/
printer.c
File metadata and controls
107 lines (100 loc) · 2.55 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdio.h>
#include <stdlib.h>
#include "mapStruct.h"
#include "printer.h"
#include "carStruct.h"
#include "playerStruct.h"
#include "carCollide.h"
/* NAME: printer
* PURPOSE: to display the current game state to the user
* IMPORTS: myMap, car, player structs
* EXPORTS: NONE
* ASSERTIONS: all structs have been initalised with valid values
*/
void printer(Map* myMap, Car* car,Player* player){
int i, j;
refresh();
for(i = 0; i < myMap->row+2; i++)
{
for(j = 0; j < myMap->col+2; j++)
{
if(i== car->carRow && j == car->carCol){
printf("%c",carDirection(car->direction));
}
else if(i== player->row && j == player->col){
printf("P");
}
else{
if(myMap->map[i][j] == 0)
{
printf(" ");
}
else if(myMap->map[i][j]==1){
printf(".");
}
else if(myMap->map[i][j]==2)
{
printf(">");
}
else if(myMap->map[i][j]==3)
{
printf("P");
}
else if(myMap->map[i][j] == 4)
{
printf("G");
}
else if(myMap->map[i][j] == 5)
{
printf("*");
}
else{
printf("!");
}
}
}
printf("\n");
}
printf("Howdy");
printf("Player row: %d\n",player->row);
printf("Player col: %d\n",player->col);
printf("Car row: %d\n",car->carRow);
printf("Car col: %d\n",car->carCol);
}
/* NAME: refresh
* PURPOSE: clear the terminal screen
* IMPORTS: NONE
* EXPORTS: NONE
* ASSERTIONS: N/A
*/
void refresh()
{
system("clear");
}
/* NAME: carDirection
* PURPOSE: returns a char charater to appropriately display the direction the car is travelling
* IMPORTS: direction an in value from the car struct
* EXPORTS: charDirection - char character to reperesent the cars direction
* ASSERTIONS: direction is an int from 1-4
*/
char carDirection(int direction){
char charDirection;
switch (direction)
{
case 1:
charDirection ='>';
break;
case 2:
charDirection ='<';
break;
case 3:
charDirection ='^';
break;
case 4:
charDirection ='v';
break;
default:
break;
}
return charDirection;
}