aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkrolyxon <krolyxon@tutanota.com>2023-09-01 11:22:33 +0530
committerkrolyxon <krolyxon@tutanota.com>2023-09-01 11:22:33 +0530
commitf8fc421e0b0d988e3c85c3a7e4b33a532f3c2827 (patch)
tree7fd46e648e9d0554c2432df64de5b2335d115638 /src
parentc6e829d33744f9896c913c35316199165f847f8e (diff)
beautification
Diffstat (limited to 'src')
-rw-r--r--src/main.c39
-rw-r--r--src/utils.c16
-rw-r--r--src/utils.h1
3 files changed, 38 insertions, 18 deletions
diff --git a/src/main.c b/src/main.c
index 542b6b3..c177290 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,6 +4,7 @@
#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;
@@ -21,6 +22,7 @@ int score = 100;
int level = 1;
int size = 5;
+// Declaring Functions
void decrement_score(Difficulty diff);
void level_up();
void level_down();
@@ -33,13 +35,14 @@ int main(int argc, char *argv[]) {
srand(time(0));
int guess;
- printf(COLOR_RED);
+ clearscreen();
+ printf(COLOR_CYAN);
print_ascii("./assets/banner.txt");
Difficulty diff = get_difficulty();
while (level > 0 && level <= 10) {
int random_number = getrand();
- printf(BAR);
+ printf(COLOR_GREEN BAR COLOR_OFF);
switch (random_number) {
case 1:
getarr(size);
@@ -58,22 +61,21 @@ int main(int argc, char *argv[]) {
break;
}
- printf(BAR);
- printf("1. BubbleSort\n");
- printf("2. InsertionSort\n");
- printf("3. SelectionSort\n");
- printf("4. RadixSort\n");
- printf("%d", random_number);
+ 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) {
- printf("Congratulations!!! Your answer was right!!\n");
score += 10;
level_up();
} else {
decrement_score(diff);
level_down();
}
+
printf("Score: %d\n", score);
}
return 0;
@@ -83,7 +85,8 @@ int getrand() { return (rand() % (UPPER - LOWER + 1)) + LOWER; }
void decrement_score(Difficulty diff) {
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;
} else if (diff == Medium) {
printf("Wrong Answer!! The score will be decremented by 20\n");
@@ -97,12 +100,12 @@ void decrement_score(Difficulty diff) {
Difficulty get_difficulty() {
int choice;
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(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) {
@@ -121,13 +124,15 @@ Difficulty get_difficulty() {
void level_up() {
if (level == 10) {
+ printf(COLOR_YELLOW);
print_ascii("./assets/winner.txt");
+ printf(COLOR_OFF);
printf("Congratulations!! You WON the game");
exit(1);
}
level++;
size += 3;
- printf(COLOR_BOLD COLOR_RED
+ printf(COLOR_BOLD COLOR_GREEN BAR
"You have been leveled up to Level %d\n" COLOR_OFF,
level);
}
diff --git a/src/utils.c b/src/utils.c
index 390aa7c..37b50bf 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,9 +1,10 @@
#include "utils.h"
#include <stdio.h>
+#include <stdlib.h>
void printarr(int a[], int n) {
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[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
+}
+
diff --git a/src/utils.h b/src/utils.h
index a667b73..20473ef 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -17,3 +17,4 @@
void printarr(int a[], int n);
void print_ascii(char *filename);
void swap(int a[], int i, int j);
+void clearscreen();