mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [Refactor] Move game logic into libcockatrice_game * [Refactor] Include card_state.h in player_actions.h * [Game] Inject settings providers into libcockatrice_game, drop Widgets * [Game] Follow base rename to createCardRequested after rebase * [Game] Drop unused CardItem forward declaration * [Game] Fix includes after moving game logic into libcockatrice_game --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include "game_state.h"
|
|
|
|
#include "abstract_game.h"
|
|
|
|
#include <QChar>
|
|
#include <QTimer>
|
|
|
|
class AbstractClient;
|
|
|
|
GameState::GameState(AbstractGame *parent,
|
|
int _secondsElapsed,
|
|
int _hostId,
|
|
bool _isLocalGame,
|
|
const QList<AbstractClient *> _clients,
|
|
bool _gameStateKnown,
|
|
bool _resuming,
|
|
int _currentPhase,
|
|
bool _gameClosed)
|
|
: QObject(parent), gameTimer(nullptr), secondsElapsed(_secondsElapsed), hostId(_hostId), isLocalGame(_isLocalGame),
|
|
clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase),
|
|
activePlayer(-1), gameClosed(_gameClosed)
|
|
{
|
|
gameTimer = new QTimer(this);
|
|
gameTimer->setInterval(1000);
|
|
connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime);
|
|
gameTimer->start();
|
|
}
|
|
|
|
void GameState::incrementGameTime()
|
|
{
|
|
setGameTime(++secondsElapsed);
|
|
}
|
|
|
|
void GameState::setGameTime(int _secondsElapsed)
|
|
{
|
|
secondsElapsed = _secondsElapsed;
|
|
emit updateTimeElapsedLabel(formatElapsedTime(_secondsElapsed));
|
|
}
|
|
|
|
QString GameState::formatElapsedTime(int _secondsElapsed)
|
|
{
|
|
int seconds = _secondsElapsed;
|
|
int minutes = seconds / 60;
|
|
seconds -= minutes * 60;
|
|
int hours = minutes / 60;
|
|
minutes -= hours * 60;
|
|
|
|
return QString::number(hours).rightJustified(2, '0') + ":" + QString::number(minutes).rightJustified(2, '0') + ":" +
|
|
QString::number(seconds).rightJustified(2, '0');
|
|
}
|