This repository was archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayout.cpp
More file actions
294 lines (261 loc) · 7.55 KB
/
Layout.cpp
File metadata and controls
294 lines (261 loc) · 7.55 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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include "Layout.h"
#include "ui_Layout.h"
#include "GameStructure.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFont>
#include <QString>
#include <QMessageBox>
#include <QDebug>
Layout::Layout(QWidget *parent) :
QWidget(parent),
ui(new Ui::Layout)
{
ui->setupUi(this);
//设置字体
font = QFont("UTF-8", 20, 5);
//设置大小
//初始化进度条
progressbar=new QProgressBar;
progressbar->setMinimum(0);
progressbar->setMaximum(200);
//创建暂停按钮
stopButton=new QPushButton;
stopButton->setFont(font);
stopButton->setEnabled(true);
stopButton->setText(QString("停止"));
stopButton->hide();
//初始化计时器
counter=new QTimer(this);
//初始化Qlabel
hurryPic_1=QPixmap(":/new/prefix4/others/timg_opaque.png");
hurryLabel_1=new QLabel(this);
hurryLabel_1->setPixmap(hurryPic_1);
hurryLabel_1->setFixedSize(100,80);
hurryLabel_1->setScaledContents(true);
hurryLabel_1->move(650,20);
hurryLabel_1->hide();
hurryPic_2=QPixmap(":/new/prefix4/others/time_opaque2.png");
hurryLabel_2=new QLabel(this);
hurryLabel_2->setPixmap(hurryPic_2);
hurryLabel_2->setFixedSize(100,80);
hurryLabel_2->setScaledContents(true);
hurryLabel_2->move(650,20);
hurryLabel_2->hide();
//设置开始、结束按钮
startButton=new QPushButton;
startButton->setFont(font);
startButton->setEnabled(true);
endButton=new QPushButton;
endButton->setFont(font);
startButton->setText(QString("出发"));
endButton->setText(QString("结束"));
endButton->setEnabled(false);
//设置提示、洗牌按钮
hintButton=new HintButton;
hintButton->setFont(font);
shuffleButton=new ShuffleButton;
shuffleButton->setFont(font);
//设置左布局
leftLayout = new QVBoxLayout;
game = new GameStructure;
leftLayout->addWidget(game);
leftLayout->addWidget(progressbar);
//设置右布局
rightLayout = new QVBoxLayout;
rightLayout->addWidget(startButton);
rightLayout->addWidget(endButton);
rightLayout->addWidget(hintButton);
rightLayout->addWidget(shuffleButton);
//设置总体布局
wholeLayout = new QHBoxLayout(this);
wholeLayout->addLayout(leftLayout);
wholeLayout->addLayout(rightLayout);
wholeLayout->setSpacing(10);
//连接
connect(startButton,SIGNAL(clicked(bool)),game,SLOT(new_game()));
connect(endButton,SIGNAL(clicked()),game,SLOT(gameEnd()));
connect(stopButton,SIGNAL(clicked(bool)),this,SLOT(replayStop()));
connect(game,SIGNAL(gameIsOn(int,int,int)),this,SLOT(gameStartSet(int,int,int)));
connect(game, SIGNAL(gameIsOver()),this,SLOT(gameEndSet()));
connect(game,SIGNAL(removeOnePair()),this,SLOT(incProgressBar()));
connect(game,SIGNAL(removeOnePair()),this,SLOT(gameCopy()));
connect(hintButton, SIGNAL(clicked()), game, SLOT(showHint()));
connect(shuffleButton, SIGNAL(clicked()), game, SLOT(shuffleUntilExist()));
connect(this,SIGNAL(progressBarIsZero()),game,SLOT(gameEnd()));
connect(counter,SIGNAL(timeout()),this,SLOT(runProgressBar()));
}
Layout::~Layout()
{
delete ui;
}
void Layout::gameStartSet(int rest_time, int rest_hint, int rest_shuffle)
{
//删除链表
// qDebug()<<"before delete link_list in gameStartSet";
while(node_start)
{
node_end=node_start->next;
delete node_start;
node_start=node_end;
}
// qDebug()<<"finish!";
qDebug()<<"rest_time:"<<rest_time;
if(rest_time>=0)
{
progressbar->setValue(rest_time);
}
else
progressbar->setValue(progressbar->maximum());
startButton->setEnabled(false);
endButton->setEnabled(true);
hintButton->hintStart(rest_hint);
shuffleButton->shuffleStart(rest_shuffle);
counter->start(300);
}
void Layout::gameEndSet()
{
if(!replayStat)
{
if(QMessageBox::question(this,"兄弟","回放录像吗?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
replay();
}
// qDebug()<<"5";
//删除链表
while(node_start)
{
node_end=node_start->next;
delete node_start;
node_start=node_end;
}
// qDebug()<<"6";
startButton->setEnabled(true);
endButton->setEnabled(false);
hintButton->hintEnd();
shuffleButton->shuffleEnd();
counter->stop();
progressbar->setValue(progressbar->maximum());
replayStat=0;
game->setGameStat(false);
//qDebug()<<"7";
}
void Layout::runProgressBar()
{
progressbar->setValue(progressbar->value()-1);
if(progressbar->value()<=0)
{
emit progressBarIsZero();
return;
}
if(progressbar->value()==180)
hurryLabel_1->show();
if(progressbar->value()<=175)
hurryLabel_1->hide();
if(progressbar->value()==190)
hurryLabel_2->show();
if(progressbar->value()<=185)
hurryLabel_2->hide();
}
void Layout::incProgressBar()
{
for(int i=0;i<20;i++)
progressbar->setValue(progressbar->value()+1);
}
bool Layout::gameSave(int i)
{
counter->stop();
bool ret = game->gameSave( i, progressbar->value(),hintButton->getTimes(),shuffleButton->getTimes());
if(ret) counter->start(300);
return ret;
}
bool Layout::gameLoad(int i)
{
return game->gameLoad(i);
}
//void Layout::replayStartSet()
//{
// endButton->setEnabled(true);
// startButton->setEnabled(false);
// hintButton->setEnabled(false);
// shuffleButton->setEnabled(false);
// progressbar->setValue(progressbar->maximum());
// counter->stop();
//}
replay_single* Layout::createNode()
{
//qDebug()<<"start creating node";
replay_single *node=new replay_single(this,game);
return node;
}
void Layout::gameCopy()
{
if(!node_start)
{
node_start=createNode();
node_end=node_start;
}
else
{
node_end->next=createNode();
node_end=node_end->next;
}
}
void Layout::replay()
{
if(!node_start) return;
replayStat=1;
stopButtonStat=0;
endButton->setEnabled(false);
startButton->setEnabled(false);
hintButton->setEnabled(false);
shuffleButton->setEnabled(false);
progressbar->setValue(progressbar->maximum());
counter->stop();
// startButton=new QPushButton;
// startButton->setFont(font);
// startButton->setEnabled(true);
// endButton=new QPushButton;
// endButton->setFont(font);
// startButton->setText(QString("出发"));
// endButton->setText(QString("结束"));
// endButton->setEnabled(false);
stopButton->show();
rightLayout->addWidget(stopButton);
game_now=game;
leftLayout->removeWidget(game);
leftLayout->removeWidget(progressbar);
node_end=node_start;
game=&node_start->gamePicture;
while(node_end)
{
leftLayout->addWidget(game);
leftLayout->addWidget(progressbar);
game->show();
//延时1s
QTime t;
t.start();
while(t.elapsed()<1000)
QCoreApplication::processEvents();
if(stopButtonStat)
break;
game->hide();
node_end=node_end->next;
game=&node_end->gamePicture;
}
leftLayout->removeWidget(game);
leftLayout->removeWidget(progressbar);
game=game_now;
leftLayout->addWidget(game);
leftLayout->addWidget(progressbar);
stopButton->hide();
rightLayout->removeWidget(stopButton);
replayStat=0;
stopButtonStat=0;
if(QMessageBox::question(this,"提示","再看一遍吗",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
replay();
return;
}
void Layout::replayStop()
{
stopButtonStat=1;
}