-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgamehandler.cpp
More file actions
65 lines (51 loc) · 1.29 KB
/
Copy pathgamehandler.cpp
File metadata and controls
65 lines (51 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "gamehandler.h"
#include "constants.h"
#include "game.h"
#include "mode.h"
#include <QImage>
#include <QDebug>
#include <QTimer>
#include <QFileInfo>
#include <cstdlib>
#include <time.h>
GameHandler::GameHandler(QObject *parent) :
QObject(parent),
m_game(nullptr),
m_high_score(0),
m_timed_high_score(0){
srand (time(NULL));
}
void GameHandler::newGame(int mode)
{
if(m_game!=nullptr) m_game->deleteLater();
m_game = new Game(Mode::Type(mode), this);
connect(m_game, &Game::finishedChanged, this, &GameHandler::updateHighScore);
emit gameChanged(m_game);
}
Game *GameHandler::getGame()
{
return m_game;
}
int GameHandler::getHighScore()
{
if(this->getGame()->getMode()==Mode::TIMED)
return m_timed_high_score;
return m_high_score;
}
void GameHandler::updateHighScore()
{
if(m_game->getMode()==Mode::NORMAL){
int newPoints = m_game->getPoints();
if(newPoints>m_high_score){
m_high_score = newPoints;
emit highScoreChanged(m_high_score);
}
}
else if(m_game->getMode()==Mode::TIMED){
int newPoints = m_game->getPoints();
if(newPoints>m_timed_high_score) {
m_timed_high_score = newPoints;
emit highScoreChanged(m_timed_high_score);
}
}
}