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