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:
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

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