| @@ -4,6 +4,7 @@ |
| 4 | 4 | | #include <stdlib.h> |
| 5 | 5 | | #include <time.h> |
| 6 | 6 | | // https://texteditor.com/multiline-text-art/ |
| 7 | + | |
| 7 | 8 | | const int EASY_SCORE_DECREMENT = 10; |
| 8 | 9 | | const int MEDIUM_SCORE_DECREMENT = 20; |
| 9 | 10 | | const int LOWER = 1; |
| @@ -21,6 +22,7 @@ int score = 100; |
| 21 | 22 | | int level = 1; |
| 22 | 23 | | int size = 5; |
| 23 | 24 | | |
| 25 | + | // Declaring Functions |
| 24 | 26 | | void decrement_score(Difficulty diff); |
| 25 | 27 | | void level_up(); |
| 26 | 28 | | void level_down(); |
| @@ -33,13 +35,14 @@ int main(int argc, char *argv[]) { |
| 33 | 35 | | srand(time(0)); |
| 34 | 36 | | int guess; |
| 35 | 37 | | |
| 36 | | − | printf(COLOR_RED); |
| 38 | + | clearscreen(); |
| 39 | + | printf(COLOR_CYAN); |
| 37 | 40 | | print_ascii("./assets/banner.txt"); |
| 38 | 41 | | Difficulty diff = get_difficulty(); |
| 39 | 42 | | |
| 40 | 43 | | while (level > 0 && level <= 10) { |
| 41 | 44 | | int random_number = getrand(); |
| 42 | | − | printf(BAR); |
| 45 | + | printf(COLOR_GREEN BAR COLOR_OFF); |
| 43 | 46 | | switch (random_number) { |
| 44 | 47 | | case 1: |
| 45 | 48 | | getarr(size); |
| @@ -58,22 +61,21 @@ int main(int argc, char *argv[]) { |
| 58 | 61 | | break; |
| 59 | 62 | | } |
| 60 | 63 | | |
| 61 | | − | printf(BAR); |
| 62 | | − | printf("1. BubbleSort\n"); |
| 63 | | − | printf("2. InsertionSort\n"); |
| 64 | | − | printf("3. SelectionSort\n"); |
| 65 | | − | printf("4. RadixSort\n"); |
| 66 | | − | printf("%d", random_number); |
| 64 | + | printf(COLOR_GREEN BAR COLOR_OFF); |
| 65 | + | printf(COLOR_BOLD "[1] " COLOR_OFF "Bubble Sort\n"); |
| 66 | + | printf(COLOR_BOLD "[2] " COLOR_OFF "Insertion Sort\n"); |
| 67 | + | printf(COLOR_BOLD "[3] " COLOR_OFF "Selection Sort\n"); |
| 68 | + | printf(COLOR_BOLD "[4] " COLOR_OFF "Radix Sort\n"); |
| 67 | 69 | | printf("Enter your guess: "); |
| 68 | 70 | | scanf("%d", &guess); |
| 69 | 71 | | if (guess == random_number) { |
| 70 | | − | printf("Congratulations!!! Your answer was right!!\n"); |
| 71 | 72 | | score += 10; |
| 72 | 73 | | level_up(); |
| 73 | 74 | | } else { |
| 74 | 75 | | decrement_score(diff); |
| 75 | 76 | | level_down(); |
| 76 | 77 | | } |
| 78 | + | |
| 77 | 79 | | printf("Score: %d\n", score); |
| 78 | 80 | | } |
| 79 | 81 | | return 0; |
| @@ -83,7 +85,8 @@ int getrand() { return (rand() % (UPPER - LOWER + 1)) + LOWER; } |
| 83 | 85 | | |
| 84 | 86 | | void decrement_score(Difficulty diff) { |
| 85 | 87 | | if (diff == Easy) { |
| 86 | | − | printf("Wrong Answer!! The score will be decremented by 10\n"); |
| 88 | + | printf(COLOR_BOLD COLOR_RED "Wrong Answer!!" COLOR_OFF |
| 89 | + | "The score will be decremented by 10\n"); |
| 87 | 90 | | score -= EASY_SCORE_DECREMENT; |
| 88 | 91 | | } else if (diff == Medium) { |
| 89 | 92 | | printf("Wrong Answer!! The score will be decremented by 20\n"); |
| @@ -97,12 +100,12 @@ void decrement_score(Difficulty diff) { |
| 97 | 100 | | Difficulty get_difficulty() { |
| 98 | 101 | | int choice; |
| 99 | 102 | | Difficulty difficulty; |
| 100 | | − | printf(COLOR_CYAN " CHOOSE DIFFICULTY\n" COLOR_OFF); |
| 101 | | − | printf(COLOR_RED BAR COLOR_OFF); |
| 102 | | − | printf("1. Easy\n"); |
| 103 | | − | printf("2. Medium\n"); |
| 104 | | − | printf("3. Hard\n"); |
| 105 | | − | printf(BAR); |
| 103 | + | printf(COLOR_BOLD COLOR_RED " CHOOSE DIFFICULTY\n"); |
| 104 | + | printf(COLOR_GREEN BAR COLOR_OFF); |
| 105 | + | printf(COLOR_BOLD "[1]" COLOR_OFF " Easy\n"); |
| 106 | + | printf(COLOR_BOLD "[2]" COLOR_OFF " Medium\n"); |
| 107 | + | printf(COLOR_BOLD "[3]" COLOR_OFF " Hard\n" COLOR_OFF); |
| 108 | + | printf(COLOR_GREEN BAR COLOR_OFF); |
| 106 | 109 | | printf("Enter difficulty: "); |
| 107 | 110 | | scanf("%d", &choice); |
| 108 | 111 | | switch (choice) { |
| @@ -121,13 +124,15 @@ Difficulty get_difficulty() { |
| 121 | 124 | | |
| 122 | 125 | | void level_up() { |
| 123 | 126 | | if (level == 10) { |
| 127 | + | printf(COLOR_YELLOW); |
| 124 | 128 | | print_ascii("./assets/winner.txt"); |
| 129 | + | printf(COLOR_OFF); |
| 125 | 130 | | printf("Congratulations!! You WON the game"); |
| 126 | 131 | | exit(1); |
| 127 | 132 | | } |
| 128 | 133 | | level++; |
| 129 | 134 | | size += 3; |
| 130 | | − | printf(COLOR_BOLD COLOR_RED |
| 135 | + | printf(COLOR_BOLD COLOR_GREEN BAR |
| 131 | 136 | | "You have been leveled up to Level %d\n" COLOR_OFF, |
| 132 | 137 | | level); |
| 133 | 138 | | } |