-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathDungeon.cpp
executable file
·2630 lines (2552 loc) · 78 KB
/
Dungeon.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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Dungeon.h"
#include <QDebug>
#include <QTime>
std::vector<std::vector<int>> directions{{0,-1},{0,1},{-1,0},{1,0}};
int ***map;//三维数组
int Total_Floor;
QTimer *NetStartTimer;
QTimer *pkStartTimer;
QTimer *pkMapUdTimer;
QTimer *FightTimer;
QTimer *CmptorGameOverCallTimer;
Dungeon::Dungeon(QWidget *parent): QWidget(parent)
{
Total_Floor=7;
//开辟堆上三维数组
map=new int **[Total_Floor+1];
for(int i=0;i<Total_Floor+1;i++)
{
map[i]=new int *[12];
for(int j=0;j<12;j++)
{
map[i][j]=new int[16];
for(int k=0;k<16;k++)
{
map[i][j][k]=0;
}
}
}
QTime time=QTime::currentTime();
qsrand(time.msec()+time.second()*1000);
initialFogArr();
initialMapString();
initialMonsterPic();
initialCmptorPic();
initialrole();
initialenemy();
GetitemNum=0;//获得物品信息栏初始化
itemNum=0;
MonsterNum=0;
fight_period_it = 0;//战斗状态信息栏初始化
fight_end_it = 0;
moveDirection=-1;
moveNum=0;
pre_x=1;
pre_y=1;
pre_floor=1;
MyPonit=0;
CmptorPoint=0;
CountDown=80;
NetModeStart=false;
MyWin=false;
dogFall=false;
isFighting=false;
display_it=0;
PickaxeUse=false;
isDead=false;
fac=new Factory();
music=new Sound();
NetStartTimer=new QTimer;
pkStartTimer=new QTimer;
pkMapUdTimer=new QTimer;
CmptorGameOverCallTimer=new QTimer;
connect(NetStartTimer,SIGNAL(timeout()),this,SLOT(NetStart()));
connect(pkStartTimer,SIGNAL(timeout()),this,SLOT(pkStart()));
connect(pkMapUdTimer,SIGNAL(timeout()),this,SLOT(pkMapUpdate()));
connect(CmptorGameOverCallTimer,SIGNAL(timeout()),this,SLOT(competitorGameOverCall()));
}
Dungeon::~Dungeon(){}
void Dungeon::initialrole()
{
role.name="Mario";
role.level=1;
role.exp=0;
role.hp=100;
role.mp=100;
role.atk=5;
role.def=3;
role.scoreNum=0;
role.Pickaxe=0;
role.Downstairs=0;
}
void Dungeon::initialenemy()
{
enemy[0].name="小星星";//15
enemy[0].hp=60;
enemy[0].atk=4;//4
enemy[0].def=1;//1
enemy[0].exp=4;
enemy[0].gold=5;
enemy[1].name="毒蘑菇";//16
enemy[1].hp=100;
enemy[1].atk=9;
enemy[1].def=5;
enemy[1].exp=8;
enemy[1].gold=10;
enemy[2].name="绿鸭子";//18
enemy[2].hp=200;
enemy[2].atk=16;
enemy[2].def=12;
enemy[2].exp=16;
enemy[2].gold=20;
enemy[3].name="红鸭子";//19
enemy[3].hp=300;
enemy[3].atk=24;
enemy[3].def=14;
enemy[3].exp=32;
enemy[3].gold=30;
enemy[4].name="食人花-绿";//20
enemy[4].hp=600;
enemy[4].atk=32;
enemy[4].def=20;
enemy[4].exp=42;
enemy[4].gold=40;
enemy[5].name="食人花-红";//21
enemy[5].hp=900;
enemy[5].atk=46;
enemy[5].def=22;
enemy[5].exp=52;
enemy[5].gold=46;
enemy[6].name="飞行鸭";//22
enemy[6].hp=1200;
enemy[6].atk=82;
enemy[6].def=42;
enemy[6].exp=64;
enemy[6].gold=60;
}
void Dungeon::initialFogArr()
{
memset(FogArr,0,sizeof(FogArr));
for(int i=0;i<2;++i)
{
for(int j=6;j<9;++j)
FogArr[3][i][j]=15;
}
memset(haveVisited,0,sizeof(haveVisited));
}
//动态贴图方式
void Dungeon::initialMapString()
{
for(int i=0;i<41;++i)
{
for(int j=0;j<4;++j)
{
if(isStatic(i))
{
DungeonStytle[i][j]=QString("border-image: url(:/Dungeon/image/Dungeon/")+
QString::number(i)+QString(".png);");
break;
}
else
DungeonStytle[i][j]=QString("border-image: url(:/Dungeon/image/Dungeon/")+
QString::number(i)+"/"+QString::number(i)+QString::number(j)+QString(".png);");
}
}
}
void Dungeon::initialMonsterPic()
{
MonsterPic[0]="border-image: url(:/info/image/information/start.png);";
MonsterPic[1]="border-image: url(:/info/image/information/badmushroom.png);";
MonsterPic[2]="border-image: url(:/info/image/information/greenDuck.png);";
MonsterPic[3]="border-image: url(:/info/image/information/flyDuck.png);";
MonsterPic[4]="border-image: url(:/info/image/information/绿色食人花.png);";
MonsterPic[5]="border-image: url(:/info/image/information/红色食人花.png);";
MonsterPic[6]="border-image: url(:/info/image/information/飞行鸭.png);";
}
void Dungeon::initialCmptorPic()
{
for(int i=0;i<4;++i)
{
for(int j=0;j<4;++j)
{
if(i==0||i==1)
{
CmptorPic[i][j]=QString("border-image: url(:/Cmptor/image/Cmptor/")+
QString::number(i)+QString(".png);");
break;
}
else
CmptorPic[i][j]=QString("border-image: url(:/Cmptor/image/Cmptor/")+
QString::number(i)+"/"+QString::number(i)+QString::number(j)+QString(".png);");
}
}
}
int Dungeon::pk(struct Monster & m)
{
//计算伤害值,-1表示打不动对方防御,-2表示双方都打不动对方防御
if (role.atk <= m.def)
{
if (m.atk > role.def)
return -1;//打不过
else
return -2;//怪物防御太高,先增加你的攻击力吧
}
else//人物的攻击力大于怪物的防御,但是依然打不过的情况
{
if(m.atk>role.def)
{
int i=0;
int role_hp=role.hp;
int enemy_hp=m.hp;
while(role_hp>0)
{
role_hp=role.hp - (m.atk - role.def)*i;
enemy_hp=m.hp - (role.atk - m.def) * i;
i++;
}
if(enemy_hp>=0)
{
return 1;
}
}
}
return 0;
}
int Dungeon::calc_damage(int MonsterNum)
{
if (role.atk <= enemy[MonsterNum].def)
{
if (enemy[MonsterNum].atk > role.def)
return -1;
else
return -2;
}
else
{
if (enemy[MonsterNum].atk > role.def)
{
int atk_times = (enemy[MonsterNum].hp - 1) / (role.atk - enemy[MonsterNum].def);//怪物攻击的次数
return atk_times * (enemy[MonsterNum].atk - role.def);//造成的伤害
}
else
{
return 0;//怪物破不了我们的防,造成的伤害为0
}
}
}
int Dungeon::sum(int arr[],int n)
{
if(arr==nullptr)
return 0;
int res=0;
for(int i=0;i<n;++i)
res+=arr[i];
return res;
}
void Dungeon::dfs(int arr[12][16],bool visited[12][16],QStack<std::pair<int,int>> &s,int i,int j)
{
if(i<0||i>=12||j<0||j>=16||arr[i][j]==0||visited[i][j])
return;
visited[i][j]=true;
s.push(std::pair<int,int>(i,j));
for(auto dir:directions)
dfs(arr,visited,s,i+dir[0],j+dir[1]);
}
void Dungeon::bfs(int arr[12][16],QStack<std::pair<int,int>> &s,std::pair<int,int> start,std::pair<int,int> end)
{
bool visited[12][16]{false};
QQueue<std::pair<int, int>> q;
q.enqueue(start);
visited[start.first][start.second] = true;
while (!q.empty())
{
int size = q.size();
while (size-- > 0)
{
std::pair<int, int> temp = q.dequeue();;
int ci = temp.first, cj = temp.second;
s.push(temp);
int index = 0;
visited[ci][cj] = true;
for (auto dir : directions)
{
int ni = ci + dir[0], nj = cj + dir[1];
if (ni < 0 || ni >= 12 || nj < 0 || nj >= 16 || visited[ni][nj] || arr[ni][nj] == 0)
{
index++;
if (index >= 4)
s.pop();
continue;
}
if (ni == end.first&&nj == end.second)
return;
q.enqueue(std::pair<int, int>(ni, nj));
}
}
}
}
void Dungeon::doDfs(int arr[12][16],QStack<std::pair<int,int>>& s,bool visited[12][16])
{
int dfsi=rand()%12;
int dfsj=rand()%16;
while(arr[dfsi%12][dfsj%16]!=1)
{
dfsj++;
if(dfsj%16==0)
dfsi++;
}
dfs(arr,visited,s,dfsi%12,dfsj%16);
}
void Dungeon::setExit(int arr[12][16],std::pair<int,int> &start,std::pair<int,int> &end)
{
QStack<std::pair<int,int>> s;
bool visited[12][16]{false};
doDfs(arr,s,visited);
//int startPos=rand()%floor;
int startPos=0;
int starti=s[startPos].first,startj=s[startPos].second;
int endi=s.top().first,endj=s.top().second;
while(std::abs(starti-endi)<=3||std::abs(startj-endj)<=3)
{
s.clear();
for(int i=0;i<12;++i)
{
for(int j=0;j<16;++j)
if(visited[i][j])
visited[i][j]=false;
}
doDfs(arr,s,visited);
starti=s[startPos].first;
startj=s[startPos].second;
endi=s.top().first;
endj=s.top().second;
}
start.first=starti;
start.second=startj;
end.first=endi;
end.second=endj;
arr[starti][startj]=6;
arr[endi][endj]=7;
}
void Dungeon::GenerateMonster(int arr[12][16],int floor)
{
int totalMonsterNum=40+floor*2;
int MonsterArr[9]{0};
int MonsterInitial[9]{8,8,5,3,1,0,0,0,0};
for(int i=0;i<9;++i)
{
if(i==0)
{
MonsterArr[i]=MonsterInitial[i]-(floor-1)*2;
if(MonsterArr[i]<=2)
MonsterArr[i]=2;
}
else if(i==1)
{
MonsterArr[i]=MonsterInitial[i]-(floor-1)*2;
if(MonsterArr[i]<=2)
MonsterArr[i]=0;
}
else if(i==2)
MonsterArr[i]=5;
else if(i==3)
MonsterArr[i]=3;
else
{
MonsterArr[i]=MonsterInitial[i]+(floor-1)*(0.5*(i-3));
}
}
while(sum(MonsterArr,9)<totalMonsterNum)
{
for(int i=floor-1;i<9;++i)
MonsterArr[i]+=1;
}
while(MonsterArr[3]>3)
{
MonsterArr[2]++;
MonsterArr[3]--;
}
int GenerateMonsterNum=0;
int MonsterArrIndex=0;
while(GenerateMonsterNum<totalMonsterNum)
{
for(int i=0;i<12;++i)
{
for(int j=0;j<16;++j)
{
if(arr[i][j]==1)
{
if(MonsterArr[MonsterArrIndex++%9]!=0)
{
arr[i][j]= (MonsterArrIndex-1)%9+14;
MonsterArr[(MonsterArrIndex-1)%9]--;
}
i+=rand()%6;
j+=rand()%8;
GenerateMonsterNum++;
if(GenerateMonsterNum>=totalMonsterNum)
return;
}
}
}
}
}
void Dungeon::GenerateItem(int arr[12][16],int floor)
{
int totalBuffItemNum=5-floor+1;
int BuffItemArr[5]{0};
int BuffItemInitial[5]{2,1,1,0,0};
for(int i=0;i<5;++i)
{
if(i==2)
BuffItemArr[i]=BuffItemInitial[i]+(floor-1)*0.5;
else
{
BuffItemArr[i]=BuffItemInitial[i]+(floor-1)*1;
}
}
while(sum(BuffItemArr,5)<totalBuffItemNum)
{
for(int i=0;i<3+floor-1;++i)
BuffItemArr[i]+=1;
}
int GenerateBuffItemNum=0;
int BuffItemArrIndex=0;
bool GenerateBuffItemDone=false;
while(GenerateBuffItemNum<totalBuffItemNum)
{
for(int i=0;i<12;++i)
{
for(int j=0;j<16;++j)
{
if(arr[i][j]==1)
{
if(BuffItemArr[BuffItemArrIndex++%5]!=0)
{
arr[i][j]= (BuffItemArrIndex-1)%5+23;
BuffItemArr[(BuffItemArrIndex-1)%5]--;
}
i+=rand()%6;
j+=rand()%8;
GenerateBuffItemNum++;
if(GenerateBuffItemNum>=totalBuffItemNum)
{
GenerateBuffItemDone=true;
break;
}
}
}
if(GenerateBuffItemDone)
break;
}
if(GenerateBuffItemDone)
break;
}
int totalToolItemNum=4-floor+1;
int ToolItemArr[2]{0};
int ToolItemInitial[2]{2,1};
for(int i=0;i<2;++i)
{
if(i==0)
ToolItemArr[i]=ToolItemInitial[i]+(floor-1)*1;
else
ToolItemArr[i]=ToolItemInitial[i]+(floor-1)*0.5;
}
while(sum(ToolItemArr,1)<totalToolItemNum)
{
for(int i=0;i<1;++i)
ToolItemArr[i]+=1;
}
int GenerateToolItemNum=0;
int ToolItemArrIndex=0;
while(GenerateToolItemNum<totalToolItemNum)
{
for(int i=0;i<12;++i)
{
for(int j=0;j<16;++j)
{
if(arr[i][j]==1)
{
if(ToolItemArr[ToolItemArrIndex++%2]!=0)
{
arr[i][j]= (ToolItemArrIndex-1)%2+31;
ToolItemArr[(ToolItemArrIndex-1)%2]--;
}
i+=rand()%6;
j+=rand()%8;
GenerateToolItemNum++;
if(GenerateToolItemNum>=totalToolItemNum)
return;
}
}
}
}
}
void Dungeon::GenerateEquip()
{
int ironSwordFloor=2;
int flowerSwordFloor=4;
int goldenSwordFloor=7;
if(map[ironSwordFloor-1][10][14]==6||map[ironSwordFloor-1][10][14]==7)
{
map[ironSwordFloor-1][10][13]=28;
}
else
map[ironSwordFloor-1][10][14]=28;
if(map[flowerSwordFloor-1][10][14]==6||map[flowerSwordFloor-1][10][14]==7)
{
map[flowerSwordFloor-1][10][13]=29;
}
else
map[flowerSwordFloor-1][10][14]=29;
if(map[goldenSwordFloor-1][10][14]==6||map[goldenSwordFloor-1][10][14]==7)
{
map[goldenSwordFloor-1][10][13]=30;
}
else
map[goldenSwordFloor-1][10][14]=30;
}
void Dungeon::GenerateElement(int arr[12][16],int floor)
{
GenerateMonster(arr,floor);
GenerateItem(arr,floor);
}
bool Dungeon::isValid(int arr[12][16],int i,int j,int floor)
{
return arr[i][j]==1||arr[i][j]==6||(arr[i][j]>=8&&arr[i][j]<=14+(floor<=2?1:floor))
||(arr[i][j]>=23&&arr[i][j]<=27)||arr[i][j]==31||arr[i][j]==32;
}
void Dungeon::RandomGeneraterMap(int arr[12][16],int floor)
{
std::pair<int,int> start;
std::pair<int,int> end;
setExit(arr,start,end);
GenerateElement(arr,floor);
QStack<std::pair<int,int>> s;
bfs(arr,s,start,end);
while(!s.empty())
{
std::pair<int,int> temp=s.pop();
if(!isValid(arr,temp.first,temp.second,floor))
arr[temp.first][temp.second]=rand()%(floor<3?2:5)+14;
}
}
void Dungeon::initialMap()
{
floor=1;
MAX_HP=100;
MAX_MP=100;
deadTimes=0;
isPre=false;
isNext=false;
initialrole();
while(1)
{
if(floor==1)
{
int tempmap[12][16]={
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,
0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,1,
0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,
0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,
0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,
0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,
0,1,1,1,1,1,0,0,1,0,0,0,1,0,0,0,
0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0,
0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0
};
RandomGeneraterMap(tempmap,floor);
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[floor-1][i][j]=tempmap[i][j];
}
}
}
if(floor==2)
{
int tempmap[12][16]={
1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0,
1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0,
1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,
1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,
1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0,
1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0,
1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,
1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,
1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,0,
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0
};
RandomGeneraterMap(tempmap,floor);
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[floor-1][i][j]=tempmap[i][j];
}
}
}
if(floor==3)
{
int tempmap[12][16]={
1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,
1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,0,1,1,1,1,0,1,0,0,0,0,0,
0,0,1,0,0,0,1,1,0,0,1,0,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,1,0,0,1,1,1,1,0,1,0,0,0,0,0,
1,1,1,1,0,0,1,1,0,0,1,0,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,0,1,1,1,1,0,1,0,0,0,0,0,
0,0,0,0,0,0,1,1,0,0,1,0,1,1,1,1,
1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,
};
RandomGeneraterMap(tempmap,floor);
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[floor-1][i][j]=tempmap[i][j];
}
}
}
if(floor==4)
{
int tempmap[12][16]={
1,1,1,1,0,1,8,9,10,1,0,1,1,1,1,1,
1,1,1,1,0,1,11,12,13,1,0,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,
0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,
1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,
1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,
1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,
};
RandomGeneraterMap(tempmap,floor);
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[floor-1][i][j]=tempmap[i][j];
}
}
}
if(floor==5)
{
int tempmap[12][16]={
1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,
1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1,
1,1,1,1,1,0,1,0,1,1,1,0,1,1,0,1,
0,0,0,0,1,0,1,0,1,1,1,0,1,1,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,1,
0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,0,
0,0,1,0,0,0,1,0,1,1,1,0,1,1,1,1,
1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,
};
RandomGeneraterMap(tempmap,floor);
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[floor-1][i][j]=tempmap[i][j];
}
}
}
if(floor==6)
{
int tempmap[12][16]={
1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,
1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,1,
1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,1,
1,1,1,1,1,0,1,0,1,1,1,0,1,1,0,1,
1,1,1,1,1,0,1,0,1,1,1,0,1,1,0,1,
1,1,1,1,1,0,1,0,1,1,1,1,1,1,0,1,
1,0,0,0,0,0,1,0,0,0,0,1,1,1,0,1,
1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,
};
RandomGeneraterMap(tempmap,floor);
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[floor-1][i][j]=tempmap[i][j];
}
}
}
if(floor==7)
{
int tempmap[12][16]={
1,0,1,1,0,1,0,1,1,1,0,1,0,1,0,1,
1,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1,
1,0,1,1,0,1,1,1,0,1,0,1,0,1,0,1,
1,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,
1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,1,1,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,
1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,
};
RandomGeneraterMap(tempmap,floor);
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[floor-1][i][j]=tempmap[i][j];
}
}
}
floor++;
if(floor>Total_Floor)
{
break;
}
}
floor=1;
setCharacterPos(floor-1,6);
GenerateEquip();
}
void Dungeon::initialpkMap()
{
int tempmap[12][16]={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,1,14,14,14,0,14,14,14,0,1,1,1,1,0,
0,1,1,14,0,0,0,14,0,14,0,0,0,1,1,0,
0,1,0,14,14,14,14,14,0,14,14,14,0,1,1,0,
0,1,0,0,0,0,0,0,0,0,0,14,0,1,1,0,
0,1,14,14,14,14,0,14,14,14,0,14,0,1,1,0,
0,1,0,0,0,0,0,14,0,14,0,14,1,1,1,0,
0,1,1,14,0,14,14,14,0,14,0,14,1,1,1,0,
0,1,1,14,0,14,0,0,0,14,0,0,0,0,1,0,
0,1,1,14,0,14,14,14,0,14,14,1,1,1,1,0,
0,1,1,14,14,14,14,14,0,14,14,1,1,1,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
for(int i=0;i<12;i++)
{
for(int j=0;j<16;j++)
{
map[7][i][j]=tempmap[i][j];
}
}
}
void Dungeon::setCharacterPos(int floor,int target)
{
bool findflag=false;
int i,j;
for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{
if(map[floor][i][j]==target)
{
findflag=true;
break;
}
}
if(findflag)
break;
}
if(!findflag)
return;
if(i<11&&((map[floor][i+1][j]==1||isDynamic(floor,i+1,j))
||(map[floor][i+1][j]>=23&&map[floor][i+1][j]<=27)))
{
if(map[floor][i+1][j]!=1)
map[floor][i+1][j]=1;
x=i+1;
y=j;
}
else if(i>0&&((map[floor][i-1][j]==1||isDynamic(floor,i-1,j))
||(map[floor][i-1][j]>=23&&map[floor][i-1][j]<=27)))
{
if(map[floor][i-1][j]!=1)
map[floor][i-1][j]=1;
x=i-1;
y=j;
}
else if(j<15&&((map[floor][i][j+1]==1||isDynamic(floor,i,j+1))
||(map[floor][i][j+1]>=23&&map[floor][i][j+1]<=27)))
{
if(map[floor][i][j+1]!=1)
map[floor][i][j+1]=1;
x=i;
y=j+1;
}
else if(j>0&&((map[floor][i][j-1]==1||isDynamic(floor,i,j-1))
||(map[floor][i][j-1]>=23&&map[floor][i][j-1]<=27)))
{
if(map[floor][i][j-1]!=1)
map[floor][i][j-1]=1;
x=i;
y=j-1;
}
else
{
x=y=0;
}
if(target==6)
updateFogArea(floor,x,y);
}
void Dungeon::initialCharacterPos()
{
if(isPre)
{
setCharacterPos(floor-2,7);
isPre=false;
}
if(isNext)
{
setCharacterPos(floor,6);
isNext=false;
}
}
void Dungeon::initialDugeon()
{
initialFogWidget();
initialMap();
Store=new StoreWidget(ptr_MianWindow);//类中如果不定义子窗口,则不能作为MianWindow的子窗口
Store->setGeometry(292,192,256,352);
Store->hide();
menu=new Menu(ptr_MianWindow);
menu->setGeometry(160,160,520,320);
menu->hide();
QFont fontLabel("Microsoft YaHei" ,12, 75);
QFont fontNum("Microsoft YaHei" ,10, 75);
NetMode_time=fac->CreateQLabel(ptr_MianWindow,640,20,200,40,"遭遇战倒计时:","color:white",fontLabel);
NetMode_secondes=fac->CreateQLabel(ptr_MianWindow,740,60,80,40,QString::number(CountDown),"color:red",fontNum);
NetMode_time->hide();
NetMode_secondes->hide();
help=new Help(ptr_MianWindow);
help->setGeometry(160,160,520,320);
help->hide();
initialinfoWidget();
initialFightWin();//希望显示在MainWidget之上的窗口,要在初始化MainWidget后再初始化
initialSetNameWin();
initialGetitemWin();
GetitemTimer=new QTimer(this);
FightTimer=new QTimer(this);
dynamicEffectTimer=new QTimer(this);
connect(GetitemTimer,SIGNAL(timeout()),this,SLOT(GetitemWinshow()));
connect(FightTimer,SIGNAL(timeout()),this,SLOT(FightWinshow()));
connect(Store->haveBuyTimer,SIGNAL(timeout()),this,SLOT(OpenStore()));
connect(dynamicEffectTimer,SIGNAL(timeout()),this,SLOT(ShowdynamicEffect()));
}
void Dungeon::initialFogWidget()
{
int BASIC_WIDTH=832/16;
int BASIC_HEIGHT=672/12;
for(int i=0;i<12;++i)
{
for(int j=0;j<16;++j)
{
FogWidget[i][j]=new QWidget(ptr_MianWindow);
FogWidget[i][j]->setGeometry(j*BASIC_WIDTH,i*BASIC_HEIGHT,BASIC_WIDTH,BASIC_HEIGHT);
FogWidget[i][j]->setAutoFillBackground(true);
FogWidget[i][j]->hide();
}
}
}
void Dungeon::initialinfoWidget()
{
infoWidget=new QWidget(ptr_MianWindow);
QFont fontLabel("Microsoft YaHei" ,12, 75);
QFont fontNum("Microsoft YaHei" ,10, 65);
QFont fontName("Microsoft YaHei" ,10, 55);
QString labelbg_style="border-image: url(:/interface/image/interface/labelbg.png);";
QString CharacterPic_style="border-image: url(:/info/image/information/Character.png);";
QString Pickaxe_style="border-image: url(:/info/image/information/Pickaxe.png);";
QString Downstairs_style="border-image: url(:/info/image/information/Downstairs.png);";
QString redkey_style="border-image: url(:/info/image/information/redkey.png);";
QLabel *CharacterPic=fac->CreateQLabel(infoWidget,20,20,40,40,"",CharacterPic_style);
QLabel *label_Name=fac->CreateQLabel(infoWidget,20,70,100,30,"人们叫他",labelbg_style,fontLabel,Qt::AlignLeft);
CharacterName=fac->CreateQLabel(infoWidget,130,70,170,30,"",labelbg_style,fontName,Qt::AlignLeft);
QLabel *label_level=fac->CreateQLabel(infoWidget,140,20,40,40,"级",labelbg_style,fontLabel);
QLabel *label_hp=fac->CreateQLabel(infoWidget,20,110,65,30,"生命",labelbg_style,fontLabel,Qt::AlignLeft);
QLabel *label_mp=fac->CreateQLabel(infoWidget,20,150,65,30,"魔法",labelbg_style,fontLabel,Qt::AlignLeft);
QLabel *label_atk=fac->CreateQLabel(infoWidget,20,230,65,30,"攻击",labelbg_style,fontLabel,Qt::AlignLeft);
QLabel *label_def=fac->CreateQLabel(infoWidget,20,270,65,30,"防御",labelbg_style,fontLabel,Qt::AlignLeft);
QLabel *label_score=fac->CreateQLabel(infoWidget,20,310,65,30,"金币",labelbg_style,fontLabel,Qt::AlignLeft);
QLabel *label_exp=fac->CreateQLabel(infoWidget,20,190,65,30,"经验",labelbg_style,fontLabel,Qt::AlignLeft);
QLabel *label_Pickaxe=fac->CreateQLabel(infoWidget,20,370,40,40,"",Pickaxe_style);
QLabel *label_Downstairs=fac->CreateQLabel(infoWidget,20,420,40,40,"",Downstairs_style);
QLabel *label_floor1=fac->CreateQLabel(infoWidget,20,520,40,40,"第",labelbg_style,fontLabel);
QLabel *label_floor2=fac->CreateQLabel(infoWidget,140,520,40,40,"层",labelbg_style,fontLabel);
level=fac->CreateQLabel(infoWidget,80,20,40,40,QString::number(role.level),labelbg_style,fontNum);
hp=fac->CreateQLabel(infoWidget,105,110,100,30,QString::number(role.hp),labelbg_style,fontNum);
mp=fac->CreateQLabel(infoWidget,105,150,100,30,QString::number(role.mp),labelbg_style,fontNum);
atk=fac->CreateQLabel(infoWidget,105,230,100,30,QString::number(role.atk),labelbg_style,fontNum);
def=fac->CreateQLabel(infoWidget,105,270,100,30,QString::number(role.def),labelbg_style,fontNum);
score=fac->CreateQLabel(infoWidget,105,310,100,30,QString::number(role.scoreNum),labelbg_style,fontNum);
exp=fac->CreateQLabel(infoWidget,105,190,100,30,QString::number(role.exp),labelbg_style,fontNum);
PickaxeNum=fac->CreateQLabel(infoWidget,105,370,100,30,QString::number(role.Pickaxe),labelbg_style,fontNum);
DownstairsNum=fac->CreateQLabel(infoWidget,105,420,100,30,QString::number(role.Downstairs),labelbg_style,fontNum);
Floor=fac->CreateQLabel(infoWidget,80,520,40,40,QString::number(floor),labelbg_style,fontNum);
label_MyName=fac->CreateQLabel(infoWidget,20,580,100,30,"",labelbg_style,fontLabel,Qt::AlignLeft);
label_VS=fac->CreateQLabel(infoWidget,120,580,40,30,"VS",labelbg_style,fontLabel,Qt::AlignLeft);
label_CmptorName=fac->CreateQLabel(infoWidget,180,580,100,30,"",labelbg_style,fontLabel,Qt::AlignLeft);
label_MyPonit=fac->CreateQLabel(infoWidget,50,620,40,30,"0",labelbg_style,fontNum,Qt::AlignLeft);
label_split=fac->CreateQLabel(infoWidget,130,620,40,30,":",labelbg_style,fontLabel,Qt::AlignLeft);
label_CmptorPoint=fac->CreateQLabel(infoWidget,210,620,40,30,"0",labelbg_style,fontNum,Qt::AlignLeft);
label_MyName->hide();
label_VS->hide();
label_CmptorName->hide();
label_MyPonit->hide();
label_split->hide();
label_CmptorPoint->hide();
connect(menu->ReturnMainMenu,SIGNAL(clicked()),this,SLOT(ReturnMainMenuPlay()));
connect(menu->Restart,SIGNAL(clicked()),this,SLOT(RestartPlay()));
connect(menu->Continue,SIGNAL(clicked()),this,SLOT(ContinuePlay()));
connect(menu->ReturnRooms,SIGNAL(clicked()),this,SLOT(ReturnRoomsPlay()));
connect(menu->Help,SIGNAL(clicked()),this,SLOT(HelpPlay()));
connect(help->Return,SIGNAL(clicked()),this,SLOT(HelpReturnPlay()));
connect(menu->music,SIGNAL(clicked()),this,SLOT(musicChangePlay()));
infoWidget->setMinimumSize(300,672);
infoWidget->setStyleSheet("color:white;border-image: url(:/interface/image/interface/infobg.png);");
infoWidget->hide();
}
void Dungeon::ReturnMainMenuPlay()//返回主菜单
{
infoWidget->hide();//隐藏状态界面
hideDungeon();//隐藏地牢界面
hideFog();
menu->pauseEvent->setText("PAUSE");
menu->Restart->show();
menu->Continue->show();
menu->hide();
NetMode_time->hide();
NetMode_secondes->hide();
MyPonit=0;
CmptorPoint=0;
surface->isok=false;
NetModeStart=false;
music->InterfaceBGM->play();
music->InterfaceBGMTimer->start(10);
NameEdit->clear();
surface->show();//开始界面显示后,主窗口大小还是不变
ptr_MianWindow->resize(832,672);//需要重新设置主窗口大小
surface->resizeEvent(nullptr);
surface->showMianMenu();
initialFogArr();
initialMap();
Store->initialStoreDatas();
updateStatusData();
}
void Dungeon::RestartPlay()//重新开始
{
menu->hide();
initialFogArr();