From 082f4df08cd0e8ff4680226920df3d864536c333 Mon Sep 17 00:00:00 2001 From: thorium1256 Date: Fri, 27 Jun 2025 15:40:48 +0300 Subject: [PATCH 1/3] gameover/win conditions --- src/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7e34a3f..9c7649c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -251,12 +251,15 @@ void startGame(Board &board) mvprintw(1, 8, "%s", tim); attroff(COLOR_PAIR(3)); refresh(); - while ((c = getch()) != 'q') + while (true) { + c = getch(); if (c == 'r') { Board newBoard(boardSize.x, boardSize.y, board.getMineCount()); startGame(newBoard); + } else if(c == 'q') { + exit(0); } }; } @@ -275,12 +278,15 @@ void startGame(Board &board) attroff(COLOR_PAIR(3)); refresh(); int c; - while ((c = getch()) != 'q') + while (true) { + c = getch(); if (c == 'r') { Board newBoard(boardSize.x, boardSize.y, board.getMineCount()); startGame(newBoard); + } else if(c == 'q') { + exit(0); } }; } From 6915a0d82738f42eb9d09065c034731718d614d0 Mon Sep 17 00:00:00 2001 From: thorium1256 Date: Fri, 27 Jun 2025 16:01:55 +0300 Subject: [PATCH 2/3] small change to board size --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5e3154d..3e9f21e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -334,9 +334,9 @@ int main() attroff(A_REVERSE); mvprintw(3, 2, choice == 1 ? "" : "Intermediate (16x16, 40 mines)"); attron(A_REVERSE); - mvprintw(4, 2, choice == 2 ? "Expert (16x30, 99 mines)" : ""); + mvprintw(4, 2, choice == 2 ? "Expert (30x16, 99 mines)" : ""); attroff(A_REVERSE); - mvprintw(4, 2, choice == 2 ? "" : "Expert (16x30, 99 mines)"); + mvprintw(4, 2, choice == 2 ? "" : "Expert (30x16, 99 mines)"); refresh(); int ch = getch(); From bbaf2f50f9c5eac055672895ad8cca862a0ddcd7 Mon Sep 17 00:00:00 2001 From: thorium1256 Date: Fri, 27 Jun 2025 16:37:14 +0300 Subject: [PATCH 3/3] winsize detection --- src/main.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3e9f21e..48b26e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,15 @@ #include #include #include "Board.h" +#ifndef _WIN32 +#include +#include +struct winsize w; +void handleSIGWINCH(int sig) +{ + ioctl(STDIN_FILENO, TIOCGWINSZ, &w); +} +#endif #define MAX_TIME 60 @@ -33,8 +42,16 @@ void startGame(Board &board) while (gameRunning) { - usleep((1000 / MAX_TIME) * 1000); +#ifndef _WIN32 + if((w.ws_row < boardSize.x + 3 )||( w.ws_col < boardSize.y + 2)) { + mvprintw(w.ws_col/2, w.ws_row/2, "Your terminal is too small:"); + mvprintw(w.ws_col / 2 + 1, w.ws_row/2, "Current size: %dx%d", w.ws_row, w.ws_col); + mvprintw(w.ws_col / 2 + 2, w.ws_row/2, "Min size: %dx%d", boardSize.x + 3, boardSize.y + 2); + refresh(); + continue; + } +#endif if (board.isGameOver() || board.isGameWon()) { gameRunning = false; @@ -161,6 +178,9 @@ void startGame(Board &board) break; case 'q': exit(0); + echo(); + cbreak(); + endwin(); break; case 'z': if (!somethingHasBeenDone) @@ -264,6 +284,9 @@ void startGame(Board &board) startGame(newBoard); } else if(c == 'q') { exit(0); + echo(); + cbreak(); + endwin(); } }; } @@ -291,6 +314,9 @@ void startGame(Board &board) startGame(newBoard); } else if(c == 'q') { exit(0); + echo(); + cbreak(); + endwin(); } }; } @@ -298,12 +324,14 @@ void startGame(Board &board) int main() { + signal(SIGWINCH, handleSIGWINCH); setlocale(LC_ALL, ""); initscr(); noecho(); cbreak(); keypad(stdscr, TRUE); nodelay(stdscr, TRUE); + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); start_color(); init_pair(1, COLOR_BLUE, COLOR_BLACK);