forked from t-mon/monsterwars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameengine.h
181 lines (148 loc) · 5.54 KB
/
gameengine.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <[email protected]> *
* *
* This file is part of Monster Wars. *
* *
* Monster Wars is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* Monster Wars is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Monster Wars. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef GAMEENGINE_H
#define GAMEENGINE_H
#include <QObject>
#include <QTimer>
#include <QElapsedTimer>
#include <QTime>
#include <QDebug>
#include <QUrl>
#include <QDir>
#include <QQmlListProperty>
#include <QUuid>
#include "aibrain.h"
#include "levelmodel.h"
#include "playersettings.h"
#include "attackpillowmodel.h"
class Level;
class Player;
class Monster;
class Board;
class Attack;
class AttackPillow;
class GameEngine : public QObject
{
Q_OBJECT
Q_PROPERTY(int rows READ rows CONSTANT)
Q_PROPERTY(int columns READ columns CONSTANT)
Q_PROPERTY(QUrl dataDir READ dataDir WRITE setDataDir NOTIFY dataDirChanged)
Q_PROPERTY(Board *board READ board NOTIFY boardChanged)
Q_PROPERTY(QString displayGameTime READ displayGameTime NOTIFY displayGameTimeChanged)
Q_PROPERTY(QString gameTime READ gameTime NOTIFY gameTimeChanged)
Q_PROPERTY(int winnerId READ winnerId NOTIFY winnerIdChanged)
Q_PROPERTY(bool running READ running NOTIFY runningChanged)
Q_PROPERTY(bool newHighScore READ newHighScore NOTIFY newHighScoreChanged)
Q_PROPERTY(bool tunePointEarned READ tunePointEarned NOTIFY tunePointEarnedChanged)
Q_PROPERTY(LevelModel *levels READ levels NOTIFY levelsChanged)
Q_PROPERTY(AttackPillowModel *pillows READ pillows NOTIFY pillowsChanged)
Q_PROPERTY(PlayerSettings *playerSettings READ playerSettings NOTIFY playerSettingsChanged)
public:
explicit GameEngine(QObject *parent = 0);
QHash<int, QVariantMap> levelDescriptions() const;
QVariantMap levelDescription(int levelId) const;
Board* board() const;
LevelModel *levels();
AttackPillowModel *pillows();
QUrl dataDir() const;
void setDataDir(const QUrl &dataDir);
void start();
void stop();
int rows() const;
int columns() const;
QString gameTime() const;
QString displayGameTime() const;
bool running() const;
bool newHighScore() const;
bool tunePointEarned() const;
int winnerId() const;
void startAttack(Attack *attack);
int ticksPerSecond() const;
int tickInterval() const;
PlayerSettings *playerSettings();
Q_INVOKABLE double strengthStepWidth() const;
Q_INVOKABLE double reproductionStepWidth() const;
Q_INVOKABLE double defenseStepWidth() const;
Q_INVOKABLE double speedStepWidth() const;
Q_INVOKABLE void startGame(const int &levelId);
Q_INVOKABLE void restartGame();
Q_INVOKABLE void stopGame();
Q_INVOKABLE void pauseGame();
Q_INVOKABLE void continueGame();
Q_INVOKABLE void attackFinished(QString pillowId);
Q_INVOKABLE void resetGameSettings();
private:
QTimer *m_timer;
QTimer *m_displayTimer;
QElapsedTimer m_gameTimer;
qint32 m_totalGameTimeMs;
qint32 m_finalTime;
bool m_gameOver;
QUrl m_dataDir;
QHash<int, QVariantMap> m_levelDescriptions;
LevelModel *m_levels;
AttackPillowModel *m_pillowsModel;
QHash<QString, AttackPillow *> m_pillowList;
QHash<Player *, AiBrain *> m_brains;
QHash<int, Level *> m_levelHash;
PlayerSettings *m_playerSettings;
Board *m_board;
int m_ticksPerSecond;
int m_tickInterval;
int m_rows;
int m_columns;
int m_winnerId;
bool m_running;
bool m_newHighScore;
bool m_tunePointEarned;
double m_strengthStepWidth;
double m_reproductionStepWidth;
double m_defenseStepWidth;
double m_speedStepWidth;
void loadLevels();
void loadPlayerSettings();
void calculateScores();
signals:
void tick();
void dataDirChanged();
void boardChanged();
void levelsChanged();
void pillowsChanged();
void runningChanged();
void gameTimeChanged();
void displayGameTimeChanged();
void gameOver();
void gameStarted();
void gameRestarted();
void gameStoped();
void gamePaused();
void gameContinue();
void gameFinished(const int &winnerId);
void winnerIdChanged();
void newHighScoreChanged();
void tunePointEarnedChanged();
void playerSettingsChanged();
private slots:
void initGameEngine();
void slotTick();
void onDisplayTimerTimeout();
void onGameOver(const int &winnerId);
};
#endif // GAMEENGINE_H