From: Matthew Mondor Date: Fri, 14 Apr 2023 12:53:09 +0000 (+0000) Subject: Added highscore tracking and display. X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=475633eb828a9c129059d8186f3c1c5df11ceebd;p=pacman.git Added highscore tracking and display. --- diff --git a/MATT-README.txt b/MATT-README.txt index c3bd514..b91c44f 100644 --- a/MATT-README.txt +++ b/MATT-README.txt @@ -13,6 +13,7 @@ IMPROVEMENTS: and "munches". - Use flushinp(3) instead of ad hoc getch(3) to flush input. - Added an atexit(3) cleanup handler for endwin(3). +- Added hiscore/level tracking and display, now requires 33 lines. BUGFIXES: @@ -35,3 +36,5 @@ ISSUES: detect the situation. - The level editor crashes, it's possible that it requires porting to 64-bit or other fixes. Did not bother. +- There are some globals in pacman.h that should really be macro + definitions, and/or moved to the main module. diff --git a/pacman.c b/pacman.c index 48378a4..54f2e58 100755 --- a/pacman.c +++ b/pacman.c @@ -33,7 +33,7 @@ *************/ void IntroScreen(); //Show introduction screen and menu int CheckCollision(); //See if Pacman and Ghosts collided -void CheckScreenSize(); //Make sure resolution is at least 32x29 +void CheckScreenSize(); //Make sure resolution is at least 33x29 void CreateWindows(int y, int x, int y0, int x0); //Make ncurses windows void Delay(); //Slow down game for better control void DrawWindow(); //Refresh display @@ -67,6 +67,8 @@ int Invincible = 0; //Check for invincibility int Food = 0; //Number of pellets left in level int Level[29][28] = { 0 }; //Main level array int LevelNumber = 0; //What level number are we on? +int HiPoints = 0; //Highscore +int HiLevelNumber = 0; //Level number reached by hiscore int GhostsInARow = 0; //Keep track of how many points to give for eating ghosts int tleft = 0; //How long left for invincibility @@ -121,7 +123,7 @@ int main(int argc, char *argv[100]) { InitCurses(); //Must be called to start ncurses CheckScreenSize(); //Make sure screen is big enough - CreateWindows(29, 28, 1, 1); //Create the main and status windows + CreateWindows(30, 28, 1, 1); //Create the main and status windows curses_initialized = true; (void)atexit(Cleanup); @@ -243,10 +245,10 @@ void CheckScreenSize() { //Make sure the window is big enough int h, w; getmaxyx(stdscr, h, w); - if((h < 32) || (w < 29)) { + if((h < 33) || (w < 29)) { endwin(); fprintf(stderr, "\nSorry.\n"); - fprintf(stderr, "To play Pacman for Console, your console window must be at least 29x32\n"); + fprintf(stderr, "To play Pacman for Console, your console window must be at least 29x33\n"); fprintf(stderr, "Please resize your window/resolution and re-run the game.\n\n"); exit(0); } @@ -256,6 +258,12 @@ void CheckScreenSize() { int GameOverScreen() { char chr = ' '; int a, b; + + if (Points > HiPoints) { + HiPoints = Points; + HiLevelNumber = LevelNumber; + } + for(a = 0; a < 29; a++) for(b = 0; b < 28; b++) { mvwaddch(win, a, b, chr); } @@ -295,7 +303,7 @@ int GameOverScreen() { void CreateWindows(int y, int x, int y0, int x0) { //Create two new windows, for status bar and for main level win = newwin(y, x, y0, x0); - status = newwin(3, 27, 29, 1); + status = newwin(4, 27, 29, 1); } /**************************************************************** @@ -370,7 +378,12 @@ void DrawWindow() { //Display level number and score wattron(status, COLOR_PAIR(Normal)); - mvwprintw(status, 2, 2, "Level: %d Score: %d ", LevelNumber, Points); + mvwprintw(status, 2, 3, "Level: %02d Score: %06d ", LevelNumber, Points); + if (HiPoints > 0) { + wattron(status, COLOR_PAIR(Pacman)); + mvwprintw(status, 3, 0, "Hi Level: %02d Score: %06d", + HiLevelNumber, HiPoints); + } wrefresh(status); //Update status window