pausing support

don't render when paused

forgot a restarting thing

forgot something YET AGAIN

forgot something

and yet another readme eror but i didnt push yet so awesome

little help on the newbies at minesweeper
This commit is contained in:
TheRedBlueCube3 2025-06-22 00:20:30 +03:00 committed by thorium1256
parent 961d62ce7d
commit fe05089cf7
2 changed files with 35 additions and 4 deletions

View File

@ -6,6 +6,7 @@ Minesweeper is a classic puzzle game where the objective is to clear a rectangul
The board consists of hidden cells, some containing mines. Uncover a cell by selecting its coordinates. If it's a mine, you lose. If it's safe, a number appears indicating how many mines are adjacent to that cell. The board consists of hidden cells, some containing mines. Uncover a cell by selecting its coordinates. If it's a mine, you lose. If it's safe, a number appears indicating how many mines are adjacent to that cell.
**Use logic to deduce mine locations and mark them with flags.** **Use logic to deduce mine locations and mark them with flags.**
Marking all mines with flags isn't necessary, but helps.
### Clear all non-mine cells to win! ### Clear all non-mine cells to win!
@ -62,3 +63,5 @@ Arrows to move.
Z to reveal. Z to reveal.
X to flag. X to flag.
R to restart. R to restart.
P to pause.
Q to quit.

View File

@ -19,16 +19,22 @@ void startGame(Board &board)
bool gameRunning = true; bool gameRunning = true;
time_t startTime = time(nullptr); time_t startTime = time(nullptr);
int elapsedTime; int elapsedTime = 0;
bool isPaused = false;
time_t startPauseTime = 0;
time_t pauseTime = 0;
time_t totalpausetime = 0;
while (gameRunning) while (gameRunning)
{ {
usleep((1000 / MAX_TIME) * 1000); usleep((1000 / MAX_TIME) * 1000);
if (board.isGameOver() || board.isGameWon()) if (board.isGameOver() || board.isGameWon())
{ {
gameRunning = false; gameRunning = false;
} }
elapsedTime = difftime(time(NULL), startTime); if (!isPaused)
elapsedTime = difftime(time(NULL), startTime) - totalpausetime;
char flags[5]; char flags[5];
char tim[5]; char tim[5];
sprintf(flags, "%03d", minesLeft); sprintf(flags, "%03d", minesLeft);
@ -36,7 +42,10 @@ void startGame(Board &board)
attron(COLOR_PAIR(3)); attron(COLOR_PAIR(3));
mvprintw(1, 1, "%s", flags); mvprintw(1, 1, "%s", flags);
attroff(COLOR_PAIR(3)); attroff(COLOR_PAIR(3));
mvprintw(1, 5, ":)"); if (!isPaused)
mvprintw(1, 5, ":)");
else
mvprintw(1, 5, ":|");
attron(COLOR_PAIR(3)); attron(COLOR_PAIR(3));
mvprintw(1, 8, "%s", tim); mvprintw(1, 8, "%s", tim);
attroff(COLOR_PAIR(3)); attroff(COLOR_PAIR(3));
@ -75,6 +84,9 @@ void startGame(Board &board)
displayChar = 'X'; displayChar = 'X';
} }
if (isPaused)
displayChar = '#';
if (x == cursorX && y == cursorY) if (x == cursorX && y == cursorY)
{ {
attron(A_REVERSE); attron(A_REVERSE);
@ -161,9 +173,25 @@ void startGame(Board &board)
case 'r': case 'r':
startTime = time(NULL); startTime = time(NULL);
board.regenerateBoard(); board.regenerateBoard();
somethingHasBeenDone = false;
elapsedTime = 0;
break; break;
case 'p':
if (isPaused)
{
pauseTime = difftime(time(NULL), startPauseTime);
totalpausetime += pauseTime;
}
else
{
startPauseTime = time(NULL);
}
isPaused = !isPaused;
} }
if (isPaused)
continue;
refresh(); refresh();
} }