-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.h
237 lines (192 loc) · 4.58 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#ifndef GAME_H
#define GAME_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QWidget>
#include <QThread>
#include <QLabel>
#include <QCloseEvent>
#include <QTimer>
#include <QPushButton>
#include <vector>
#include "Player.h"
#include "BackgroundMusic.h"
#include "ScoreUpdater.h"
#include "NoobSet.h"
#include "Set1.h"
#include "Set2.h"
#include "RunPlayerWorker.h"
#include "BackgroundUpdater.h"
#include "GameType.h"
#include "GameState.h"
class Game : public QGraphicsView
{
Q_OBJECT
public:
// member functions
/**
* \brief Constructor
* \param type Type of the game
* \param playerIDMapping Vector representing the choice of characters
* \param parent Pointer to Parent of this Widget
*/
Game(GameType type, std::vector <int> playerIDMapping, QWidget* parent = 0);
/**
* \brief Function called when Key press is detected
*/
void keyPressEvent(QKeyEvent* event);
/**
* \brief Function called when X button is pressed
*/
void closeEvent(QCloseEvent* event);
/**
* \brief Starts a SinglePlayer Game
*/
void startSinglePlayerGame();
/**
* \brief Starts a MultiPlayer Game
*/
void startMultiPlayerGame();
/**
* \brief Connects the signals which are common to both single and multiplayer games
*/
void connectCommonSignals();
/**
* \brief Connects the signals required for singleplayer game
*/
void connectSignalsForSinglePlayerGame();
/**
* \brief Connects the signals required for multiplayer game
*/
void connectSignalsForMultiPlayerGame();
// member variables
/**
* \brief timer
* Used for updating the player position and score
*/
QTimer* timer;
/**
* \brief scene
*/
QGraphicsScene* scene;
/**
* \brief Background music
*/
BackgroundMusic* backgroundMusic;
/**
* \brief Background updater
* Object which is called by timer to update the background
*/
BackgroundUpdater* backgroundUpdater;
/**
* \brief Noob Set
*/
NoobSet* noobSet;
/**
* \brief Set 1
*/
Set1* set1;
/**
* \brief Set 2
*/
Set2* set2;
/**
* \brief Type of the Game
* Can either be GAMETYPE::SINGLEPLAYER or GAMETYPE::MULTIPLAYER
*/
GameType gameType;
/**
* \brief State of the Game
* Can either be GAMESTATE::PLAYING or GAMESTATE::PAUSED or GAMESTATE::FINISHED
*/
GameState gameState;
/**
* \brief Information regarding the player
*/
Player* player[2];
/**
* \brief Player to character Mapping
* Vector representing the indices of characters chosen by the user
*/
std::vector <int> playerID;
/**
* \brief Images
* Image of the Player
*/
QPixmap images[2];
/**
* \brief Display Image
* Image to be displayed near the score
*/
QLabel* displayImage;
/**
* \brief Score Updater
* Object to store/update the score
*/
ScoreUpdater* scoreUpdater;
/**
* \brief Thread For 1st Player
* Operations on the first player are performed in this thread
*/
QThread* threadForPlayer1;
/**
* \brief Thread for 2nd Player
* Operations on the second player are performed in this thread
*/
QThread* threadForPlayer2;
/**
* \brief Worker Object for 1st Thread
* Worker Function to be executed on the 1st thread
*/
RunPlayerWorker* workerForPlayer1;
/**
* \brief Worker Object for 2nd Thread
* Worker Function to be executed on the 2nd thread
*/
RunPlayerWorker* workerForPlayer2;
/**
* \brief Pause Button
*/
QPushButton* pauseButton;
/**
* \brief Resume Button
*/
QPushButton* resumeButton;
/**
* \brief Shift in x per 10 milli seconds
*/
int xShift;
/**
* \brief Shift in y per 10 milli seconds
*/
int yShift;
public slots:
/**
* \brief Regenerate the set
* \param Index of the set
*/
void reincarnateSet(int);
private slots:
/**
* \brief Slot to pause the game
*/
void handlePauseGame();
/**
* \brief Slot to resume the game
*/
void handleResumeGame();
signals:
/**
* \brief Send a request to flip the player
*/
void requestFlipPlayerUpdate(Player* player);
/**
* \brief Send a request to flip player 1
*/
void requestFlipPlayerUpdateForPlayer1(Player* player);
/**
* \brief Send a request to flip player 2
*/
void requestFlipPlayerUpdateForPlayer2(Player* player);
};
#endif // GAME_H