-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
93 lines (85 loc) · 2.55 KB
/
widget.cpp
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
#include "widget.h"
#include "ui_widget.h"
#ifdef DEBUG
#include <QDebug>
#endif //DEBUG
#include "gamemodel.h"
#include <QPainter>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
//scoreWidget = nullptr;
ui->setupUi(this);
setMinimumSize(playWidget.size());
playWidget.setParent(this); //设置游戏界面
playWidget.hide(); //设置隐藏
int cx = (width() - playWidget.width()) / 2;
int cy = (height() - playWidget.height()) / 2;
playWidget.move(cx, cy);
//评分界面
scoreWidget = new ScoreWidget(playWidget.size(), this);
scoreWidget->hide();
//设置按钮
connect(ui->pushButton_pvp, &QPushButton::clicked, //PVP
[this]()
{
playWidget.show();
ui->StartWidget->hide();
playWidget.gameWidget.initGame(PVP);
}
);
connect(ui->pushButton_pve, &QPushButton::clicked, //PVE
[this]()
{
playWidget.show();
ui->StartWidget->hide();
playWidget.gameWidget.initGame(PVE);
}
);
connect(&playWidget.gameWidget, &GameWidget::winSignal, //WIN
[this](int winPlayer)
{
int cx = (width() - scoreWidget->width()) / 2;
int cy = (height() - scoreWidget->height()) / 2;
scoreWidget->move(cx, cy);
scoreWidget->setLabel(winPlayer);
scoreWidget->show();
}
);
connect(scoreWidget, &ScoreWidget::againSignal, //AGAIN
[this]()
{
playWidget.gameWidget.again();
scoreWidget->hide();
}
);
connect(scoreWidget, &ScoreWidget::homeSignal, //HOME
[this]()
{
playWidget.hide();
playWidget.gameWidget.endGame();
scoreWidget->hide();
ui->StartWidget->show();
}
);
}
void Widget::resizeEvent(QResizeEvent *event) //重写调整窗口事件
{
Q_UNUSED(event);
int cx = (width() - playWidget.width()) / 2;
int cy = (height() - playWidget.height()) / 2;
playWidget.move(cx, cy);
if(scoreWidget == nullptr) return;
cx = (width() - scoreWidget->width()) / 2;
cy = (height() - scoreWidget->height()) / 2;
scoreWidget->move(cx, cy);
#ifdef DEBUG
qDebug() << cx << cy;
#endif //DEBUG
}
Widget::~Widget()
{
delete ui;
delete scoreWidget;
}