Krolyxon
Commit 0980f89

Branches

Refs →

trossrcmain.c

121 lines · 2.6 KB · C

1#include "sort.h"
2#include "utils.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <time.h>
6// https://texteditor.com/multiline-text-art/
7const int EASY_SCORE_DECREMENT = 10;
8const int MEDIUM_SCORE_DECREMENT = 20;
9const int LOWER = 1;
10const int UPPER = 3;
11
12enum Difficulty {
13 Easy,
14 Medium,
15 Hard,
16};
17
18int list[] = {40, 78, 94, 62, 68, 74, 56, 55, 88, 55, 59, 73,
19 19, 32, 81, 95, 71, 63, 15, 41, 11, 38, 86};
20
21int score = 100;
22int level = 1;
23int size = 5;
24
25void decrement_score(enum Difficulty diff);
26void level_up();
27int getrand();
28enum Difficulty get_difficulty();
29
30int main(int argc, char *argv[]) {
31 // Get a random number to run a random algorithm
32 int guess;
33 int random_number = getrand();
34
35 printf(COLOR_RED);
36 print_ascii("./assets/banner.txt");
37 enum Difficulty diff = get_difficulty();
38
39 while (level > 0 && level <= 10) {
40 printf(BAR);
41 switch (random_number) {
42 case 1:
43 bubblesort(list, size);
44 break;
45 case 2:
46 insertionsort(list, size);
47 break;
48 case 3:
49 selectionsort(list, size);
50 break;
51 // case 4: radixsort(list); break;
52 default:
53 break;
54 }
55
56 printf(BAR);
57 printf("1. BubbleSort\n");
58 printf("2. InsertionSort\n");
59 printf("3. SelectionSort\n");
60 printf("4. RadixSort\n");
61 printf("Enter your guess: ");
62 scanf("%d", &guess);
63 if (guess == random_number) {
64 printf("Congratulations!!! Your answer was right!!\n");
65 score += 10;
66 level_up();
67 } else {
68 decrement_score(diff);
69 }
70 printf("Score: %d\n", score);
71 }
72 return 0;
73}
74
75int getrand() {
76 srand(time(0));
77 return (rand() % (UPPER - LOWER + 1)) + LOWER;
78}
79
80void decrement_score(enum Difficulty diff) {
81 if (diff == Easy) {
82 printf("Wrong Answer!! The score will be decremented by 10\n");
83 score -= EASY_SCORE_DECREMENT;
84 } else if (diff == Medium) {
85 printf("Wrong Answer!! The score will be decremented by 20\n");
86 score -= MEDIUM_SCORE_DECREMENT;
87 } else {
88 printf("Wrong Answer!! The score will be reseted to 0\n");
89 score = 0;
90 }
91}
92
93enum Difficulty get_difficulty() {
94 int choice;
95 enum Difficulty difficulty;
96 printf(COLOR_CYAN " CHOOSE DIFFICULTY\n" COLOR_OFF);
97 printf(COLOR_RED BAR COLOR_OFF);
98 printf("1. Easy\n");
99 printf("2. Medium\n");
100 printf("3. Hard\n");
101 printf(BAR);
102 printf("Enter difficulty: ");
103 scanf("%d", &choice);
104 switch (choice) {
105 case 1:
106 difficulty = Easy;
107 break;
108 case 2:
109 difficulty = Medium;
110 break;
111 case 3:
112 difficulty = Hard;
113 break;
114 }
115 return difficulty;
116}
117
118void level_up() {
119 level++;
120 size += 3;
121}