mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
Fix timer starting twice, not stopping and not resetting correctly.
Took 39 minutes
This commit is contained in:
parent
23612ba6ec
commit
594985bf9e
2 changed files with 11 additions and 3 deletions
|
|
@ -15,6 +15,9 @@ GameState::GameState(AbstractGame *parent,
|
||||||
clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase),
|
clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase),
|
||||||
activePlayer(-1), gameClosed(_gameClosed)
|
activePlayer(-1), gameClosed(_gameClosed)
|
||||||
{
|
{
|
||||||
|
gameTimer = new QTimer(this);
|
||||||
|
gameTimer->setInterval(1000);
|
||||||
|
connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameState::incrementGameTime()
|
void GameState::incrementGameTime()
|
||||||
|
|
@ -24,6 +27,7 @@ void GameState::incrementGameTime()
|
||||||
|
|
||||||
void GameState::setGameTime(int _secondsElapsed)
|
void GameState::setGameTime(int _secondsElapsed)
|
||||||
{
|
{
|
||||||
|
secondsElapsed = _secondsElapsed;
|
||||||
int seconds = _secondsElapsed;
|
int seconds = _secondsElapsed;
|
||||||
int minutes = seconds / 60;
|
int minutes = seconds / 60;
|
||||||
seconds -= minutes * 60;
|
seconds -= minutes * 60;
|
||||||
|
|
@ -37,8 +41,10 @@ void GameState::setGameTime(int _secondsElapsed)
|
||||||
|
|
||||||
void GameState::startGameTimer()
|
void GameState::startGameTimer()
|
||||||
{
|
{
|
||||||
gameTimer = new QTimer(this);
|
|
||||||
gameTimer->setInterval(1000);
|
|
||||||
connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime);
|
|
||||||
gameTimer->start();
|
gameTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameState::stopGameTimer()
|
||||||
|
{
|
||||||
|
gameTimer->stop();
|
||||||
|
}
|
||||||
|
|
@ -94,11 +94,13 @@ public:
|
||||||
startGameTimer();
|
startGameTimer();
|
||||||
emit gameStarted(_started);
|
emit gameStarted(_started);
|
||||||
} else {
|
} else {
|
||||||
|
stopGameTimer();
|
||||||
emit gameStopped();
|
emit gameStopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startGameTimer();
|
void startGameTimer();
|
||||||
|
void stopGameTimer();
|
||||||
|
|
||||||
void setGameStateKnown(bool known)
|
void setGameStateKnown(bool known)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue