|
| 1 | +#include <stdio.h> |
| 2 | +#include <string.h> |
| 3 | +#include <stdlib.h> |
| 4 | +#include <unistd.h> |
| 5 | + |
| 6 | +char ascii_art[] = |
| 7 | + |
| 8 | +"\e[0;33m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣤⣤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 9 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠸⠿⠿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 10 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⣿⡟⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 11 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⣿⣷⠿⠃⢠⣤⣴⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 12 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⣿⣏⣤⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 13 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡈⠉⠁⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 14 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢺⣿⣯⠆⠀⣠⣶⠿⣛⠛⠳⣦⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 15 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣙⣤⣤⣼⡏⠹⠛⠋⢁⣠⣿⠋⠉⠛⠳⣦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 16 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣴⡶⠾⣿⠟⢉⣭⡿⠛⠁⠀⠀⢰⠟⠉⠀⠀⠀⠀⠀⠀⠙⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 17 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⡾⠟⠛⠉⠀⠀⠀⣿⣾⠟⠁⠀⠀⠀⠀⠀⠘⣷⡀⠀⠀⠀⠀⠀⠀⠀⠈⢿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 18 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⠟⠋⣿⠀⠀⠀⠀⠀⠀⢰⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠘⣷⡀⠀⠀⠀⠀⠀⠀⠀⠘⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 19 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠋⠁⠀⠀⣿⠀⠀⠀⠀⠀⠀⣿⣧⣿⠀⠀⢰⡷⠀⠀⠀⠀⢠⡟⠃⠀⠀⠀⠀⠀⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 20 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡾⠋⠀⠀⠀⠀⠀⣿⡟⠀⠀⠀⠀⠀⢿⡏⠛⢀⠀⠙⠃⠀⠀⠀⢠⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 21 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⡟⠀⠀⠀⠀⢰⣄⠀⠀⣰⡄⠀⠀⠀⠀⠘⢿⣄⢻⣖⡀⠀⠀⠀⠀⢸⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⡟⠨⠻⣦⣀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 22 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠈⠙⠛⠷⢾⣧⣀⠀⠀⠀⠀⢠⣿⣧⣉⢷⠀⠀⠀⠀⢸⡆⠀⠀⠀⠀⠀⠀⠀⠀⣴⡟⠛⠛⠀⠈⠻⣦⠀⠀⠀⠀⠀⠀⠀\n" |
| 23 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣙⣻⣦⣴⠶⣿⡛⢻⡙⠻⢧⣄⣀⠀⠈⢿⣄⠀⠀⠀⠀⢀⣴⡾⠋⠀⠀⠀⠀⠀⠀⢹⣇⠀⠀⠀⠀⠀⠀\n" |
| 24 | +"⠀⠀⠀⠀⠀⠀⢀⣤⡾⠋⠉⠻⣦⣀⠀⠀⠀⠀⢀⣤⣶⣿⠛⠉⠁⠀⠀⠈⣿⡈⣿⠀⠀⠉⠙⠛⠶⠶⣽⣷⣤⣶⠞⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⣾⠻⣦⡄⠀⠀⠀⠀\n" |
| 25 | +"⠀⠀⠀⢀⣴⡾⠋⠁⠀⠀⠀⠀⠈⠙⠳⢶⣤⣄⣿⡵⣟⣿⢷⡄⠀⠀⠀⠀⣿⠇⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⡾⠏⠀⠈⠻⣦⡀⠀⠀\n" |
| 26 | +"⢀⣤⣾⣛⣁⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢻⣵⣯⣾⢋⣁⣤⣴⠶⠾⠛⠶⠾⠷⢶⣦⣤⣤⣤⣤⣤⣤⡤⠶⠶⠶⠶⠶⠿⠿⠛⠋⠉⠉⠀⠀⠀⠀⠀⠈⠻⣦⡀\n" |
| 27 | +"⠀⠉⠙⠛⣿⡛⠛⠛⠛⠳⠶⠶⠶⠶⠦⠤⢤⣤⣤⣤⣤⣽⣯⣥⣠⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣄⣤⣤⣤⡤⠤⠴⢶⡾⠟⠛⠃\n" |
| 28 | +"⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⣾⠃⠀⠀⠀\n" |
| 29 | +"⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡏⠀⠀⠀⠀\n" |
| 30 | +"⠀⠀⠀⠀⠀⠈⠿⠿⠿⠿⣿⠿⠿⠿⢿⡶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⠶⢶⣶⠶⢶⠶⣶⣶⣶⣶⣶⡿⠁⠀⠀⠀⠀\n" |
| 31 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡇⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 32 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣧⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⢸⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 33 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 34 | +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠓⠚⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠚⠓⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" |
| 35 | +" class was so boring, you fell fast asleep... \n" |
| 36 | +" tell me about your dreams?... \n\e[0m"; |
| 37 | + |
| 38 | +char* notes[10]; |
| 39 | +int note_ctr = 0; |
| 40 | + |
| 41 | +void take_note() { |
| 42 | + size_t size; |
| 43 | + |
| 44 | + if (note_ctr < 10) { |
| 45 | + printf("note size: "); |
| 46 | + scanf("%zu", &size); |
| 47 | + getchar(); |
| 48 | + |
| 49 | + if (size > 0x100) { |
| 50 | + puts("your notebook is not that big!"); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + notes[note_ctr] = malloc(size); |
| 55 | + printf("note content: "); |
| 56 | + size_t sz = read(STDIN_FILENO, notes[note_ctr], size); |
| 57 | + if (notes[note_ctr][sz-1] == '\n') { |
| 58 | + notes[note_ctr][sz-1] = 0; |
| 59 | + } |
| 60 | + printf("you took down note #%d into your notebook!\n", note_ctr); |
| 61 | + note_ctr++; |
| 62 | + } else { |
| 63 | + puts("your notebook ran out of space"); |
| 64 | + return; |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +void erase_note() { |
| 69 | + unsigned int idx; |
| 70 | + printf("note index to remove: "); |
| 71 | + scanf("%u", &idx); |
| 72 | + getchar(); |
| 73 | + |
| 74 | + if (idx < 10 && notes[idx]) { |
| 75 | + free(notes[idx]); |
| 76 | + notes[idx] = 0; |
| 77 | + printf("note #%u is removed\n", idx); |
| 78 | + } else { |
| 79 | + puts("that note does not exist!"); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +void read_note() { |
| 84 | + unsigned int idx; |
| 85 | + printf("note index to read: "); |
| 86 | + scanf("%u", &idx); |
| 87 | + getchar(); |
| 88 | + |
| 89 | + if (idx < 10 && notes[idx]) { |
| 90 | + printf("note #%u: %s\n", idx, notes[idx]); |
| 91 | + } else { |
| 92 | + puts("that note does not exist!"); |
| 93 | + } |
| 94 | + |
| 95 | +} |
| 96 | + |
| 97 | +void class() { |
| 98 | + |
| 99 | + int opt; |
| 100 | + int done = 1; |
| 101 | + |
| 102 | + while(done) { |
| 103 | + puts("\n1) take down a note"); |
| 104 | + puts("2) erase a note"); |
| 105 | + puts("3) read a note"); |
| 106 | + puts("4) go back"); |
| 107 | + printf("> "); |
| 108 | + scanf("%d", &opt); |
| 109 | + getchar(); |
| 110 | + |
| 111 | + switch(opt) { |
| 112 | + case 1: |
| 113 | + take_note(); |
| 114 | + break; |
| 115 | + case 2: |
| 116 | + erase_note(); |
| 117 | + break; |
| 118 | + case 3: |
| 119 | + read_note(); |
| 120 | + break; |
| 121 | + case 4: |
| 122 | + done = 0; |
| 123 | + break; |
| 124 | + default: |
| 125 | + break; |
| 126 | + } |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +typedef void func(); |
| 131 | +func** dreams; |
| 132 | +size_t num_dreams; |
| 133 | +size_t dream_i; |
| 134 | + |
| 135 | +void dream_about_kdrama_guys() { |
| 136 | + puts("oooooooooooooooooooooooooo, cute kdrama guy......."); |
| 137 | +} |
| 138 | + |
| 139 | +void dream_about_flag_real() { |
| 140 | + char flag[100] = {0}; |
| 141 | + FILE *f = fopen("flag.txt", "r"); |
| 142 | + fread(flag, 100, sizeof(char), f); |
| 143 | + fclose(f); |
| 144 | + printf("and the flag is.............. %s............\n", flag); |
| 145 | +} |
| 146 | + |
| 147 | +void dream_about_flag_fake() { |
| 148 | + printf("and the flag is.............. i forgot............\n"); |
| 149 | +} |
| 150 | + |
| 151 | +void dream_about_valorant() { |
| 152 | + puts("THWACK! THWACK! THWACK! THWACK! THWACK! ACE!......"); |
| 153 | +} |
| 154 | + |
| 155 | +void dream_about_school() { |
| 156 | + puts("and the best STUDENT award goes to..........."); |
| 157 | +} |
| 158 | + |
| 159 | +func* pick_a_dream() { |
| 160 | + int opt; |
| 161 | + |
| 162 | + while (1) { |
| 163 | + puts("\n1) dream about valorant"); |
| 164 | + puts("2) dream about kdrama guys"); |
| 165 | + puts("3) dream about school"); |
| 166 | + puts("4) dream about flag"); |
| 167 | + printf("> "); |
| 168 | + scanf("%d", &opt); |
| 169 | + getchar(); |
| 170 | + |
| 171 | + switch(opt) { |
| 172 | + case 1: |
| 173 | + return (func*)&dream_about_valorant; |
| 174 | + case 2: |
| 175 | + return (func*)&dream_about_kdrama_guys; |
| 176 | + case 3: |
| 177 | + return (func*)&dream_about_school; |
| 178 | + case 4: |
| 179 | + return (func*)&dream_about_flag_fake; |
| 180 | + default: |
| 181 | + break; |
| 182 | + } |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +void add_dream() { |
| 187 | + if (dreams == NULL) { |
| 188 | + puts("you currently have no dreams planned."); |
| 189 | + printf("how many dreams are you planning to have? "); |
| 190 | + scanf("%zu", &num_dreams); |
| 191 | + if (num_dreams > 100) { |
| 192 | + puts("that's too many dreams to have in a single nap!"); |
| 193 | + num_dreams = 0; |
| 194 | + return; |
| 195 | + } |
| 196 | + dreams = malloc(sizeof(func*) * num_dreams); |
| 197 | + } |
| 198 | + |
| 199 | + if (dream_i < num_dreams) { |
| 200 | + dreams[dream_i] = pick_a_dream(); |
| 201 | + dream_i++; |
| 202 | + printf("you currently have %zu/%zu dreams prepared!\n", dream_i, num_dreams); |
| 203 | + } else { |
| 204 | + puts("you have already finished planning all your dreams!"); |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | +void start_dreaming() { |
| 209 | + |
| 210 | + for (size_t i = 0; i < num_dreams; i++) { |
| 211 | + if (dreams[i]) { |
| 212 | + ((func*)(dreams[i]))(); |
| 213 | + } else { |
| 214 | + break; |
| 215 | + } |
| 216 | + printf("."); |
| 217 | + printf("."); |
| 218 | + printf(".\n"); |
| 219 | + } |
| 220 | + |
| 221 | + puts("you woke up from your dream -- 'wow what a good dream!'"); |
| 222 | + num_dreams = 0; |
| 223 | + dream_i = 0; |
| 224 | + free(dreams); |
| 225 | + dreams = NULL; |
| 226 | + |
| 227 | +} |
| 228 | + |
| 229 | +void dream() { |
| 230 | + int opt; |
| 231 | + int done = 1; |
| 232 | + |
| 233 | + while(done) { |
| 234 | + puts("\n1) add a dream"); |
| 235 | + puts("2) start dreaming!"); |
| 236 | + puts("3) go back"); |
| 237 | + printf("> "); |
| 238 | + scanf("%d", &opt); |
| 239 | + getchar(); |
| 240 | + |
| 241 | + switch(opt) { |
| 242 | + case 1: |
| 243 | + add_dream(); |
| 244 | + break; |
| 245 | + case 2: |
| 246 | + start_dreaming(); |
| 247 | + break; |
| 248 | + case 3: |
| 249 | + done = 0; |
| 250 | + break; |
| 251 | + default: |
| 252 | + break; |
| 253 | + } |
| 254 | + } |
| 255 | + |
| 256 | +} |
| 257 | + |
| 258 | +void menu() { |
| 259 | + |
| 260 | + int opt; |
| 261 | + |
| 262 | + puts("\n1) listen to class"); |
| 263 | + puts("2) start dreaming"); |
| 264 | + puts("3) exit"); |
| 265 | + printf("> "); |
| 266 | + scanf("%d", &opt); |
| 267 | + getchar(); |
| 268 | + |
| 269 | + switch(opt) { |
| 270 | + case 1: |
| 271 | + class(); |
| 272 | + break; |
| 273 | + case 2: |
| 274 | + dream(); |
| 275 | + break; |
| 276 | + case 3: |
| 277 | + default: |
| 278 | + exit(0); |
| 279 | + } |
| 280 | +} |
| 281 | + |
| 282 | +int main() { |
| 283 | + |
| 284 | + setbuf(stdin, 0); |
| 285 | + setbuf(stdout, 0); |
| 286 | + printf("%s", ascii_art); |
| 287 | + while (1) { |
| 288 | + menu(); |
| 289 | + } |
| 290 | + |
| 291 | +} |
| 292 | + |
0 commit comments