mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
[Refactor] Move game logic into libcockatrice_game
This commit is contained in:
parent
710dfabea2
commit
7556f6465a
91 changed files with 388 additions and 179 deletions
|
|
@ -1,50 +0,0 @@
|
|||
#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');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue