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
|
#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;
enum Difficulty {
Easy,
Medium,
Hard,
};
int list[] = {40, 78, 94, 62, 68, 74, 56, 55, 88, 55, 59, 73,
19, 32, 81, 95, 71, 63, 15, 41, 11, 38, 86};
int score = 100;
int level = 1;
int size = 5;
void decrement_score(enum Difficulty diff);
void level_up();
int getrand();
enum Difficulty get_difficulty();
int main(int argc, char *argv[]) {
// Get a random number to run a random algorithm
int guess;
int random_number = getrand();
printf(COLOR_RED);
print_ascii("./assets/banner.txt");
enum Difficulty diff = get_difficulty();
while (level > 0 && level <= 10) {
printf(BAR);
switch (random_number) {
case 1:
bubblesort(list, size);
break;
case 2:
insertionsort(list, size);
break;
case 3:
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("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);
}
printf("Score: %d\n", score);
}
return 0;
}
int getrand() {
srand(time(0));
return (rand() % (UPPER - LOWER + 1)) + LOWER;
}
void decrement_score(enum 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;
}
}
enum Difficulty get_difficulty() {
int choice;
enum 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() {
level++;
size += 3;
}
|