-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.h
70 lines (60 loc) · 1.65 KB
/
game.h
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
64
65
66
67
68
69
70
#ifndef GAME_H
#define GAME_H
#include <QObject>
#include <QTimer>
#include <QVector>
#include <random>
struct Task
{
Task(int aScoreValue = 1) {
scoreValue = aScoreValue;
}
Task(QString aQuestion, QString aAnswer, QString wrongAnswer1, QString wrongAnswer2, QString wrongAnswer3)
: question(aQuestion), answer(aAnswer), scoreValue(1) {
possibleAnswers.append(wrongAnswer1);
possibleAnswers.append(wrongAnswer2);
possibleAnswers.append(wrongAnswer3);
}
QString question;
QString answer;
QVector<QString> possibleAnswers;
int scoreValue;
};
class Game : public QObject
{
Q_OBJECT
public:
explicit Game(QObject *parent = 0);
signals:
void remainingTimeChanged(int timeInSeconds);
void scoreChanged(int score);
void userMessage(const QString &reason);
void nextTaskPossible();
void end(int score);
public:
template<typename Container>
static void shuffleContainer(Container &container) {
static std::random_device randomDevice;
static std::mt19937 generator(randomDevice());
std::shuffle(container.begin(), container.end(), generator);
}
void setTasks(const QVector<Task> &tasks);
void reset(int intervalInSeconds = 20);
QString nextTask();
bool checkAnswer(const QString &answer);
QVector<QString> possibleAnswers() const;
int score();
int intervall();
private slots:
void update();
private:
void setScore(int score);
QTimer m_secondsTimer;
QVector<Task> m_tasks;
int m_score;
int m_remainingTime;
int m_taskIntervalTime;
int m_currentTask;
bool m_isInCheckAnswer;
};
#endif // GAME_H