From d0862dd9d5f1170f4e25cc6e3a1da70d567038c2 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Wed, 28 Aug 2024 18:17:36 -0500 Subject: Count spins --- src/screen.c | 87 ++++++++++++++++++++++++++++++++++++++++-------------------- 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[] = { "Quit" }; -static struct funcholder userfuncs[] = { - {.callback = spin, .type = FH_SPIN}, - {.callback = buy, .type = FH_BUY}, - {.callback = quit, .type = FH_QUIT} -}; - void catcher(int signum, siginfo_t *info, void *ucontext) { // This is retarded lol, but makes gcc happy 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 } static int init_slotholder(struct slotholder *slots) { + mvwaddstr(slots->slotwin, 0, 1, "Spins: 3, Price: 1"); + wnoutrefresh(slots->slotwin); + getmaxyx(slots->slotwin, slots->sloty, slots->slotx); for(size_t i = 0; i < STATIC_ARRSIZE(slots->subslot); i++) { slots->subslot[i] = derwin(slots->slotwin, slots->sloty, slots->slotx/3, 0, slots->slotx/3 * i); @@ -274,13 +271,21 @@ int main() { // Variable definitions ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items - struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver + struct funcholder *p = NULL; + struct params params; // Function pointer used for callbacks in the menu driver WINDOW *menuholder = NULL; // The window for displaying the menu int row = -1, col = -1; // The rows and columns of the main screen uint32_t randomnum; // A random number for getting the banner phrase MENU *menu; // The actual menu object int c; // Integer for storing keys from user input + struct funcholder userfuncs[] = { + {.callback = spin, .type = FH_SPIN}, + {.callback = buy, .type = FH_BUY}, + {.callback = quit, .type = FH_QUIT}, + {0} + }; + struct slotholder slots; getmaxyx(stdscr, row, col); @@ -317,10 +322,12 @@ int main() { doupdate(); - userfuncs[0].params.spinp.bannerwin = banner; - userfuncs[0].params.spinp.menuholder = menuholder; - userfuncs[0].params.spinp.menu = menu; - userfuncs[0].params.spinp.slots = &slots; + params.bannerwin = banner; + params.menu = menu; + params.menuholder = menuholder; + params.numspins = 3; + params.price = 1; + params.slots = &slots; // Get user input and deal with the menu while((c = wgetch(menuholder)) != KEY_F(4)) { @@ -344,16 +351,12 @@ int main() { case KEY_ENTER: case FUCKED_UP_ENTER: // Enter p = (struct funcholder *)item_userptr(current_item(menu)); switch(p->type) { - case FH_SPIN: - p->callback((void*)&p->params.spinp); - break; - - case FH_BUY: - p->callback((void*)&p->params.buyp); + case FH_SPIN: case FH_BUY: + p->callback((void*)¶ms); break; case FH_QUIT: - p->callback((void*)&p->params.quitp); + p->callback(NULL); break; default: @@ -380,8 +383,21 @@ int main() { } // Spin the wheel -int spin(void *spinp) { - struct spinp *p = (struct spinp *)spinp; +int spin(void *params) { + struct params *p = (struct params *)params; + + p->numspins -= 1; + if(p->numspins < 0) { + endwin(); + error(1, 0, "[VX-GAMBLEGROUND] You ran out of spins! Game Over!"); + } + char *newstr = NULL; + if(asprintf(&newstr, "Spins: %d, Price: %d", p->numspins, p->price) < 0) { + endwin(); + error(1, errno, "[VX-GAMBLEGROUND] Shit brokey lol"); + } + mvwaddstr(p->slots->slotwin, 0, 1, newstr); + free(newstr); static const struct timespec sleeper = { .tv_sec = 0, @@ -440,22 +456,35 @@ int spin(void *spinp) { } // Increase number of spins -int buy(void *buyp) { - struct buyp *p = (struct buyp*)buyp; +int buy(void *params) { + struct params *p = (struct params *)params; + + if(p->numspins >= 100) + return 0; + p->numspins += 3; - p->price *= 2; + if(p->price <= 2000000) + p->price *= 2; - endwin(); - error(0, 0, "buy"); - exit(0); + + char *newstring = NULL; + if(asprintf(&newstring, "Spins: %d, Price: %d", p->numspins, p->price) < 0) { + endwin(); + error(1, errno, "[VX-GAMBLEGROUND] Could not allocate space for spin/price string"); + } + + mvwaddstr(p->slots->slotwin, 0, 1, newstring); + free(newstring); + + wnoutrefresh(p->slots->slotwin); + doupdate(); return 0; } // Quit out -int quit(void *quitp) { - struct quitp *p = (struct quitp*)quitp; - p->REPLACEME = "lol"; +int quit(void *params) { + endwin(); 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 { FH_TOOBIG } type; +}; - union param { - struct spinp { - WINDOW *bannerwin; - struct slotholder *slots; - - WINDOW *menuholder; - MENU *menu; - } spinp; - - struct buyp { - unsigned long int price; - int numspins; - - } buyp; - - struct quitp { - char *REPLACEME; +struct params { + // Previously spinp + WINDOW *bannerwin; + struct slotholder *slots; - } quitp; - } params; - -}; + WINDOW *menuholder; + MENU *menu; + + // Previously buyp + unsigned int price; + int numspins; +} params; // Converts value from within the range of [oldmin, oldmax] to a value within the range [newmin, newmax] 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); // Initialize a new curses color using standard rgb values (0-255) instead of curses' 0-1000 range static int init_rgb_color(int colornum, int red, int green, int blue); -int spin(void *spinp); -int buy(void *buyp); -int quit(void *quitp); +int spin(void *params); +int buy(void *params); +int quit(void *params); #endif \ No newline at end of file -- cgit v1.2.3