-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
620 lines (578 loc) · 25.1 KB
/
mainwindow.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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
#include "mainwindow.h"
#include "ui_mainwindow.h"
static int paint_flag = 0;
QPainter * paintmywindow;
MainWindow * app;
int ROW =9;
int COL =9;
int BOOMNUM = 10;
block * mine = new block(ROW,COL,BOOMNUM);
int click_x,click_y,end = 0,timeend=1;
int LENGTH=mine->getcol()*21;
int HEIGHT=mine->getrow()*21 + TITILE_HEIGH;
static bool showimage = 1;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
app = this;
ui->setupUi(this);
this->setFixedSize(LENGTH, HEIGHT);
runtime = new QTimer(this);
connect(runtime,SIGNAL(timeout()),this,SLOT(on_secondadd()));
connect(runtime,SIGNAL(timeout()),this,SLOT(update()));
this->setWindowTitle("QMineSweeper");
this->setWindowIcon(QIcon(":/image/image/langong.png"));
QMenuBar *menubar = new QMenuBar(this);
this->setMenuBar(menubar);
QMenu *gamemenu = new QMenu("Game",menubar);
QAction *pgame = new QAction("Easy");
QAction *mgame = new QAction("Middle");
QAction *sgame = new QAction("Hard");
QAction *ugame = new QAction("Customize");
QAction *quit = new QAction("Quit");
connect(pgame, SIGNAL(triggered()), this, SLOT(Easy_triggered()));
connect(mgame, SIGNAL(triggered()), this, SLOT(Middle_triggered()));
connect(sgame, SIGNAL(triggered()), this, SLOT(Hard_triggered()));
connect(ugame, SIGNAL(triggered()), this, SLOT(Customize_triggered()));
connect(quit, SIGNAL(triggered()), this, SLOT(Exit_triggered()));
gamemenu->addAction(pgame);
gamemenu->addAction(mgame);
gamemenu->addAction(sgame);
gamemenu->addAction(ugame);
gamemenu->addAction(quit);
QMenu *aboutmenu = new QMenu("About", menubar);
QAction *aboutact = new QAction("About");
QAction *aboutqtact = new QAction("About Qt");
connect(aboutact, SIGNAL(triggered()), this, SLOT(About_triggered()));
connect(aboutqtact, SIGNAL(triggered()), this, SLOT(AboutQT_triggered()));
aboutmenu->addAction(aboutact);
aboutmenu->addAction(aboutqtact);
menubar->addMenu(gamemenu);
menubar->addMenu(aboutmenu);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
// Mouse Click
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
click_x = event->position().x();
click_y = event->position().y();
#else
click_x = event->x();
click_y = event->y();
#endif
if(event->buttons()==(Qt::LeftButton)&&(click_x>(int)LENGTH*100/200-11)&&
(click_x<(int)LENGTH*100/200+11 +EXPRESSION_LENGHT)&&(click_y>7+TTILE_BEGIN)&&
(click_y<7+TTILE_BEGIN+EXPRESSION_HEIGH))
{
restart(mine->getrow(),mine->getcol(),mine->getboomNum());
paint_flag = 0;
end = 0;
timeend = 1;
runtime->stop();
update();
return;
}
else if( click_y<TITILE_HEIGH ) return;
if(end==1)
return ;
// Check positon
click_x = click_x/BLOCK_LENGTH;
click_y = (click_y-TITILE_HEIGH)/BLOCK_HEIGH;
if(event->buttons()==(Qt::LeftButton))
{
if(timeend==1)
{
runtime->start(1000);
}
if(mine->p[click_y][click_x]==99)
{
// Clicked boom!
paint_flag = 4;
end = 1;
timeend=1;
runtime->stop();
update();
}
else if((mine->p[click_y][click_x]<10))
{
// DFS
showblock(click_y,click_x);
paint_flag = 2;
if (iswin() == 1)
{
end = 1;
}
else
{
end = 0;
}
if (end)
// if(end = iswin()==1)
{
paint_flag = 5;
timeend=1;
runtime->stop();
}
update();
if(end)
{
if(showimage)
{
QMessageBox message(QMessageBox::NoIcon, "You Win!", "Well done! I really appreciate you!");
message.setIconPixmap(QPixmap(":/image/image/win.png"));
showimage = !showimage;
message.exec();
}
else
{
QMessageBox message(QMessageBox::NoIcon, "You Win!", "I will give you a red flower!");
message.setIconPixmap(QPixmap(":/image/image/good.png"));
showimage = !showimage;
message.exec();
}
}
}
else return;
}
else if(event->buttons()==(Qt::RightButton))
{
// Right Click
if((mine->p[click_y][click_x]<10)||(mine->p[click_y][click_x]==99))
{
mine->p[click_y][click_x] = mine->p[click_y][click_x] +50;
mine->minusredFlagNum();
}
else if((mine->p[click_y][click_x]>=50&&mine->p[click_y][click_x]<60)||(mine->p[click_y][click_x]>110))
{
mine->p[click_y][click_x] = mine->p[click_y][click_x] -50;
mine->addredFlagNum();
}
paint_flag = 3;
if (iswin() == 1)
{
end = 1;
}
else
{
end = 0;
}
if (end)
// if(end = iswin()==1)
{
paint_flag = 5;
timeend=1;
runtime->stop();
}
update();
if(end)
{
if(showimage)
{
QMessageBox message(QMessageBox::NoIcon, "You Win!", "Well done! I really appreciate you!");
message.setIconPixmap(QPixmap(":/image/image/win.png"));
showimage = !showimage;
message.exec();
}
else
{
QMessageBox message(QMessageBox::NoIcon, "You Win!", "I will give you a red flower!");
message.setIconPixmap(QPixmap(":/image/image/good.png"));
showimage = !showimage;
message.exec();
}
}
}
}
//绘图事件
void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
paintmywindow = &painter;
// Load images
QPixmap mine_title(":/image/image/mine_title.bmp");
QPixmap block_close(":/image/image/block_close.bmp");
QPixmap block_open(":/image/image/block_open.bmp");
QPixmap red_flag(":/image/image/redflag.bmp");
QPixmap keil_boom(":/image/image/keilboom.bmp");
QPixmap click_boom(":/image/image/clickboom.bmp");
QPixmap boom(":/image/image/boom.bmp");
QPixmap qq_smile(":/image/image/smile.bmp");
QPixmap qq_lose(":/image/image/lose.bmp");
QPixmap qq_pround(":/image/image/proud.bmp");
QPixmap ele_0(":/image/image/ele0.bmp");
QPixmap ele_1(":/image/image/ele1.bmp");
QPixmap ele_2(":/image/image/ele2.bmp");
QPixmap ele_3(":/image/image/ele3.bmp");
QPixmap ele_4(":/image/image/ele4.bmp");
QPixmap ele_5(":/image/image/ele5.bmp");
QPixmap ele_6(":/image/image/ele6.bmp");
QPixmap ele_7(":/image/image/ele7.bmp");
QPixmap ele_8(":/image/image/ele8.bmp");
QPixmap ele_9(":/image/image/ele9.bmp");
QPixmap blk_1(":/image/image/blk1.bmp");
QPixmap blk_2(":/image/image/blk2.bmp");
QPixmap blk_3(":/image/image/blk3.bmp");
QPixmap blk_4(":/image/image/blk4.bmp");
QPixmap blk_5(":/image/image/blk5.bmp");
QPixmap blk_6(":/image/image/blk6.bmp");
QPixmap blk_7(":/image/image/blk7.bmp");
QPixmap blk_8(":/image/image/blk8.bmp");
// Init
if(paint_flag==0)
{
painttitle(paintmywindow);
for(int i = 0;i<mine->getcol()*BLOCK_LENGTH;i=i+BLOCK_LENGTH)
for(int j =TITILE_HEIGH;j<TITILE_HEIGH+mine->getrow()*BLOCK_HEIGH;j=j+BLOCK_HEIGH)
painter.drawPixmap(i,j,block_close,0,0,BLOCK_LENGTH,BLOCK_LENGTH);
}
else if (paint_flag == 4)
{
painttitle(paintmywindow);
for(int i = 0;i<mine->getrow();i++)
{
for(int j = 0;j<mine->getcol();j++ )
{
if((mine->p[i][j]<10))
{
painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,block_close,0,0,BLOCK_LENGTH,BLOCK_HEIGH);
}
else if((mine->p[i][j]==99))
{
painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,boom,0,0,BLOCK_LENGTH,BLOCK_HEIGH);
}
else if (mine->p[i][j]>110)
{
painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,red_flag,0,0,BLOCK_LENGTH,BLOCK_HEIGH);
}
else if ((mine->p[i][j]<60)&&(mine->p[i][j]>=50))
{
painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,keil_boom,0,0,BLOCK_LENGTH,BLOCK_HEIGH);
}
else if ((mine->p[i][j])>99&&(mine->p[i][j]<110))
{
int blk_num = mine->p[i][j] - 100;
switch (blk_num)
{
case 0: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,block_open,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 1: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_1,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 2: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_2,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 3: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_3,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 4: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_4,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 5: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_5,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 6: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_6,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 7: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_7,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 8: painter.drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_8,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
}
}
}
}
painter.drawPixmap(click_x*BLOCK_LENGTH,click_y*BLOCK_HEIGH+TITILE_HEIGH,click_boom,0,0,BLOCK_LENGTH,BLOCK_HEIGH);
}
else if (paint_flag == 2 )
{
painttitle(paintmywindow);
paintboom(paintmywindow);
}
else if(paint_flag ==3)
{
painttitle(paintmywindow);
paintboom(paintmywindow);
}
else if(paint_flag == 5)
{
painttitle(paintmywindow);
paintboom(paintmywindow);
}
}
void showblock(int x,int y)
{
for(int blockRow = x - 1; blockRow <=x + 1;blockRow++)
for(int blockCol = y - 1;blockCol <=y + 1;blockCol++)
{
if(blockRow<0||blockCol<0||blockRow>=mine->getrow()||blockCol>=mine->getcol())
continue;
if(mine->p[blockRow][blockCol]<10)
{
mine->p[blockRow][blockCol] = mine->p[blockRow][blockCol] + 100;
if(mine->p[blockRow][blockCol]==100)
showblock(blockRow,blockCol);
}
}
}
int iswin()
{
int cnt = 0;
for(int row = 0; row <mine->getrow();row++)
for(int col =0;col<mine->getcol();col++)
{
if((mine->p[row][col]>=100)&&(mine->p[row][col]<110))
cnt++;
}
if(cnt>=((mine->getcol()*mine->getrow())-mine->getboomNum()))
return 1;
else
return 0;
}
void restart(int row,int col,int boolnum)
{
mine = new block (row,col,boolnum);
}
void painttitle(QPainter * painter)
{
QPixmap mine_title(":/image/image/mine_title.bmp");
QPixmap block_close(":/image/image/block_close.bmp");
QPixmap block_open(":/image/image/block_open.bmp");
QPixmap red_flag(":/image/image/redflag.bmp");
QPixmap keil_boom(":/image/image/keilboom.bmp");
QPixmap click_boom(":/image/image/clickboom.bmp");
QPixmap boom(":/image/image/boom.bmp");
QPixmap qq_smile(":/image/image/smile.bmp");
QPixmap qq_lose(":/image/image/lose.bmp");
QPixmap qq_pround(":/image/image/proud.bmp");
QPixmap ele_0(":/image/image/ele0.bmp");
QPixmap ele_1(":/image/image/ele1.bmp");
QPixmap ele_2(":/image/image/ele2.bmp");
QPixmap ele_3(":/image/image/ele3.bmp");
QPixmap ele_4(":/image/image/ele4.bmp");
QPixmap ele_5(":/image/image/ele5.bmp");
QPixmap ele_6(":/image/image/ele6.bmp");
QPixmap ele_7(":/image/image/ele7.bmp");
QPixmap ele_8(":/image/image/ele8.bmp");
QPixmap ele_9(":/image/image/ele9.bmp");
QPixmap ele_10(":/image/image/ele10.bmp");
QPixmap blk_1(":/image/image/blk1.bmp");
QPixmap blk_2(":/image/image/blk2.bmp");
QPixmap blk_3(":/image/image/blk3.bmp");
QPixmap blk_4(":/image/image/blk4.bmp");
QPixmap blk_5(":/image/image/blk5.bmp");
QPixmap blk_6(":/image/image/blk6.bmp");
QPixmap blk_7(":/image/image/blk7.bmp");
QPixmap blk_8(":/image/image/blk8.bmp");
mine_title = mine_title.scaled(QSize(LENGTH,40));
painter->drawPixmap(0,TTILE_BEGIN,mine_title,0,0,1000,1000);
if(paint_flag == 4)
painter->drawPixmap((int)LENGTH*100/200-11,7+TTILE_BEGIN,qq_lose,0,0,1000,1000);
else if (paint_flag == 5)
painter->drawPixmap((int)LENGTH*100/200-11,7+TTILE_BEGIN,qq_pround,0,0,1000,1000);
else
painter->drawPixmap((int)LENGTH*100/200-11,7+TTILE_BEGIN,qq_smile,0,0,1000,1000);
int redflagnum = mine->getredFlagNum();
if(redflagnum<0)
{
redflagnum = -redflagnum;
painter->drawPixmap((int)(LENGTH*40)/200-30,5+TTILE_BEGIN,ele_10,0,0,1000,1000);
}
else painter->drawPixmap((int)(LENGTH*40)/200-30,5+TTILE_BEGIN,ele_0,0,0,1000,1000);
switch(redflagnum/10)
{
case 0: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_0,0,0,1000,1000);break;
case 1: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_1,0,0,1000,1000);break;
case 2: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_2,0,0,1000,1000);break;
case 3: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_3,0,0,1000,1000);break;
case 4: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_4,0,0,1000,1000);break;
case 5: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_5,0,0,1000,1000);break;
case 6: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_6,0,0,1000,1000);break;
case 7: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_7,0,0,1000,1000);break;
case 8: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_8,0,0,1000,1000);break;
case 9: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_9,0,0,1000,1000);break;
}
switch (redflagnum%10)
{
case 0: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_0,0,0,1000,1000);break;
case 1: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_1,0,0,1000,1000);break;
case 2: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_2,0,0,1000,1000);break;
case 3: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_3,0,0,1000,1000);break;
case 4: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_4,0,0,1000,1000);break;
case 5: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_5,0,0,1000,1000);break;
case 6: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_6,0,0,1000,1000);break;
case 7: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_7,0,0,1000,1000);break;
case 8: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_8,0,0,1000,1000);break;
case 9: painter->drawPixmap((int)(LENGTH*40)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_9,0,0,1000,1000);break;
}
int timenum = mine->gettimeNum();
switch (timenum/100)
{
case 0: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_0,0,0,1000,1000);break;
case 1: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_1,0,0,1000,1000);break;
case 2: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_2,0,0,1000,1000);break;
case 3: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_3,0,0,1000,1000);break;
case 4: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_4,0,0,1000,1000);break;
case 5: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_5,0,0,1000,1000);break;
case 6: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_6,0,0,1000,1000);break;
case 7: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_7,0,0,1000,1000);break;
case 8: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_8,0,0,1000,1000);break;
case 9: painter->drawPixmap((int)(LENGTH*163)/200-30,5+TTILE_BEGIN,ele_9,0,0,1000,1000);break;
}
switch (timenum/10)
{
case 0: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_0,0,0,1000,1000);break;
case 1: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_1,0,0,1000,1000);break;
case 2: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_2,0,0,1000,1000);break;
case 3: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_3,0,0,1000,1000);break;
case 4: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_4,0,0,1000,1000);break;
case 5: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_5,0,0,1000,1000);break;
case 6: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_6,0,0,1000,1000);break;
case 7: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_7,0,0,1000,1000);break;
case 8: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_8,0,0,1000,1000);break;
case 9: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT,5+TTILE_BEGIN,ele_9,0,0,1000,1000);break;
}
switch (timenum%10)
{
case 0: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_0,0,0,1000,1000);break;
case 1: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_1,0,0,1000,1000);break;
case 2: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_2,0,0,1000,1000);break;
case 3: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_3,0,0,1000,1000);break;
case 4: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_4,0,0,1000,1000);break;
case 5: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_5,0,0,1000,1000);break;
case 6: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_6,0,0,1000,1000);break;
case 7: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_7,0,0,1000,1000);break;
case 8: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_8,0,0,1000,1000);break;
case 9: painter->drawPixmap((int)(LENGTH*163)/200-30+ELENUM_LENGHT+ELENUM_LENGHT,5+TTILE_BEGIN,ele_9,0,0,1000,1000);break;
}
}
void paintboom(QPainter * painter)
{
QPixmap mine_title(":/image/image/mine_title.bmp");
QPixmap block_close(":/image/image/block_close.bmp");
QPixmap block_open(":/image/image/block_open.bmp");
QPixmap red_flag(":/image/image/redflag.bmp");
QPixmap keil_boom(":/image/image/keilboom.bmp");
QPixmap click_boom(":/image/image/clickboom.bmp");
QPixmap boom(":/image/image/boom.bmp");
QPixmap qq_smile(":/image/image/smile.bmp");
QPixmap qq_lose(":/image/image/lose.bmp");
QPixmap qq_pround(":/image/image/proud.bmp");
QPixmap ele_0(":/image/image/ele0.bmp");
QPixmap ele_1(":/image/image/ele1.bmp");
QPixmap ele_2(":/image/image/ele2.bmp");
QPixmap ele_3(":/image/image/ele3.bmp");
QPixmap ele_4(":/image/image/ele4.bmp");
QPixmap ele_5(":/image/image/ele5.bmp");
QPixmap ele_6(":/image/image/ele6.bmp");
QPixmap ele_7(":/image/image/ele7.bmp");
QPixmap ele_8(":/image/image/ele8.bmp");
QPixmap ele_9(":/image/image/ele9.bmp");
QPixmap blk_1(":/image/image/blk1.bmp");
QPixmap blk_2(":/image/image/blk2.bmp");
QPixmap blk_3(":/image/image/blk3.bmp");
QPixmap blk_4(":/image/image/blk4.bmp");
QPixmap blk_5(":/image/image/blk5.bmp");
QPixmap blk_6(":/image/image/blk6.bmp");
QPixmap blk_7(":/image/image/blk7.bmp");
QPixmap blk_8(":/image/image/blk8.bmp");
for(int i = 0;i<mine->getrow();i++)
{
for(int j = 0;j<mine->getcol();j++ )
{
if((mine->p[i][j]<10)||(mine->p[i][j]==99))
{
painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,block_close,0,0,BLOCK_LENGTH,BLOCK_HEIGH);
}
else if (((mine->p[i][j]<60)&&(mine->p[i][j]>=50))||(mine->p[i][j]>120))
{
painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,red_flag,0,0,BLOCK_LENGTH,BLOCK_HEIGH);
}
else if ((mine->p[i][j]>99)&&(mine->p[i][j]<110))
{
int blk_num = mine->p[i][j] - 100;
switch (blk_num)
{
case 0: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,block_open,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 1: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_1,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 2: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_2,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 3: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_3,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 4: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_4,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 5: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_5,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 6: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_6,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 7: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_7,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
case 8: painter->drawPixmap(j*BLOCK_LENGTH,i*BLOCK_HEIGH+TITILE_HEIGH,blk_8,0,0,BLOCK_LENGTH,BLOCK_HEIGH);break;
}
}
}
}
}
void MainWindow::on_secondadd()
{
mine->addtimeNum();
}
void createinterface()
{
end =0;
timeend =1;
mine = new block(ROW,COL,BOOMNUM);
LENGTH=mine->getcol()*21;
HEIGHT=mine->getrow()*21 + TITILE_HEIGH;
app->setMinimumSize(LENGTH,HEIGHT);
app->setMaximumSize(LENGTH,HEIGHT);
}
void MainWindow::Easy_triggered()
{
end =0;
timeend =1;
mine = new block(9,9,10);
LENGTH=mine->getcol()*21;
HEIGHT=mine->getrow()*21 + TITILE_HEIGH;
this->setMinimumSize(LENGTH,HEIGHT);
this->setMaximumSize(LENGTH,HEIGHT);
}
void MainWindow::Middle_triggered()
{
end =0;
timeend =1;
mine = new block(16,16,40);
LENGTH=mine->getcol()*21;
HEIGHT=mine->getrow()*21 + TITILE_HEIGH;
this->setMinimumSize(LENGTH,HEIGHT);
this->setMaximumSize(LENGTH,HEIGHT);
}
void MainWindow::Hard_triggered()
{
end =0;
timeend =1;
mine = new block(16,30,99);
LENGTH=mine->getcol()*21;
HEIGHT=mine->getrow()*21 + TITILE_HEIGH;
this->setMinimumSize(LENGTH,HEIGHT);
this->setMaximumSize(LENGTH,HEIGHT);
}
void MainWindow::Exit_triggered()
{
QApplication::quit();
}
void MainWindow::Customize_triggered()
{
InputDialog *cust = new InputDialog(this);
cust->show();
}
void MainWindow::AboutQT_triggered()
{
qApp->aboutQt();
}
void MainWindow::About_triggered()
{
QMessageBox mess(QMessageBox::NoIcon, tr("About"), tr("QMineSweeper is an open source minesweeper game written in Qt by LanGong Dev like the minesweeper software that comes with Windows XP and Windows 3.x."));
QPushButton *buttonURL = (mess.addButton(tr("View Sources"), QMessageBox::AcceptRole));
QPushButton *buttonLic = (mess.addButton(tr("View License"), QMessageBox::YesRole));
QPushButton *buttonOk = (mess.addButton(tr("OK"), QMessageBox::RejectRole));
buttonOk->setFocus();
mess.exec();
if (mess.clickedButton() == buttonURL)
{
QString url = "https://github.com/langong-dev/QMineSweeper";
QDesktopServices::openUrl(QUrl(url.toLatin1()));
}
else if (mess.clickedButton() == buttonLic){
QString url = "https://github.com/langong-dev/QMineSweeper/";
QDesktopServices::openUrl(QUrl(url.toLatin1()));
}
else
{
return;
}
}