aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 4e6d57a355814827fecad6e2fea51b36ed384263 (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
#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;

void decrement_score(enum Difficulty diff);
enum Difficulty get_difficulty();

int main(int argc, char *argv[]) {
  // Get a random number to run a random algorithm
  int guess;
  srand(time(0));
  int random_number = (rand() % (UPPER - LOWER + 1)) + LOWER;

  printf(COLOR_RED);
  print_ascii("./assets/banner.txt");
  int size;
  enum Difficulty diff = get_difficulty();
  switch (diff) {
  case Easy:
    size = 5;
    break;
  case Medium:
    size = 10;
    break;
  case Hard:
    size = 23;
    break;
  }

  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;
  } else {
    decrement_score(diff);
  }
  printf("Score: %d\n", score);
  return 0;
}

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;
}