-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.c
96 lines (68 loc) · 1.49 KB
/
input.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
#include "head.h"
void get_entry(char entry[32]){
int i = 0;
while ((entry[i] = getchar()) != '\n') i++;
entry[i] = '\0';
}
int get_difficulty(){
/*
* Easy : 10% of bombs
* Medium : 20% of bombs
* Hard : 30% of bombs
*/
char entry[32];
do{
printf(" # Choose difficulty : easy, medium, hard\n > ");
get_entry(entry);
} while (strcmp(entry, "easy") && strcmp(entry, "medium") && strcmp(entry, "hard"));
if (entry[0] == 'e') // Lazy-ass method
return 1;
else if (entry[0] == 'm')
return 2;
else if (entry[0] == 'h')
return 3;
return 1;
}
int get_int(void){
int value = 0;
char c;
while (isdigit((c = getchar()))){
value *= 10;
value += c - '0';
}
return value;
}
int get_size(void){
/*
* Small : 8x8
* Medium : 12x12
* Large : 16x16
* Custom
*/
char entry[32];
do{
printf(" # Choose size : small, medium, large, custom\n > ");
get_entry(entry);
} while (strcmp(entry, "small") && strcmp(entry, "medium") && strcmp(entry, "large") && strcmp(entry, "custom"));
if (entry[0] == 's')
return 8;
else if (entry[0] == 'm')
return 12;
else if (entry[0] == 'l')
return 16;
else
return get_int();
return 8;
}
void get_yn(char entry[32]){
do {
printf(" # Choices : yes, no\n > ");
get_entry(entry);
} while (strcmp(entry, "yes") && strcmp(entry, "no"));
}
void get_board(char entry[32]){
do {
printf(" # Choose the board : leaders, recent\n > ");
get_entry(entry);
} while (strcmp(entry, "recent") && strcmp(entry, "leader"));
}