15 Commits

Author SHA1 Message Date
2855b64f03 fix for incorrect phony rule declaration 2025-06-30 12:27:57 +03:00
9c45259962 fixed unusual terminal state after quitting 2025-06-30 12:27:57 +03:00
b1256014e3 forgot the preprocessor keywords 2025-06-29 21:01:19 +03:00
b1af7b4f41 Merge branch 'main' of https://gitea.codersquack.nl/thorium1256/minesweeper 2025-06-29 20:57:19 +03:00
bbaf2f50f9 winsize detection 2025-06-27 16:37:14 +03:00
6915a0d827 small change to board size 2025-06-27 16:01:55 +03:00
2b0f20d65a Merge branch 'main' of https://gitea.codersquack.nl/thorium1256/minesweeper 2025-06-25 21:12:32 +03:00
e394d0986e relicense and make it REUSE-compliant 2025-06-25 20:49:03 +03:00
d8eb655dd7 fixed expert board size 2025-06-25 20:49:03 +03:00
b878c2ddb3 added install script 2025-06-25 20:49:03 +03:00
a0e5850e68 fix for compiler screams
forgotten others
2025-06-25 20:49:01 +03:00
84972ed9bb silly makefile stuff
makefile realization

makefile insanity

makefile madness

readme update to fit in with actual makefile
2025-06-25 20:48:44 +03:00
08f6ee7161 fixed a bug that would need you to press q a lot when there were a lot of restarts 2025-06-25 20:48:40 +03:00
f7d2f138ea minor changes to the rules 2025-06-25 20:48:39 +03:00
1d07cee01a the timer only starts when an action is taken 2025-06-25 20:48:36 +03:00
3 changed files with 44 additions and 7 deletions

View File

@@ -39,7 +39,7 @@ $(shell mkdir -p $(RLS_DIR))
$(shell mkdir -p $(BUILD_DIR)) $(shell mkdir -p $(BUILD_DIR))
# phony rules # phony rules
.PHONY := all debug release clean install uninstall .PHONY = all debug release clean install uninstall
all: release all: release

View File

@@ -37,7 +37,7 @@ $(shell if not exist $(RLS_DIR) mkdir $(RLS_DIR))
$(shell if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)) $(shell if not exist $(BUILD_DIR) mkdir $(BUILD_DIR))
# phony rules # phony rules
.PHONY := all debug release clean libraries_debug libraries_release both .PHONY = all debug release clean libraries_debug libraries_release both
all: release all: release

View File

@@ -8,6 +8,15 @@
#include <ctime> #include <ctime>
#include <unistd.h> #include <unistd.h>
#include "Board.h" #include "Board.h"
#ifndef _WIN32
#include <signal.h>
#include <sys/ioctl.h>
struct winsize w;
void handleSIGWINCH(int sig)
{
ioctl(STDIN_FILENO, TIOCGWINSZ, &w);
}
#endif
#define MAX_TIME 60 #define MAX_TIME 60
@@ -33,8 +42,17 @@ void startGame(Board &board)
while (gameRunning) while (gameRunning)
{ {
usleep((1000 / MAX_TIME) * 1000); 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()) if (board.isGameOver() || board.isGameWon())
{ {
gameRunning = false; gameRunning = false;
@@ -160,6 +178,9 @@ void startGame(Board &board)
cursorX = (cursorX < boardSize.x - 1) ? cursorX + 1 : 0; cursorX = (cursorX < boardSize.x - 1) ? cursorX + 1 : 0;
break; break;
case 'q': case 'q':
echo();
cbreak();
endwin();
exit(0); exit(0);
break; break;
case 'z': case 'z':
@@ -262,7 +283,12 @@ void startGame(Board &board)
{ {
Board newBoard(boardSize.x, boardSize.y, board.getMineCount()); Board newBoard(boardSize.x, boardSize.y, board.getMineCount());
startGame(newBoard); startGame(newBoard);
} else if(c == 'q') { }
else if (c == 'q')
{
echo();
cbreak();
endwin();
exit(0); exit(0);
} }
}; };
@@ -289,7 +315,12 @@ void startGame(Board &board)
{ {
Board newBoard(boardSize.x, boardSize.y, board.getMineCount()); Board newBoard(boardSize.x, boardSize.y, board.getMineCount());
startGame(newBoard); startGame(newBoard);
} else if(c == 'q') { }
else if (c == 'q')
{
echo();
cbreak();
endwin();
exit(0); exit(0);
} }
}; };
@@ -298,12 +329,18 @@ void startGame(Board &board)
int main() int main()
{ {
#ifndef _WIN32
signal(SIGWINCH, handleSIGWINCH);
#endif
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
initscr(); initscr();
noecho(); noecho();
cbreak(); cbreak();
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
nodelay(stdscr, TRUE); nodelay(stdscr, TRUE);
#ifndef _WIN32
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
#endif
start_color(); start_color();
init_pair(1, COLOR_BLUE, COLOR_BLACK); init_pair(1, COLOR_BLUE, COLOR_BLACK);
@@ -334,9 +371,9 @@ int main()
attroff(A_REVERSE); attroff(A_REVERSE);
mvprintw(3, 2, choice == 1 ? "" : "Intermediate (16x16, 40 mines)"); mvprintw(3, 2, choice == 1 ? "" : "Intermediate (16x16, 40 mines)");
attron(A_REVERSE); attron(A_REVERSE);
mvprintw(4, 2, choice == 2 ? "Expert (16x30, 99 mines)" : ""); mvprintw(4, 2, choice == 2 ? "Expert (30x16, 99 mines)" : "");
attroff(A_REVERSE); attroff(A_REVERSE);
mvprintw(4, 2, choice == 2 ? "" : "Expert (16x30, 99 mines)"); mvprintw(4, 2, choice == 2 ? "" : "Expert (30x16, 99 mines)");
refresh(); refresh();
int ch = getch(); int ch = getch();