aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: d15756c8eec2cd119f2e716ff2443a95f5ead415 (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "sort.h"
#include "utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// https://texteditor.com/multiline-text-art/

const char BANNER[][300] = {
    "    ╔════╗ ╔═══╗ ╔═══╗ ╔═══╗", "    ║╔╗╔╗║ ║╔═╗║ ║╔═╗║ ║╔═╗║",
    "    ╚╝║║╚╝ ║╚═╝║ ║║ ║║ ║╚══╗", "      ║║   ║╔╗╔╝ ║║ ║║ ╚══╗║",
    "     ╔╝╚╗  ║║║╚╗ ║╚═╝║ ║╚═╝║", "     ╚══╝  ╚╝╚═╝ ╚═══╝ ╚═══╝",
};

const char WINNER[][300] = {
    "──────────────────────────────────────────",
    "   ╔╗╔╗╔╗╔══╗╔═╗ ╔╗╔═╗ ╔╗╔═══╗╔═══╗╔╗╔╗",
    "   ║║║║║║╚╣╠╝║║╚╗║║║║╚╗║║║╔══╝║╔═╗║║║║║",
    "   ║║║║║║ ║║ ║╔╗╚╝║║╔╗╚╝║║╚══╗║╚═╝║║║║║",
    "   ║╚╝╚╝║ ║║ ║║╚╗║║║║╚╗║║║╔══╝║╔╗╔╝╚╝╚╝",
    "   ╚╗╔╗╔╝╔╣╠╗║║ ║║║║║ ║║║║╚══╗║║║╚╗╔╗╔╗",
    "    ╚╝╚╝ ╚══╝╚╝ ╚═╝╚╝ ╚═╝╚═══╝╚╝╚═╝╚╝╚╝",
    "──────────────────────────────────────────",
};

static const int EASY_SCORE_DECREMENT = 10;
static const int MEDIUM_SCORE_DECREMENT = 20;
static const int LOWER = 1;
static const int UPPER = 4;
typedef enum {
  Easy,
  Medium,
  Hard,
} Difficulty;

int list[35];

static int score = 0;
static int level = 1;
static int size = 5;

// Declaring Functions
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;

  clearscreen();
  printf(COLOR_CYAN BAR);
  for (int i = 0; i < 6; i++) {
    printf("%s\n", BANNER[i]);
  }
  Difficulty diff = get_difficulty();

  while (level > 0 && level <= 10) {
    int random_number = getrand();
    printf(COLOR_GREEN BAR COLOR_OFF);
    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:
      getarr(size);
      radixsort(list, size);
      break;
    default:
      break;
    }

    printf(COLOR_GREEN BAR COLOR_OFF);
    printf(COLOR_BOLD "[1] " COLOR_OFF "Bubble Sort\n");
    printf(COLOR_BOLD "[2] " COLOR_OFF "Insertion Sort\n");
    printf(COLOR_BOLD "[3] " COLOR_OFF "Selection Sort\n");
    printf(COLOR_BOLD "[4] " COLOR_OFF "Radix Sort\n");
    printf("Enter your guess: ");
    scanf("%d", &guess);
    if (guess == random_number) {
      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(COLOR_BOLD COLOR_RED "Wrong Answer!!" COLOR_OFF
                                "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(COLOR_RED COLOR_BOLD "Wrong Answer!! You Lose!!\n" COLOR_OFF);
    exit(1);
  }
}

Difficulty get_difficulty() {
  int choice;
  Difficulty difficulty;
  printf(COLOR_GREEN BAR COLOR_OFF);
  printf(COLOR_BOLD COLOR_RED "       CHOOSE DIFFICULTY\n");
  printf(COLOR_GREEN BAR COLOR_OFF);
  printf(COLOR_BOLD "[1]" COLOR_OFF " Easy\n");
  printf(COLOR_BOLD "[2]" COLOR_OFF " Medium\n");
  printf(COLOR_BOLD "[3]" COLOR_OFF " Hard\n" COLOR_OFF);
  printf(COLOR_GREEN BAR COLOR_OFF);
  printf("Enter difficulty: ");
  scanf("%d", &choice);
  switch (choice) {
  case 1:
    difficulty = Easy;
    break;
  case 2:
    difficulty = Medium;
    break;
  case 3:
    difficulty = Hard;
    break;
  default:
    printf(COLOR_RED "Invalid Choice. Defaulting to Medium\n" COLOR_OFF);
    difficulty = Medium;
    break;
  }
  return difficulty;
}

void level_up() {
  if (level == 10) {
    printf(COLOR_YELLOW);
    for (int i = 0; i < 8; i++) {
      printf("%s\n", WINNER[i]);
    }
    printf(COLOR_OFF);
    printf("Congratulations!! You WON the game");
    exit(1);
  }
  level++;
  size += 3;
  printf(COLOR_BOLD COLOR_GREEN BAR
         "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!! " COLOR_RED COLOR_BOLD
           "You Lose!!\n" COLOR_OFF);
    exit(1);
  }
}

void getarr(int size) {
  for (int i = 0; i < size; i++) {
    list[i] = rand() % 100;
  }
}