Updated: fixed stuff

This commit is contained in:
Lian Drake 2023-12-08 18:38:00 -04:00
parent 3942bc03e1
commit 52da66ed01

View file

@ -387,6 +387,7 @@ void drawGame() {
/* Clear the terminal screen */ /* Clear the terminal screen */
erase(); erase();
/* Create a ncurses window for the game board */
WINDOW *gameBoard = newwin(SCREEN_HEIGHT, SCREEN_WIDTH, startY, startX); WINDOW *gameBoard = newwin(SCREEN_HEIGHT, SCREEN_WIDTH, startY, startX);
box(gameBoard, 0, 0); box(gameBoard, 0, 0);
refresh(); refresh();
@ -458,6 +459,7 @@ int initializeGame() {
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
curs_set(0); curs_set(0);
/* Detect if the terminal window is smaller than the board */
if (SCREEN_HEIGHT > LINES || SCREEN_WIDTH > COLS) { if (SCREEN_HEIGHT > LINES || SCREEN_WIDTH > COLS) {
endwin(); endwin();
fprintf(stderr, "ERROR: The terminal window needs to be larger.\n"); fprintf(stderr, "ERROR: The terminal window needs to be larger.\n");
@ -465,6 +467,8 @@ int initializeGame() {
} }
nodelay(stdscr, TRUE); nodelay(stdscr, TRUE);
/* Set starting X and Y coordinates to center ncurses windows */
getmaxyx(stdscr, terminalRows, terminalCols); getmaxyx(stdscr, terminalRows, terminalCols);
startY = (terminalRows - SCREEN_HEIGHT) / 2; startY = (terminalRows - SCREEN_HEIGHT) / 2;
startX = (terminalCols - SCREEN_WIDTH) / 2; startX = (terminalCols - SCREEN_WIDTH) / 2;
@ -484,6 +488,7 @@ void run() {
int choice; int choice;
bool isRunning = true; bool isRunning = true;
/* Create an ncurses window for the main menu */
WINDOW * menuScreen = newwin(SCREEN_HEIGHT, SCREEN_WIDTH, startY, startX); WINDOW * menuScreen = newwin(SCREEN_HEIGHT, SCREEN_WIDTH, startY, startX);
refresh(); refresh();
wrefresh(menuScreen); wrefresh(menuScreen);
@ -494,7 +499,7 @@ void run() {
/* Input validation loop */ /* Input validation loop */
do { do {
/* Use getch to get a single character */ /* Use wgetch to get a single character */
choice = wgetch(menuScreen); choice = wgetch(menuScreen);
} while (choice < '1' || choice > '3'); } while (choice < '1' || choice > '3');
@ -569,6 +574,7 @@ void mainMenu(WINDOW *menuScreen, int menuType) {
break; break;
case 3: case 3:
/* Display the final score on the main menu */ /* Display the final score on the main menu */
mvwprintw(menuScreen, menuY + 12, menuX, "\tGAME OVER");
mvwprintw(menuScreen, menuY + 13, menuX, "\tFinal Score: %d", score); mvwprintw(menuScreen, menuY + 13, menuX, "\tFinal Score: %d", score);
mvwprintw(menuScreen, menuY + 14, menuX, "\tPress a key to go back..."); mvwprintw(menuScreen, menuY + 14, menuX, "\tPress a key to go back...");
wgetch(menuScreen); wgetch(menuScreen);