diff options
| -rw-r--r-- | src/screen.c | 87 | ||||
| -rw-r--r-- | src/screen.h | 39 |
2 files changed, 73 insertions, 53 deletions
diff --git a/src/screen.c b/src/screen.c index 85bc031..db34745 100644 --- a/src/screen.c +++ b/src/screen.c | |||
| @@ -77,12 +77,6 @@ static const char *menu_choices[] = { | |||
| 77 | "Quit" | 77 | "Quit" |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | static struct funcholder userfuncs[] = { | ||
| 81 | {.callback = spin, .type = FH_SPIN}, | ||
| 82 | {.callback = buy, .type = FH_BUY}, | ||
| 83 | {.callback = quit, .type = FH_QUIT} | ||
| 84 | }; | ||
| 85 | |||
| 86 | void catcher(int signum, siginfo_t *info, void *ucontext) { | 80 | void catcher(int signum, siginfo_t *info, void *ucontext) { |
| 87 | // This is retarded lol, but makes gcc happy | 81 | // This is retarded lol, but makes gcc happy |
| 88 | info->si_code = info->si_code; | 82 | info->si_code = info->si_code; |
| @@ -221,6 +215,9 @@ static int mvwcreate_box(WINDOW *win, int y, int x, int height, int width, const | |||
| 221 | } | 215 | } |
| 222 | 216 | ||
| 223 | static int init_slotholder(struct slotholder *slots) { | 217 | static int init_slotholder(struct slotholder *slots) { |
| 218 | mvwaddstr(slots->slotwin, 0, 1, "Spins: 3, Price: 1"); | ||
| 219 | wnoutrefresh(slots->slotwin); | ||
| 220 | |||
| 224 | getmaxyx(slots->slotwin, slots->sloty, slots->slotx); | 221 | getmaxyx(slots->slotwin, slots->sloty, slots->slotx); |
| 225 | for(size_t i = 0; i < STATIC_ARRSIZE(slots->subslot); i++) { | 222 | for(size_t i = 0; i < STATIC_ARRSIZE(slots->subslot); i++) { |
| 226 | slots->subslot[i] = derwin(slots->slotwin, slots->sloty, slots->slotx/3, 0, slots->slotx/3 * i); | 223 | slots->subslot[i] = derwin(slots->slotwin, slots->sloty, slots->slotx/3, 0, slots->slotx/3 * i); |
| @@ -274,13 +271,21 @@ int main() { | |||
| 274 | 271 | ||
| 275 | // Variable definitions | 272 | // Variable definitions |
| 276 | ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items | 273 | ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items |
| 277 | struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver | 274 | struct funcholder *p = NULL; |
| 275 | struct params params; // Function pointer used for callbacks in the menu driver | ||
| 278 | WINDOW *menuholder = NULL; // The window for displaying the menu | 276 | WINDOW *menuholder = NULL; // The window for displaying the menu |
| 279 | int row = -1, col = -1; // The rows and columns of the main screen | 277 | int row = -1, col = -1; // The rows and columns of the main screen |
| 280 | uint32_t randomnum; // A random number for getting the banner phrase | 278 | uint32_t randomnum; // A random number for getting the banner phrase |
| 281 | MENU *menu; // The actual menu object | 279 | MENU *menu; // The actual menu object |
| 282 | int c; // Integer for storing keys from user input | 280 | int c; // Integer for storing keys from user input |
| 283 | 281 | ||
| 282 | struct funcholder userfuncs[] = { | ||
| 283 | {.callback = spin, .type = FH_SPIN}, | ||
| 284 | {.callback = buy, .type = FH_BUY}, | ||
| 285 | {.callback = quit, .type = FH_QUIT}, | ||
| 286 | {0} | ||
| 287 | }; | ||
| 288 | |||
| 284 | struct slotholder slots; | 289 | struct slotholder slots; |
| 285 | 290 | ||
| 286 | getmaxyx(stdscr, row, col); | 291 | getmaxyx(stdscr, row, col); |
| @@ -317,10 +322,12 @@ int main() { | |||
| 317 | 322 | ||
| 318 | doupdate(); | 323 | doupdate(); |
| 319 | 324 | ||
| 320 | userfuncs[0].params.spinp.bannerwin = banner; | 325 | params.bannerwin = banner; |
| 321 | userfuncs[0].params.spinp.menuholder = menuholder; | 326 | params.menu = menu; |
| 322 | userfuncs[0].params.spinp.menu = menu; | 327 | params.menuholder = menuholder; |
| 323 | userfuncs[0].params.spinp.slots = &slots; | 328 | params.numspins = 3; |
| 329 | params.price = 1; | ||
| 330 | params.slots = &slots; | ||
| 324 | 331 | ||
| 325 | // Get user input and deal with the menu | 332 | // Get user input and deal with the menu |
| 326 | while((c = wgetch(menuholder)) != KEY_F(4)) { | 333 | while((c = wgetch(menuholder)) != KEY_F(4)) { |
| @@ -344,16 +351,12 @@ int main() { | |||
| 344 | case KEY_ENTER: case FUCKED_UP_ENTER: // Enter | 351 | case KEY_ENTER: case FUCKED_UP_ENTER: // Enter |
| 345 | p = (struct funcholder *)item_userptr(current_item(menu)); | 352 | p = (struct funcholder *)item_userptr(current_item(menu)); |
| 346 | switch(p->type) { | 353 | switch(p->type) { |
| 347 | case FH_SPIN: | 354 | case FH_SPIN: case FH_BUY: |
| 348 | p->callback((void*)&p->params.spinp); | 355 | p->callback((void*)¶ms); |
| 349 | break; | ||
| 350 | |||
| 351 | case FH_BUY: | ||
| 352 | p->callback((void*)&p->params.buyp); | ||
| 353 | break; | 356 | break; |
| 354 | 357 | ||
| 355 | case FH_QUIT: | 358 | case FH_QUIT: |
| 356 | p->callback((void*)&p->params.quitp); | 359 | p->callback(NULL); |
| 357 | break; | 360 | break; |
| 358 | 361 | ||
| 359 | default: | 362 | default: |
| @@ -380,8 +383,21 @@ int main() { | |||
| 380 | } | 383 | } |
| 381 | 384 | ||
| 382 | // Spin the wheel | 385 | // Spin the wheel |
| 383 | int spin(void *spinp) { | 386 | int spin(void *params) { |
| 384 | struct spinp *p = (struct spinp *)spinp; | 387 | struct params *p = (struct params *)params; |
| 388 | |||
| 389 | p->numspins -= 1; | ||
| 390 | if(p->numspins < 0) { | ||
| 391 | endwin(); | ||
| 392 | error(1, 0, "[VX-GAMBLEGROUND] You ran out of spins! Game Over!"); | ||
| 393 | } | ||
| 394 | char *newstr = NULL; | ||
| 395 | if(asprintf(&newstr, "Spins: %d, Price: %d", p->numspins, p->price) < 0) { | ||
| 396 | endwin(); | ||
| 397 | error(1, errno, "[VX-GAMBLEGROUND] Shit brokey lol"); | ||
| 398 | } | ||
| 399 | mvwaddstr(p->slots->slotwin, 0, 1, newstr); | ||
| 400 | free(newstr); | ||
| 385 | 401 | ||
| 386 | static const struct timespec sleeper = { | 402 | static const struct timespec sleeper = { |
| 387 | .tv_sec = 0, | 403 | .tv_sec = 0, |
| @@ -440,22 +456,35 @@ int spin(void *spinp) { | |||
| 440 | } | 456 | } |
| 441 | 457 | ||
| 442 | // Increase number of spins | 458 | // Increase number of spins |
| 443 | int buy(void *buyp) { | 459 | int buy(void *params) { |
| 444 | struct buyp *p = (struct buyp*)buyp; | 460 | struct params *p = (struct params *)params; |
| 461 | |||
| 462 | if(p->numspins >= 100) | ||
| 463 | return 0; | ||
| 464 | |||
| 445 | p->numspins += 3; | 465 | p->numspins += 3; |
| 446 | p->price *= 2; | 466 | if(p->price <= 2000000) |
| 467 | p->price *= 2; | ||
| 447 | 468 | ||
| 448 | endwin(); | 469 | |
| 449 | error(0, 0, "buy"); | 470 | char *newstring = NULL; |
| 450 | exit(0); | 471 | if(asprintf(&newstring, "Spins: %d, Price: %d", p->numspins, p->price) < 0) { |
| 472 | endwin(); | ||
| 473 | error(1, errno, "[VX-GAMBLEGROUND] Could not allocate space for spin/price string"); | ||
| 474 | } | ||
| 475 | |||
| 476 | mvwaddstr(p->slots->slotwin, 0, 1, newstring); | ||
| 477 | free(newstring); | ||
| 478 | |||
| 479 | wnoutrefresh(p->slots->slotwin); | ||
| 480 | doupdate(); | ||
| 451 | 481 | ||
| 452 | return 0; | 482 | return 0; |
| 453 | } | 483 | } |
| 454 | 484 | ||
| 455 | // Quit out | 485 | // Quit out |
| 456 | int quit(void *quitp) { | 486 | int quit(void *params) { |
| 457 | struct quitp *p = (struct quitp*)quitp; | 487 | |
| 458 | p->REPLACEME = "lol"; | ||
| 459 | 488 | ||
| 460 | endwin(); | 489 | endwin(); |
| 461 | error(0, 0, "quit"); | 490 | error(0, 0, "quit"); |
diff --git a/src/screen.h b/src/screen.h index 094aa40..22211b4 100644 --- a/src/screen.h +++ b/src/screen.h | |||
| @@ -88,29 +88,20 @@ struct funcholder { | |||
| 88 | 88 | ||
| 89 | FH_TOOBIG | 89 | FH_TOOBIG |
| 90 | } type; | 90 | } type; |
| 91 | }; | ||
| 91 | 92 | ||
| 92 | union param { | 93 | struct params { |
| 93 | struct spinp { | 94 | // Previously spinp |
| 94 | WINDOW *bannerwin; | 95 | WINDOW *bannerwin; |
| 95 | struct slotholder *slots; | 96 | struct slotholder *slots; |
| 96 | |||
| 97 | WINDOW *menuholder; | ||
| 98 | MENU *menu; | ||
| 99 | } spinp; | ||
| 100 | |||
| 101 | struct buyp { | ||
| 102 | unsigned long int price; | ||
| 103 | int numspins; | ||
| 104 | |||
| 105 | } buyp; | ||
| 106 | |||
| 107 | struct quitp { | ||
| 108 | char *REPLACEME; | ||
| 109 | 97 | ||
| 110 | } quitp; | 98 | WINDOW *menuholder; |
| 111 | } params; | 99 | MENU *menu; |
| 112 | 100 | ||
| 113 | }; | 101 | // Previously buyp |
| 102 | unsigned int price; | ||
| 103 | int numspins; | ||
| 104 | } params; | ||
| 114 | 105 | ||
| 115 | // Converts value from within the range of [oldmin, oldmax] to a value within the range [newmin, newmax] | 106 | // Converts value from within the range of [oldmin, oldmax] to a value within the range [newmin, newmax] |
| 116 | float normalize(float value, float oldmin, float oldmax, float newmin, float newmax); | 107 | float normalize(float value, float oldmin, float oldmax, float newmin, float newmax); |
| @@ -121,8 +112,8 @@ int rangemod(int x, int offset, int min, int max); | |||
| 121 | // Initialize a new curses color using standard rgb values (0-255) instead of curses' 0-1000 range | 112 | // Initialize a new curses color using standard rgb values (0-255) instead of curses' 0-1000 range |
| 122 | static int init_rgb_color(int colornum, int red, int green, int blue); | 113 | static int init_rgb_color(int colornum, int red, int green, int blue); |
| 123 | 114 | ||
| 124 | int spin(void *spinp); | 115 | int spin(void *params); |
| 125 | int buy(void *buyp); | 116 | int buy(void *params); |
| 126 | int quit(void *quitp); | 117 | int quit(void *params); |
| 127 | 118 | ||
| 128 | #endif \ No newline at end of file | 119 | #endif \ No newline at end of file |
