Krolyxon
Commit 52087d0

Branches

Refs →

tros52087d0

remove print_ascii()

Author
krolyxon
Date
2023-09-17 11:47 +0530
Committer
krolyxon · 2023-09-17 11:48 +0530
Parent
3830e03
Commit
52087d0d717f7fb0e9cbae16584cb4bece38a161

+28 −34

5 files changed

  1. D assets/banner.txt +0 −8
  2. D assets/winner.txt +0 −8
  3. M src/main.c +28 −6
  4. M src/utils.c +0 −11
  5. M src/utils.h +0 −1
D assets/banner.txt View
@@ -1,8 +0,0 @@
1−────────────────────────────────
2− ╔════╗ ╔═══╗ ╔═══╗ ╔═══╗
3− ║╔╗╔╗║ ║╔═╗║ ║╔═╗║ ║╔═╗║
4− ╚╝║║╚╝ ║╚═╝║ ║║ ║║ ║╚══╗
5− ║║ ║╔╗╔╝ ║║ ║║ ╚══╗║
6− ╔╝╚╗ ║║║╚╗ ║╚═╝║ ║╚═╝║
7− ╚══╝ ╚╝╚═╝ ╚═══╝ ╚═══╝
8−────────────────────────────────
D assets/winner.txt View
@@ -1,8 +0,0 @@
1−──────────────────────────────────────────
2− ╔╗╔╗╔╗╔══╗╔═╗ ╔╗╔═╗ ╔╗╔═══╗╔═══╗╔╗╔╗
3− ║║║║║║╚╣╠╝║║╚╗║║║║╚╗║║║╔══╝║╔═╗║║║║║
4− ║║║║║║ ║║ ║╔╗╚╝║║╔╗╚╝║║╚══╗║╚═╝║║║║║
5− ║╚╝╚╝║ ║║ ║║╚╗║║║║╚╗║║║╔══╝║╔╗╔╝╚╝╚╝
6− ╚╗╔╗╔╝╔╣╠╗║║ ║║║║║ ║║║║╚══╗║║║╚╗╔╗╔╗
7− ╚╝╚╝ ╚══╝╚╝ ╚═╝╚╝ ╚═╝╚═══╝╚╝╚═╝╚╝╚╝
8−──────────────────────────────────────────
M src/main.c View
@@ -5,11 +5,27 @@
55 #include <time.h>
66 // https://texteditor.com/multiline-text-art/
77
8+const char BANNER[][300] = {
9+ " ╔════╗ ╔═══╗ ╔═══╗ ╔═══╗", " ║╔╗╔╗║ ║╔═╗║ ║╔═╗║ ║╔═╗║",
10+ " ╚╝║║╚╝ ║╚═╝║ ║║ ║║ ║╚══╗", " ║║ ║╔╗╔╝ ║║ ║║ ╚══╗║",
11+ " ╔╝╚╗ ║║║╚╗ ║╚═╝║ ║╚═╝║", " ╚══╝ ╚╝╚═╝ ╚═══╝ ╚═══╝",
12+};
13+
14+const char WINNER[][300] = {
15+ "──────────────────────────────────────────",
16+ " ╔╗╔╗╔╗╔══╗╔═╗ ╔╗╔═╗ ╔╗╔═══╗╔═══╗╔╗╔╗",
17+ " ║║║║║║╚╣╠╝║║╚╗║║║║╚╗║║║╔══╝║╔═╗║║║║║",
18+ " ║║║║║║ ║║ ║╔╗╚╝║║╔╗╚╝║║╚══╗║╚═╝║║║║║",
19+ " ║╚╝╚╝║ ║║ ║║╚╗║║║║╚╗║║║╔══╝║╔╗╔╝╚╝╚╝",
20+ " ╚╗╔╗╔╝╔╣╠╗║║ ║║║║║ ║║║║╚══╗║║║╚╗╔╗╔╗",
21+ " ╚╝╚╝ ╚══╝╚╝ ╚═╝╚╝ ╚═╝╚═══╝╚╝╚═╝╚╝╚╝",
22+ "──────────────────────────────────────────",
23+};
24+
825 static const int EASY_SCORE_DECREMENT = 10;
926 static const int MEDIUM_SCORE_DECREMENT = 20;
1027 static const int LOWER = 1;
1128 static const int UPPER = 4;
12−
1329 typedef enum {
1430 Easy,
1531 Medium,
@@ -36,8 +52,10 @@ int main(int argc, char *argv[]) {
3652 int guess;
3753
3854 clearscreen();
39− printf(COLOR_CYAN);
40− print_ascii("./assets/banner.txt");
55+ printf(COLOR_CYAN BAR);
56+ for (int i = 0; i < 6; i++) {
57+ printf("%s\n", BANNER[i]);
58+ }
4159 Difficulty diff = get_difficulty();
4260
4361 while (level > 0 && level <= 10) {
@@ -103,6 +121,7 @@ void decrement_score(Difficulty diff) {
103121 Difficulty get_difficulty() {
104122 int choice;
105123 Difficulty difficulty;
124+ printf(COLOR_GREEN BAR COLOR_OFF);
106125 printf(COLOR_BOLD COLOR_RED " CHOOSE DIFFICULTY\n");
107126 printf(COLOR_GREEN BAR COLOR_OFF);
108127 printf(COLOR_BOLD "[1]" COLOR_OFF " Easy\n");
@@ -121,7 +140,7 @@ Difficulty get_difficulty() {
121140 case 3:
122141 difficulty = Hard;
123142 break;
124− default:
143+ default:
125144 printf(COLOR_RED "Invalid Choice. Defaulting to Medium\n" COLOR_OFF);
126145 difficulty = Medium;
127146 break;
@@ -132,7 +151,9 @@ Difficulty get_difficulty() {
132151 void level_up() {
133152 if (level == 10) {
134153 printf(COLOR_YELLOW);
135− print_ascii("./assets/winner.txt");
154+ for (int i = 0; i < 8; i++) {
155+ printf("%s\n", WINNER[i]);
156+ }
136157 printf(COLOR_OFF);
137158 printf("Congratulations!! You WON the game");
138159 exit(1);
@@ -149,7 +170,8 @@ void level_down() {
149170 level--;
150171 size -= 3;
151172 } else {
152− printf("Too many wrong answers!! " COLOR_RED COLOR_BOLD "You Lose!!\n" COLOR_OFF);
173+ printf("Too many wrong answers!! " COLOR_RED COLOR_BOLD
174+ "You Lose!!\n" COLOR_OFF);
153175 exit(1);
154176 }
155177 }
M src/utils.c View
@@ -8,17 +8,6 @@ void printarr(int a[], int n) {
88 }
99 }
1010
11−void print_ascii(char *filename) {
12− char read_string[MAX_LEN];
13− FILE *fptr = NULL;
14− if ((fptr = fopen(filename, "r")) == NULL) {
15− fprintf(stderr, "error opening %s\n", filename);
16− }
17− while (fgets(read_string, sizeof(read_string), fptr) != NULL) {
18− printf("%s", read_string);
19− }
20− fclose(fptr);
21−}
2211
2312 void swap(int a[], int i, int j) {
2413 int tmp = a[i];
M src/utils.h View
@@ -15,6 +15,5 @@
1515 #define COLOR_OFF "\e[m"
1616
1717 void printarr(int a[], int n);
18−void print_ascii(char *filename);
1918 void swap(int a[], int i, int j);
2019 void clearscreen();