-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlevel1.c
311 lines (262 loc) · 8.15 KB
/
level1.c
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* File : level1.c
By : Nathan Lam
Login : nathancy
Team : Hot Wings
Date : 4/25/2015 */
/* This file contains the function that loads the simulator to level 1
with all of its features and capabilities. */
#include <stdio.h>
#include "display.h"
#include "functions.h"
#include "huggers.h"
#include "mousecam.h"
#define DEBUG
/* Function is given '1'. It sends the mouse to the level 1 simulator
with all of past features and any additional features as determined
in the spec. */
void level1(int level)
{
/* Declare variables */
int *northcam, *southcam, *eastcam, *westcam, ncam, ecam, wcam,
north, east, ready, south, west, x, y, dir, direction, row, col,
spaceerror, d_error, checker, win, cells;
char input, ch, restart, flagrestart;
/* Write strings to arrays (shortcut) */
char blank[64] = " ";
char str[64] = "Ready?";
char error[64] = "What??";
char m[64] = "Maze cheat now available at Level 0";
char n[64] = "Maze uncheat not available below Level 2";
char lr[64] = "Wall hugger not available at Level 0";
char space[64] = "No mouse's choice";
char crash1[64] = "CRASH";
char crash2[64] = " CRASH";
char crash3[64] = " CRASH";
char res[64] = "Restart (y/n)?";
/* Initiate values for the simulator */
x = 0;
y = 0;
cells = 0;
/* Set initial flags */
flagrestart = FALSE;
win = FALSE;
d_error = TRUE;
ready = TRUE;
dir = NORTH;
/* Initiate the display to level 1 */
init_display(level);
/* Show the mouse in starting position */
show_position(x, y);
/* Write initial ready message */
write_message(str, 10);
/* Initiate mouse cam to starting position */
mouse_cam(1,0,1);
/* Show initial number of cells */
show_cells(cells);
/* Initiate the walls */
lvl0_get_walls(x, y, &north, &east, &west, &south);
/* Display the walls on the screen */
put_walls(x, y, north, east, west, south);
/* Show the mouse in starting position */
show_mouse(dir, x, y);
/* Get command */
input = getchar();
if(input == '\n')
{
input = getchar();
}
/* As long as command is not quit */
while (input != 'q')
{
/* Clear win messages when flag is triggered */
if (win == TRUE)
{
write_message(blank, 3);
write_message(blank, 2);
write_message(blank, 1);
win == FALSE;
}
switch(input)
{
/* Change direction */
case 'a' :
dir = getdirection(input, dir);
break;
case 's' :
dir = getdirection(input, dir);
break;
case 'd' :
dir = getdirection(input, dir);
break;
/* Move foward in new direction */
case 'w' :
/* Increment number of cells */
cells ++;
/* Clear initial ready message */
if(ready == TRUE)
{
write_message(blank, 10);
ready = FALSE;
}
/* Clear win message if user restarts */
if(flagrestart == TRUE)
{
write_message(blank, 10);
flagrestart == FALSE;
}
/* Clear error message for default errors */
if(d_error == TRUE || spaceerror == TRUE)
{
write_message(blank, 2);
d_error = FALSE;
spaceerror = FALSE;
}
/* Check for crash */
checker = checkcrash(dir, &north, &east, &west, &south);
/* If crash, change direction to crash */
if (checker == TRUE)
{
dir = CRASH;
}
/* If did not crash, move the mouse */
else
{
movemouse(dir, &y, &x);
}
break;
/* Reveal the maze */
case 'm' :
cheese_scope();
break;
/* Print error message for hiding maze */
case 'n' :
write_message(n, 9);
break;
/* Right wall hugger */
case 'r' :
/* Clear messages if flags were triggered */
if(ready == TRUE)
{
write_message(blank, 10);
ready = FALSE;
}
if(flagrestart == TRUE)
{
write_message(blank, 10);
flagrestart == FALSE;
}
if(d_error == TRUE || spaceerror == TRUE)
{
write_message(blank, 2);
d_error = FALSE;
spaceerror = FALSE;
}
/* Move mouse along right wall */
right_hugger(&dir, &x, &y, north, east, west, south);
/* Increment number of cells */
cells ++;
break;
/* Left wall hugger */
case 'l' :
/* Clear messages if flags were triggered */
if(ready == TRUE)
{
write_message(blank, 10);
ready = FALSE;
}
if(flagrestart == TRUE)
{
write_message(blank, 10);
flagrestart == FALSE;
}
if(d_error == TRUE || spaceerror == TRUE)
{
write_message(blank, 2);
d_error = FALSE;
spaceerror = FALSE;
}
/* Move mouse along left wall */
left_hugger(&dir, &x, &y, north, east, west, south);
/* Increment number of cells */
cells ++;
break;
/* Print error messages */
case ' ' :
write_message(space, 9);
write_message(error, 2);
spaceerror = TRUE;
break;
default :
if (d_error == FALSE)
{
write_message(error, 2);
}
d_error = TRUE;
}
/* Get walls for next coordinate */
lvl0_get_walls(x, y, &north, &east, &west, &south);
/* Get direction for mousecam */
dir_mousecam(&dir, &ncam, &ecam, &wcam, north, south, east, west);
/* Show mousecam on display */
mouse_cam(wcam, ncam, ecam);
/* Print win messages if win */
if ((x == 8 || x == 7) && (y == 8 || y == 7))
{
write_message("WIN!!", 3);
write_message(" WIN!!", 2);
write_message(" WIN!!",1);
win = TRUE;
}
/* Print crash messages if crash */
if (dir == CRASH)
{
/* Show crashed mouse */
show_mouse(dir, x, y);
write_message(crash1, 3);
write_message(crash2, 2);
write_message(crash3, 1);
write_message(res, 10);
/* If user wants to restart */
if((getchar()) == 'y')
{
/* Initiate maze to beginning */
x = 0;
y = 0;
cells = 0;
dir = NORTH;
mouse_cam(1,0,1);
/* Initiate the walls to beginning */
lvl0_get_walls(x, y, &north, &east, &west, &south);
/* Clear old crash messages */
write_message(blank, 3);
write_message(blank, 2);
write_message(blank, 1);
write_message(blank, 10);
write_message(str, 10);
/* Set restart flag */
flagrestart = TRUE;
/* Show mouse at start position */
show_mouse(dir, x, y);
/* Show coordinates at start position */
show_position(x, y);
}
/* Close maze if user does not want to restart */
else
{
break;
}
}
/* Show number of cells on display */
show_cells(cells);
/* Show mouse on display */
show_mouse(dir, x, y);
/* Place walls onto display */
put_walls(x, y, north, east, west, south);
/* Show new coordinates on display */
show_position(x, y);
/* Get next command */
input = getchar();
}
/* Close the maze */
clear_screen();
}