beautification
This commit is contained in:
parent
c6e829d337
commit
f8fc421e0b
17
README.md
17
README.md
|
|
@ -1,11 +1,13 @@
|
||||||
## WIP WIP WIP
|
## WIP WIP WIP
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [] Implement Score system
|
- [] Algorithms to be implemented:
|
||||||
Difficulties: Easy, Medium, Hard\
|
- [x] Bubblesort
|
||||||
Easy = +10, -10\
|
- [x] SelectionSort
|
||||||
Medium = +10, -20\
|
- [x] InsertionSort
|
||||||
Hard = +10, score = 0
|
- [] Radix Sort
|
||||||
|
- [x] Implement Score system
|
||||||
|
- [] Code Refactoring/Cleaning
|
||||||
|
|
||||||
## Levels:
|
## Levels:
|
||||||
1: 5 elems\
|
1: 5 elems\
|
||||||
|
|
@ -20,9 +22,4 @@ Hard = +10, score = 0
|
||||||
10: 30 elems\
|
10: 30 elems\
|
||||||
|
|
||||||
|
|
||||||
# Algorithms to be implemented:
|
|
||||||
- [x] Bubblesort
|
|
||||||
- [x] SelectionSort
|
|
||||||
- [x] InsertionSort
|
|
||||||
- [] Radix Sort
|
|
||||||
|
|
||||||
|
|
|
||||||
39
src/main.c
39
src/main.c
|
|
@ -4,6 +4,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
// https://texteditor.com/multiline-text-art/
|
// https://texteditor.com/multiline-text-art/
|
||||||
|
|
||||||
const int EASY_SCORE_DECREMENT = 10;
|
const int EASY_SCORE_DECREMENT = 10;
|
||||||
const int MEDIUM_SCORE_DECREMENT = 20;
|
const int MEDIUM_SCORE_DECREMENT = 20;
|
||||||
const int LOWER = 1;
|
const int LOWER = 1;
|
||||||
|
|
@ -21,6 +22,7 @@ int score = 100;
|
||||||
int level = 1;
|
int level = 1;
|
||||||
int size = 5;
|
int size = 5;
|
||||||
|
|
||||||
|
// Declaring Functions
|
||||||
void decrement_score(Difficulty diff);
|
void decrement_score(Difficulty diff);
|
||||||
void level_up();
|
void level_up();
|
||||||
void level_down();
|
void level_down();
|
||||||
|
|
@ -33,13 +35,14 @@ int main(int argc, char *argv[]) {
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
int guess;
|
int guess;
|
||||||
|
|
||||||
printf(COLOR_RED);
|
clearscreen();
|
||||||
|
printf(COLOR_CYAN);
|
||||||
print_ascii("./assets/banner.txt");
|
print_ascii("./assets/banner.txt");
|
||||||
Difficulty diff = get_difficulty();
|
Difficulty diff = get_difficulty();
|
||||||
|
|
||||||
while (level > 0 && level <= 10) {
|
while (level > 0 && level <= 10) {
|
||||||
int random_number = getrand();
|
int random_number = getrand();
|
||||||
printf(BAR);
|
printf(COLOR_GREEN BAR COLOR_OFF);
|
||||||
switch (random_number) {
|
switch (random_number) {
|
||||||
case 1:
|
case 1:
|
||||||
getarr(size);
|
getarr(size);
|
||||||
|
|
@ -58,22 +61,21 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(BAR);
|
printf(COLOR_GREEN BAR COLOR_OFF);
|
||||||
printf("1. BubbleSort\n");
|
printf(COLOR_BOLD "[1] " COLOR_OFF "Bubble Sort\n");
|
||||||
printf("2. InsertionSort\n");
|
printf(COLOR_BOLD "[2] " COLOR_OFF "Insertion Sort\n");
|
||||||
printf("3. SelectionSort\n");
|
printf(COLOR_BOLD "[3] " COLOR_OFF "Selection Sort\n");
|
||||||
printf("4. RadixSort\n");
|
printf(COLOR_BOLD "[4] " COLOR_OFF "Radix Sort\n");
|
||||||
printf("%d", random_number);
|
|
||||||
printf("Enter your guess: ");
|
printf("Enter your guess: ");
|
||||||
scanf("%d", &guess);
|
scanf("%d", &guess);
|
||||||
if (guess == random_number) {
|
if (guess == random_number) {
|
||||||
printf("Congratulations!!! Your answer was right!!\n");
|
|
||||||
score += 10;
|
score += 10;
|
||||||
level_up();
|
level_up();
|
||||||
} else {
|
} else {
|
||||||
decrement_score(diff);
|
decrement_score(diff);
|
||||||
level_down();
|
level_down();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Score: %d\n", score);
|
printf("Score: %d\n", score);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -83,7 +85,8 @@ int getrand() { return (rand() % (UPPER - LOWER + 1)) + LOWER; }
|
||||||
|
|
||||||
void decrement_score(Difficulty diff) {
|
void decrement_score(Difficulty diff) {
|
||||||
if (diff == Easy) {
|
if (diff == Easy) {
|
||||||
printf("Wrong Answer!! The score will be decremented by 10\n");
|
printf(COLOR_BOLD COLOR_RED "Wrong Answer!!" COLOR_OFF
|
||||||
|
"The score will be decremented by 10\n");
|
||||||
score -= EASY_SCORE_DECREMENT;
|
score -= EASY_SCORE_DECREMENT;
|
||||||
} else if (diff == Medium) {
|
} else if (diff == Medium) {
|
||||||
printf("Wrong Answer!! The score will be decremented by 20\n");
|
printf("Wrong Answer!! The score will be decremented by 20\n");
|
||||||
|
|
@ -97,12 +100,12 @@ void decrement_score(Difficulty diff) {
|
||||||
Difficulty get_difficulty() {
|
Difficulty get_difficulty() {
|
||||||
int choice;
|
int choice;
|
||||||
Difficulty difficulty;
|
Difficulty difficulty;
|
||||||
printf(COLOR_CYAN " CHOOSE DIFFICULTY\n" COLOR_OFF);
|
printf(COLOR_BOLD COLOR_RED " CHOOSE DIFFICULTY\n");
|
||||||
printf(COLOR_RED BAR COLOR_OFF);
|
printf(COLOR_GREEN BAR COLOR_OFF);
|
||||||
printf("1. Easy\n");
|
printf(COLOR_BOLD "[1]" COLOR_OFF " Easy\n");
|
||||||
printf("2. Medium\n");
|
printf(COLOR_BOLD "[2]" COLOR_OFF " Medium\n");
|
||||||
printf("3. Hard\n");
|
printf(COLOR_BOLD "[3]" COLOR_OFF " Hard\n" COLOR_OFF);
|
||||||
printf(BAR);
|
printf(COLOR_GREEN BAR COLOR_OFF);
|
||||||
printf("Enter difficulty: ");
|
printf("Enter difficulty: ");
|
||||||
scanf("%d", &choice);
|
scanf("%d", &choice);
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
|
|
@ -121,13 +124,15 @@ Difficulty get_difficulty() {
|
||||||
|
|
||||||
void level_up() {
|
void level_up() {
|
||||||
if (level == 10) {
|
if (level == 10) {
|
||||||
|
printf(COLOR_YELLOW);
|
||||||
print_ascii("./assets/winner.txt");
|
print_ascii("./assets/winner.txt");
|
||||||
|
printf(COLOR_OFF);
|
||||||
printf("Congratulations!! You WON the game");
|
printf("Congratulations!! You WON the game");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
level++;
|
level++;
|
||||||
size += 3;
|
size += 3;
|
||||||
printf(COLOR_BOLD COLOR_RED
|
printf(COLOR_BOLD COLOR_GREEN BAR
|
||||||
"You have been leveled up to Level %d\n" COLOR_OFF,
|
"You have been leveled up to Level %d\n" COLOR_OFF,
|
||||||
level);
|
level);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
src/utils.c
16
src/utils.c
|
|
@ -1,9 +1,10 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void printarr(int a[], int n) {
|
void printarr(int a[], int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
printf("%d ", a[i]);
|
printf(COLOR_BOLD "%d " COLOR_OFF, a[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,3 +25,16 @@ void swap(int a[], int i, int j) {
|
||||||
a[i] = a[j];
|
a[i] = a[j];
|
||||||
a[j] = tmp;
|
a[j] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void clearscreen(void) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
system("cls");
|
||||||
|
#elif defined(unix) || defined(__unix__) || defined(__unix) || \
|
||||||
|
(defined(__APPLE__) && defined(__MACH__))
|
||||||
|
system("clear");
|
||||||
|
#else
|
||||||
|
#error "OS not supported."
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,3 +17,4 @@
|
||||||
void printarr(int a[], int n);
|
void printarr(int a[], int n);
|
||||||
void print_ascii(char *filename);
|
void print_ascii(char *filename);
|
||||||
void swap(int a[], int i, int j);
|
void swap(int a[], int i, int j);
|
||||||
|
void clearscreen();
|
||||||
|
|
|
||||||
Reference in New Issue