-
Notifications
You must be signed in to change notification settings - Fork 1
/
Args.c
142 lines (139 loc) · 4.92 KB
/
Args.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
#include "Run.h"
#include "Config.h"
bool _insertColorFromArg(char * a, short * s){
if ( strcmp(a, "RED") == 0){
(*s) = COLOR_RED;
}
else if (strcmp(a, "BLACK") == 0){
(*s) = COLOR_BLACK;
}
else if (strcmp(a, "WHITE") == 0){
(*s) = COLOR_WHITE;
}
else if (strcmp(a, "GREEN") == 0){
(*s) = COLOR_GREEN;
}
else if (strcmp(a, "MAGENTA") == 0){
(*s) = COLOR_MAGENTA;
}
else if (strcmp(a, "CYAN") == 0){
(*s) = COLOR_CYAN;
}
else if (strcmp(a, "BLUE") == 0){
(*s) = COLOR_BLUE;
}
else if (strcmp(a, "NOCOLOR") == 0){
(*s) = NOCOLOR;
}
else {
return true;
}
return false;
}
bool handleArgs(Board * b, Player * p, int argc, char * argv[], short * cpf, short * cpb, short * cwf, short * cwb, bool * contact){
bool noPlayer = false;
bool noWall = false;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0){
printf("Help for Walled In:\n");
printf(" -h --> help\n");
printf(" -cw arg1 arg2 --> Set color of walls (Foreground) (Background) \n");
printf(" -cp arg1 arg2 --> Set color of player (Foreground) (Background) \n");
printf(" -> Available color arguments: RED, BLACK, WHITE, GREEN, MAGENTA, CYAN, BLUE, NOCOLOR\n" );
printf(" -ncp --> Shortcut to not color player \n");
printf(" -ncw --> Shortcut to not color wall \n");
printf(" --nocolor --> Don't color anything (terminal defaults used)\n");
printf(" -nc --> Shortcut to not color anything \n\n");
printf(" -p arg1 --> Change the character that the player is displayed as. Limit 1 character\n");
printf(" -w arg1 --> Change the character that the inside of the walls are displayed as. Default is " ". Limit 1 character\n");
printf(" -t arg1 --> Change the number of tunnels that will exist at any time. Limit 100\n\n");
printf(" --nocollision --> Turn off collision mechanics, game runs until you quit\n");
printf(" -ncol --> Shortcut to no collision\n");
printf("\nWalled In by Paul Harrington\n");
return true;
}
if (!noWall && strcmp(argv[i], "-cw") == 0 && argc > i + 2){
if (_insertColorFromArg(argv[i + 1], cwf) || _insertColorFromArg(argv[i + 2], cwb)){
printf("Bad color code - default assumed\n");
}
}
if (!noPlayer && strcmp(argv[i], "-cp") == 0 && argc > i + 2){
if (_insertColorFromArg(argv[i + 1], cpf) || _insertColorFromArg(argv[i + 2], cpb)){
printf("Bad color code - default assumed\n");
}
}
if (strcmp(argv[i], "-ncp") == 0){
(*cpf) = 100;
noPlayer = true;
}
if (strcmp(argv[i], "-ncw") == 0){
(*cwf) = 100;
noWall = true;
}
if (strcmp(argv[i], "-nc") == 0 || strcmp(argv[i], "--nocolor") == 0){
*cwf = 100;
*cpf = 100;
noWall = true;
noPlayer = true;
}
if (strcmp(argv[i], "-p") == 0 && argc > i + 1){
int length = 0;
while (1){
if (argv[i + 1][length] == '\0'){
break;
}
else {
length++;
}
}
if (length == 1){
p->avatar = argv[i + 1];
}
else {
printf("Bad length for player string\n");
}
}
if (strcmp(argv[i], "-w") == 0 && argc > i + 1){
int length = 0;
while (1){
if (argv[i + 1][length] == '\0'){
break;
}
else {
length++;
}
}
if (length == 1){
b->wallChar = argv[i + 1];
}
else {
printf("Bad length for wall string\n");
}
}
if (strcmp(argv[i], "-t") == 0 && argc > i + 1){
bool allNum = true;
int length = 0;
while (1){
if (argv[i + 1][length] == '\0'){
break;
}
else {
if (!(argv[i + 1][length] > 47 && argv[i + 1][length] < 58)){
allNum = false;
}
}
length++;
}
if (allNum && atoi(argv[i + 1]) < 100 && atoi(argv[i + 1]) > 0){
b->numTunnels = atoi(argv[i + 1]);
}
else {
printf("Too many tunnels\n");
}
}
if (strcmp(argv[i], "-ncol") == 0 || strcmp(argv[i], "--nocollision") == 0){
*contact = false;
}
}
return false;
}