pausing support

This commit is contained in:
TheRedBlueCube3 2025-06-22 00:20:30 +03:00
parent bb41c6643e
commit a3e80d0b43
2 changed files with 26 additions and 3 deletions

View File

@ -62,3 +62,4 @@ Arrows to move.
Z to reveal. Z to reveal.
X to flag. X to flag.
R to restart. R to restart.
Q to quit.

View File

@ -21,6 +21,10 @@ void startGame(Board &board)
time_t startTime = time(nullptr); time_t startTime = time(nullptr);
int elapsedTime; int elapsedTime;
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);
@ -28,7 +32,6 @@ void startGame(Board &board)
{ {
gameRunning = false; gameRunning = false;
} }
elapsedTime = difftime(time(NULL), startTime);
char flags[5]; char flags[5];
char tim[5]; char tim[5];
sprintf(flags, "%03d", minesLeft); sprintf(flags, "%03d", minesLeft);
@ -36,7 +39,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));
@ -162,8 +168,24 @@ void startGame(Board &board)
startTime = time(NULL); startTime = time(NULL);
board.regenerateBoard(); board.regenerateBoard();
break; 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(); refresh();
} }