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:
parent
961d62ce7d
commit
fe05089cf7
@ -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.
|
||||
**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!
|
||||
|
||||
@ -62,3 +63,5 @@ Arrows to move.
|
||||
Z to reveal.
|
||||
X to flag.
|
||||
R to restart.
|
||||
P to pause.
|
||||
Q to quit.
|
||||
|
34
src/main.cpp
34
src/main.cpp
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user