-
Notifications
You must be signed in to change notification settings - Fork 1
/
direction.c
35 lines (33 loc) · 1014 Bytes
/
direction.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
//contains a function which gets a direction for non-movement commands which require a direction
//returns the direction else returns -1
#include <string.h>
#include "direction.h"
#include <stdio.h>
int getDirection(void) {
char command[10];
int direction;
int commandDone = FALSE;
while (commandDone == FALSE) {
scanf("%9s",command);
printf("\n");
if (strcmp(command, "down") == SAME) {
direction = DOWN;
commandDone = TRUE;
} else if (strcmp(command, "up") == SAME) {
direction = UP;
commandDone = TRUE;
} else if (strcmp(command, "right") == SAME) {
direction = RIGHT;
commandDone = TRUE;
} else if (strcmp(command, "left") == SAME) {
direction = LEFT;
commandDone = TRUE;
} else if (strcmp(command, "cancel") == SAME) {
direction = -1;
commandDone = TRUE;
} else {
printf("Enter a valid direction or cancel.\n");
}
}
return direction;
}