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:
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user