-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.h
217 lines (165 loc) · 4.47 KB
/
mainwindow.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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include <QPainter>
#include <QPushButton>
#include <math.h>
#include "initialize.h"
#include "controller.h"
// 游戏初始界面
// 有4个buttons:Start Game, Load Game, Customize Map, Quit
class StartWindow : public QWidget
{
Q_OBJECT
public:
StartWindow(QWidget *parent = nullptr);
~StartWindow() {}
void setCustomizeEntryMode();
private:
QPushButton* startGameButton;
QPushButton* loadGameButton;
QPushButton* customizeMapButton;
QPushButton* quitButton;
signals:
void enterCustomizeMode();
};
// 初始界面点击start后的选择模式界面
// 有4个buttons:SOLO, PVP, PVE, Return to Menu
class ChooseModeWindow : public QWidget
{
Q_OBJECT
public:
ChooseModeWindow(QWidget *parent = nullptr);
~ChooseModeWindow() {}
private:
QPushButton* singlePlayerButton;
QPushButton* twoPlayerButton;
QPushButton* fightComputerButton;
QPushButton* return2MenuButton;
};
// 游戏暂停界面
// 有5个buttons:Resume, Restart, Save Game, Customize Map, Return to Menu
class PauseWindow : public QWidget
{
Q_OBJECT
public:
PauseWindow(QWidget *parent = nullptr);
~PauseWindow() {}
void setCustomizeEntryMode();
void return2Menu();
private:
QPushButton* resumeButton;
QPushButton* restartButton;
QPushButton* saveGameButton;
QPushButton* customizeMapButton;
QPushButton* return2MenuButton;
signals:
void enterCustomizeMode();
void pauseReturn2Menu();
};
// 自定义地图界面
// 有1个button:Return to Menu
class CustomizeMapWindow : public QWidget
{
Q_OBJECT
public:
CustomizeMapWindow(QWidget *parent = nullptr);
~CustomizeMapWindow() {}
void endEditing();
DISPLAYMODE entryMode;
protected:
void paintEvent(QPaintEvent* ) override;
void mousePressEvent(QMouseEvent *event) override;
signals:
void paint(QPainter &painter);
void changeBlock(POINT &p);
void changeFood(POINT &p);
};
// 游戏中界面
class PlayWindow : public QWidget
{
Q_OBJECT
public:
PlayWindow(QWidget *parent = nullptr);
~PlayWindow() {}
static int fps;
void setPlayMode(PLAYMODE m);
void keyPressed(QKeyEvent *event);
void setTitle(int sec);
void setReady();
void restartGame();
void resetMap();
void paint(QPainter &painter);
void changeBlock(POINT &p);
void changeFood(POINT &p);
void saveGame();
void loadGame();
protected:
// void keyPressEvent(QKeyEvent *event) override;
void paintEvent(QPaintEvent* ) override;
private:
Controller* controller;
PLAYMODE playMode;
signals:
void setMainTitle(QString s);
};
//游戏结算界面
// 有1个button:Return to Menu
class EndGameWindow : public QWidget
{
Q_OBJECT
public:
EndGameWindow(QWidget *parent = nullptr);
~EndGameWindow() {}
int loser = 0;
PLAYMODE playMode = SOLO;
private:
QPushButton* return2MenuButton;
protected:
void paintEvent(QPaintEvent* ) override;
};
// 主界面
// 有5个子界面:startWindow, chooseModeWindow, pauseWindow, customizeMapWindow, playWindow
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow() {}
// press button后切换显示界面,用connect函数调用
void showStartWindow();
void showChooseModeWindow();
void showPauseWindow();
void showCustomizeMapWindow();
void showPlayWindow();
void showEndGameWindow(int l, PLAYMODE mode);
void paint(QPainter &painter);
void changeBlock(POINT &p);
void changeFood(POINT &p);
void restartGame();
void sendQuitGame();
void pauseEnterCustomize();
void startEnterCustomize();
void pauseReturn2Menu();
void setSOLO();
void setPVE();
void setPVP();
void saveGame();
void loadGame();
static int width;
static int height;
protected:
void keyPressEvent(QKeyEvent *event) override;
private:
DISPLAYMODE displayMode;
StartWindow* startWindow;
ChooseModeWindow* chooseModeWindow;
PauseWindow* pauseWindow;
CustomizeMapWindow* customizeMapWindow;
EndGameWindow* endGameWindow;
PlayWindow* playWindow;
signals:
void quitGame();
};
#endif // MAINWINDOW_H