-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.h
More file actions
147 lines (121 loc) · 3.52 KB
/
Copy pathmainwindow.h
File metadata and controls
147 lines (121 loc) · 3.52 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
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <QElapsedTimer>
#include <QPainter>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QtMultimedia/QSoundEffect>
#include <QPixmap>
#include <QFont>
#include <QFontDatabase>
#include <QPointF>
#include <QRandomGenerator>
#include <QList>
#include <QVector>
#include <QUrl>
#include <QMessageBox>
#include <QImage>
#include <QTemporaryFile>
#include <QFile>
#include "camera.h"
#include "bullet.h"
#include "chicken.h"
#include "atlas.h"
#include "animation.h"
#include "timer.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
// 表情类型枚举
enum class EmotionType {
GRINNING, // 开心
SOB, // 悲伤
RAGE, // 愤怒
ASTONISHED, // 惊讶
SCREAM // 尖叫
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
protected:
void paintEvent(QPaintEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void closeEvent(QCloseEvent *event) override;
private slots:
void updateGame();
public:
void loadResources();
void unloadResources();
void checkCollisions();
void fireWeapon();
void gameOver();
// 表情识别相关功能
void setupEmotionDetection();
void loadEmotionEmojis();
void createEmotionChicken();
void clearChickensWithMatchingEmotion();
// 扫雷游戏相关功能
void calculateAdjacentMines(); // 计算每个小鸡周围的地雷数
void handleMineChickenHit(); // 处理击中地雷小鸡的情况
void updateMineNumbers(); // 更新所有小鸡周围的地雷数
void createMinePeckerChicken(); // 创建小鸡,随机设置为地雷
Ui::MainWindow *ui;
QTimer *gameTimer;
QElapsedTimer frameTimer;
// 游戏资源
Camera *camera;
QPixmap texHeart;
QPixmap texBullet;
QPixmap texBattery;
QPixmap texCrosshair;
QPixmap texBackground;
QPixmap texBarrelIdle;
QPixmap texMineWarning;
Atlas m_atlasBarrelFire;
Atlas m_atlasChickenFast;
Atlas m_atlasChickenMedium;
Atlas m_atlasChickenSlow;
Atlas m_atlasExplosion;
QSoundEffect *soundBgm;
QSoundEffect *soundLoss;
QSoundEffect *soundHurt;
QSoundEffect *soundFire1;
QSoundEffect *soundFire2;
QSoundEffect *soundFire3;
// 游戏状态
int hp = 10;
int score = 0;
QList<Bullet*> bulletList;
QList<Chicken*> chickenList;
int numPerGen = 2;
Timer *timerGenerate;
Timer *timerIncreaseNumPerGen;
QPointF posCrosshair;
double angleBarrel = 0;
const QPointF posBattery{640, 600};
const QPointF posBarrel{592, 585};
const QPointF centerBarrel{48, 25};
bool isCoolDown = true;
bool isFireKeyDown = false;
Animation animationBarrelFire;
QFont gameFont;
bool isQuit = false;
// 表情相关成员
QMap<EmotionType, QPixmap> emotionEmojis;
EmotionType currentPlayerEmotion = EmotionType::GRINNING;
QPixmap currentEmotionDisplay;
QTimer* emotionDetectionTimer = nullptr;
QImage webcamImage; // 用于显示摄像头图像
// 扫雷游戏相关
bool gameModeMineField = true; // 是否启用扫雷模式
float mineChickenProbability = 0.2; // 小鸡成为地雷的概率(20%)
};
#endif // MAINWINDOW_H