2023-06-28 22:57:03 +08:00
|
|
|
#ifndef MAINWIDGET_H
|
|
|
|
#define MAINWIDGET_H
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
namespace Ui { class MainWidget; }
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
class MainWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
MainWidget(QWidget *parent = nullptr);
|
|
|
|
~MainWidget();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ui::MainWidget *ui;
|
|
|
|
QPixmap switchImgs(int); // 切换电脑图片函数
|
|
|
|
|
|
|
|
private:
|
|
|
|
int randNum; // 电脑出招映射的随机数 0, 1, 2
|
|
|
|
int playerInputNum; // 玩家点击的按钮映射的数值 0, 1, 2
|
|
|
|
QTimer *timer; // 计时器
|
2023-06-29 10:12:24 +08:00
|
|
|
// QPixmap *randImg; // 随机的电脑出招图片
|
2023-06-28 22:57:03 +08:00
|
|
|
int numsOfGame; // 游戏次数
|
|
|
|
int currentScore; // 当前得分
|
2023-06-29 10:12:24 +08:00
|
|
|
QPixmap *rockImg; // 拳头
|
|
|
|
QPixmap *paperImg; // 布
|
|
|
|
QPixmap *scissorsImg; // 剪刀
|
2023-06-28 22:57:03 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
// 定义枚举: 0-拳、1-布、2-剪刀
|
|
|
|
enum{
|
|
|
|
rock,
|
|
|
|
paper,
|
|
|
|
scissors
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void on_startGameBtn_clicked();
|
|
|
|
void on_rockBtn_clicked();
|
|
|
|
void on_paperBtn_clicked();
|
|
|
|
void on_scissorsBtn_clicked();
|
|
|
|
void on_clearBtn_clicked();
|
|
|
|
};
|
|
|
|
#endif // MAINWIDGET_H
|