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
|
#include "sort.h"
#include "utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// https://texteditor.com/multiline-text-art/
const int EASY_SCORE_DECREMENT = 10;
const int MEDIUM_SCORE_DECREMENT = 20;
const int LOWER = 1;
const int UPPER = 3;
typedef enum Difficulty {
Easy,
Medium,
Hard,
} Difficulty;
int list[35];
int score = 100;
int level = 1;
int size = 5;
void decrement_score(Difficulty diff);
void level_up();
void level_down();
int getrand();
void getarr(int size);
Difficulty get_difficulty();
int main(int argc, char *argv[]) {
// Get a random number to run a random algorithm
srand(time(0));
int guess;
printf(COLOR_RED);
print_ascii("./assets/banner.txt");
Difficulty diff = get_difficulty();
while (level > 0 && level <= 10) {
int random_number = getrand();
printf(BAR);
switch (random_number) {
case 1:
getarr(size);
bubblesort(list, size);
break;
case 2:
getarr(size);
insertionsort(list, size);
break;
case 3:
getarr(size);
selectionsort(list, size);
break;
// case 4: radixsort(list); break;
default:
break;
}
printf(BAR);
printf("1. BubbleSort\n");
printf("2. InsertionSort\n");
printf("3. SelectionSort\n");
printf("4. RadixSort\n");
printf("%d", random_number);
printf("Enter your guess: ");
scanf("%d", &guess);
if (guess == random_number) {
printf("Congratulations!!! Your answer was right!!\n");
score += 10;
level_up();
} else {
decrement_score(diff);
level_down();
}
printf("Score: %d\n", score);
}
return 0;
}
int getrand() { return (rand() % (UPPER - LOWER + 1)) + LOWER; }
void decrement_score(Difficulty diff) {
if (diff == Easy) {
printf("Wrong Answer!! The score will be decremented by 10\n");
score -= EASY_SCORE_DECREMENT;
} else if (diff == Medium) {
printf("Wrong Answer!! The score will be decremented by 20\n");
score -= MEDIUM_SCORE_DECREMENT;
} else {
printf("Wrong Answer!! The score will be reseted to 0\n");
score = 0;
}
}
Difficulty get_difficulty() {
int choice;
Difficulty difficulty;
printf(COLOR_CYAN " CHOOSE DIFFICULTY\n" COLOR_OFF);
printf(COLOR_RED BAR COLOR_OFF);
printf("1. Easy\n");
printf("2. Medium\n");
printf("3. Hard\n");
printf(BAR);
printf("Enter difficulty: ");
scanf("%d", &choice);
switch (choice) {
case 1:
difficulty = Easy;
break;
case 2:
difficulty = Medium;
break;
case 3:
difficulty = Hard;
break;
}
return difficulty;
}
void level_up() {
if (level == 10) {
print_ascii("./assets/winner.txt");
printf("Congratulations!! You WON the game");
exit(1);
}
level++;
size += 3;
printf(COLOR_BOLD COLOR_RED
"You have been leveled up to Level %d\n" COLOR_OFF,
level);
}
void level_down() {
if (level >= 2) {
level--;
size -= 3;
} else {
printf("Too many wrong answers!!, You Lose!");
exit(1);
}
}
void getarr(int size) {
for (int i = 0; i < size; i++) {
list[i] = rand() % 100;
}
}
|