-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_mastermind.c
71 lines (55 loc) · 1.79 KB
/
my_mastermind.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
#include "my_headers.h"
int main(int argc, char *argv[]){
char* master_code = malloc(16);
master_code[0] = '\0';
int gimmick_int[5] = {8};
int* int_mastercode;
int_mastercode = &gimmick_int[0];
char* guess = malloc(16);
guess[0] = '\0';
check_c_opt(argc, argv, master_code);
int attempts = check_t_opt(argc, argv);
if(*master_code == '\0'){
my_secretcode(int_mastercode);
my_itoa(master_code, int_mastercode);
printf("We generated code for you!\n");
}
printf(COLOR_YELLOW "Will you find the secret code?" COLOR_RESET "\n");
int round = 1;
bool valid_code = false;
char* my_buf = malloc(16);
while(attempts != 0){
printf(COLOR_BLUE "\t---***---" COLOR_RESET "\n");
printf(COLOR_YELLOW "\t-Round %d-" COLOR_RESET "\n", round);
if(attempts == 1){
printf(COLOR_YELLOW "Last attempt left! You're gonna lose! :D" COLOR_RESET "\n");
}
while(valid_code == false){
if(guess[0] != '\0'){
my_emptystr(guess);
}
my_guess_reader(guess, my_buf);
int length = my_strlen(guess);
if(length != 4){
printf(COLOR_RED "Wrong input!" COLOR_RESET "\n");
continue;
}
else{
valid_code = code_validator(guess);
}
}
if(my_guess_check(master_code, guess)){
break;
}
attempts--;
round++;
valid_code = false;
}
if(attempts == 0){
printf("The secret code was " COLOR_RED "%s, Looser" COLOR_RESET "!\n", master_code);
}
free(master_code);
free(guess);
free(my_buf);
return EXIT_SUCCESS;
}