From a3e80d0b43cc20ae3a2b8ae32ea62bd4c616cfaa Mon Sep 17 00:00:00 2001 From: TheRedBlueCube3 Date: Sun, 22 Jun 2025 00:20:30 +0300 Subject: [PATCH] pausing support --- README.md | 3 ++- src/main.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0d16ed..142dcad 100644 --- a/README.md +++ b/README.md @@ -61,4 +61,5 @@ Then rename `Makefile.unix`, press the make button, and a moment later, you got Arrows to move. Z to reveal. X to flag. -R to restart. +R to restart. +Q to quit. diff --git a/src/main.cpp b/src/main.cpp index 144b507..d215bed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,10 @@ void startGame(Board &board) time_t startTime = time(nullptr); int elapsedTime; + bool isPaused = false; + time_t startPauseTime = 0; + time_t pauseTime = 0; + time_t totalpausetime = 0; while (gameRunning) { usleep((1000 / MAX_TIME) * 1000); @@ -28,7 +32,6 @@ void startGame(Board &board) { gameRunning = false; } - elapsedTime = difftime(time(NULL), startTime); char flags[5]; char tim[5]; sprintf(flags, "%03d", minesLeft); @@ -36,7 +39,10 @@ void startGame(Board &board) attron(COLOR_PAIR(3)); mvprintw(1, 1, "%s", flags); attroff(COLOR_PAIR(3)); - mvprintw(1, 5, ":)"); + if (!isPaused) + mvprintw(1, 5, ":)"); + else + mvprintw(1, 5, ":|"); attron(COLOR_PAIR(3)); mvprintw(1, 8, "%s", tim); attroff(COLOR_PAIR(3)); @@ -162,8 +168,24 @@ void startGame(Board &board) startTime = time(NULL); board.regenerateBoard(); break; + case 'p': + if (isPaused) + { + pauseTime = difftime(time(NULL), startPauseTime); + totalpausetime += pauseTime; + } + else + { + startPauseTime = time(NULL); + } + isPaused = !isPaused; } + if (isPaused) + continue; + + elapsedTime = difftime(time(NULL), startTime) - totalpausetime; + refresh(); }