-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit1.pas
4476 lines (4332 loc) · 128 KB
/
Unit1.pas
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
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ToolWin, Vcl.ActnMan, Vcl.ActnCtrls,
Vcl.ActnMenus, Vcl.StdCtrls,PngImage, Vcl.ExtCtrls, Math, StrUtils, mmSystem,
Vcl.MPlayer;
type
Tr = class(TForm)
Map: TImage;
Timer: TTimer;
StateMap: TImage;
Menu: TImage;
Sound: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure TimerTimer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure SoundTimer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
public
procedure MainMenu;
procedure MenuText(m, n, l, k: Integer);
procedure CreateMap;
procedure MonsterMove(p,q,n,s:Integer);
procedure MapCreate;
function OpenDoor(p,q:Integer):Boolean;
procedure ItemMenu;
procedure Equip;
procedure GetTxt;
procedure StartFight;
procedure FightPrint;
procedure LifeFlash;
procedure AttackFlash(n:Integer);
procedure Attack(n,Turn:Integer);
function Fight(p,q:Integer): Boolean;
function GemPicture(n:Integer):TBitMap;
procedure MsgView(str: String);
function GemCheck(n, k: Integer): Boolean;
procedure WallRefresh;
procedure DestoryWall(p,q:Integer);
procedure GetWeapon(p, q : Integer);
procedure StartNum;
procedure StartCreate;
procedure GameOver;
procedure StartSound(m, n: Integer);
procedure HeroMove(n: Integer);
procedure SaveGame;
procedure ReadGame;
procedure UpFloor;
procedure DownFloor;
procedure Walk;
{ Public declarations }
end;
var
r: Tr;
Num: Integer=13;
BigNum: Integer=3000;
HardNum: Integer=5;
Floor: Integer=-10;
WallNum: Integer=3;
Time: Integer=0;
Allow: Boolean = False; //战斗画面区域禁止地图怪物动画
FightAllow: Boolean = False; //战斗开启
EquipChance: Boolean = False; //装备栏开启
EquipChoose: Boolean = False; //装备选择
EquipOrGem: Boolean = True; //宝石/装备选择
ItemChance: Boolean = False;
GemSet: Boolean = False; //宝石镶嵌状态开启/关闭
GemChoose: Boolean = False; //宝石选择
GemSpace: Boolean = False;
LifeChoose: Boolean = False; //生命显示开启
TimeAllow: Boolean = False;
KeyAble: Boolean = True;
MonsterBook: Boolean = False;
FightQuit: Boolean;
NumFight, CopyFight: Integer;
PngFloor,PngWall: TPngImage;
BmpFight,BmpFight1,BmpFight2: TBitMap;
BmpLifeBack1,BmpLifeBack2: TBitMap;
MapArray: Array of Array of Integer;
NumArray: Array of Array of Integer;
//HardFloor: Array of Array of Integer;
FindWayArray,FindNumArray: Array of Integer;
HardArray: Array of Array of Array of Integer;
FloorArray: Array of Array of Array of Integer;
TimeNum: Integer; //时间计数
GemArray: Array[1..35] of Integer = (101,102,103,104,105,106,{107,}108,109,{110,}111,112,
{113,}151,152,153,154,155,156,157,158,{159,}201,202,203,204,205,206,{207,}208,{209,210,}
301,302,303,304,305,306,351,352,353,354);
ItemArray: Array[1..26] of Integer=(101,102,103,104,107,121,122,123,124,131,132,
133,151,152,153,154,161,162,163,164,171,172,173,174,175,176);
MonsterArray: Array[1..44] of Integer=(301,302,303,304,311,312,313,
314,321,322,323,324,331,332,333,334,351,352,353,361,362,363,371,372,373,401,402,411,
412,421,422,431,432,441,442,451,452,453,454,455,461,462,463,464);
DoorArray: Array[1..4] of Integer=(21,22,23,24);
Item: Array[100..299] of Integer;
WeaponEquip: Array[1..2] of Integer; //1.武器 2.防具
//WeaponNum: Array[1..3] of Array[1..7] of Integer; //1..3 position 4.种类 5.名称 6.星级 7.攻击/防御
WeaponItem: Array[1..24] of Array[1..7] of Integer; //1.排序 2.属性
//1.种类 2.名称 3.星级 4.攻击/防御 5.宝石1 6.宝石2 7.宝石3
GemItem: Array[1..28] of Integer; //宝石栏
page,pageNum,EquipPage: Integer; //装备页数 选择装备位置 装备选项
GemNum,GemPage: Integer;
EquipNum, GemNumber: Integer;
xHero,yHero,kHero: Integer;
HeroFace: Integer;
MoveChance: Boolean = True; //移动许可
MoveAllow: Boolean;
HitChance: Boolean; //
LifeLost: Boolean; //损失或增加生命
LifeTime: Integer; //显示生命数字次数
LifeNumber1,LifeNumber2: Integer; //损失或增加生命值
LifeBack: Array[0..1] of Integer;
HeroState: Array[1..18] of Integer; //英雄属性
MonsterState: Array[1..18] of Integer; //怪物属性
FightArray: Array[0..1] of Array[1..18] of Integer;
FightNum: Array[0..1] of Array[1..17] of Integer;
HeroStart: Array[1..18] of Integer=(2000,500,20,20,20,20,0,0,0,0,0,0,100,0,20,0,0,0);
MonsterStart: Array[1..18] of Integer=(50,10,40,10,30,10,0,0,0,0,0,0,100,0,10,1,1,0);
MonsterRead: Array[1..18] of Integer; //读取怪物参数
MonsterBase: Array[1..18] of Integer; //怪物基准属性
Wall: Integer = 3;
MsgBmp: TBitmap;
MsgLock: Integer = 0;
FindFloor: Integer = 0;
BookPage: Integer;
BookPageMax: Integer;
BookFloor: Integer = 0;
MenuNum: Integer = 1;
MenuChoose: Boolean = True;
FightMenuNum: Integer = 1;
FightMenu: Boolean = False;
AttackChoose: Integer; //攻击效果类型
BackMusic: Integer = 0;
MoveKey: Integer;
Over: Boolean;
SaveTime: Integer;
{3.墙 4.石头 5.岩浆 15.地面(53.54.55) 21-24门 101-199.物品 301-499.怪物}
implementation
{$R *.dfm}
function SkillName(n:Integer):String;forward;
procedure MapStart;
var
i: Integer;
begin
SetLength(MapArray,Num+2);
SetLength(NumArray,Num+2);
for i := 0 to Num+1 do
begin
SetLength(MapArray[i],Num+2);
SetLength(NumArray[i],Num+2);
end;
end;
procedure MapClear;
var
i,j: Integer;
begin
for i := 0 to Num+1 do
for j := 0 to Num+1 do
MapArray[i,j]:=0;
for i := 0 to Num+1 do
begin
MapArray[0,i]:=WallNum;
MapArray[i,0]:=WallNum;
MapArray[Num+1,i]:=WallNum;
MapArray[i,Num+1]:=WallNum;
end;
end;
procedure NumClear;
var
i,j: Integer;
begin
for i := 0 to Num+1 do
for j := 0 to Num+1 do
NumArray[i,j]:=0;
for i := 0 to Num+1 do
begin
NumArray[0,i]:=WallNum;
NumArray[i,0]:=WallNum;
NumArray[Num+1,i]:=WallNum;
NumArray[i,Num+1]:=WallNum;
end;
end;
procedure FloorStart;
var
i,j:Integer;
begin
SetLength(FloorArray,Num+2);
for i := 0 to Num+1 do
begin
SetLength(FloorArray[i],Num+2);
for j := 0 to Num+1 do
SetLength(FloorArray[i,j],10);
end;
end;
procedure AllStart;
var
i,j,k:Integer;
begin
MapStart;
FloorStart;
SetLength(FindWayArray,Num*Num);
SetLength(FindNumArray,Num*Num);
SetLength(HardArray,2);
for i := 0 to 1 do
begin
SetLength(HardArray[i],10);
for j := 0 to 9 do
begin
SetLength(HardArray[i,j],Num*Num);
for k := 0 to Num*Num-1 do
HardArray[i,j,k]:=0;
end;
end;
end;
function FloorHard:Integer;
begin
Result:=Trunc(Sqrt(Trunc(Floor/10)+1));
end;
procedure Delay(MSecs: Longint);//延时函数,MSecs单位为毫秒(千分之1秒)
var
FirstTickCount, Now: Longint;
begin
FirstTickCount := GetTickCount();
repeat
Application.ProcessMessages;
Now := GetTickCount();
until (Now - FirstTickCount >= MSecs) or (Now < FirstTickCount);
end;
procedure FloorPoint; //楼梯确定
var
i,p,q,s:Integer;
begin
for i := 1 to 2 do
begin
while True do
begin
p:=Random(Num)+1;
q:=Random(Num)+1;
if MapArray[p,q]<>0 then continue;
s:=0;
if MapArray[p-1,q]=WallNum then s:=s+1;
if MapArray[p+1,q]=WallNum then s:=s+1;
if MapArray[p,q-1]=WallNum then s:=s+1;
if MapArray[p,q+1]=WallNum then s:=s+1;
if s=3 then break;
end;
MapArray[p,q]:=i;
end;
end;
procedure CopyFloor(k:Integer);
var
i,j:Integer;
begin
for i := 0 to Num+1 do
for j := 0 to Num+1 do
MapArray[i,j]:=FloorArray[k,i,j];
end;
procedure CopyMap(k:Integer);
var
i,j:Integer;
begin
for i := 0 to Num+1 do
for j := 0 to Num+1 do
FloorArray[k,i,j]:=MapArray[i,j];
end;
procedure CopyNum(m,n:Integer);
var
i,j:Integer;
begin
for i := 0 to Num+1 do
for j := 0 to Num+1 do
if (MapArray[i,j]>m-1)And(MapArray[i,j]<n+1) then NumArray[i,j]:=MapArray[i,j]
end;
function RanNum(m,n:Integer):Integer;
var
i, s, t: Integer;
begin
if m < 1 then m := 1;
repeat
if n > 0 then
begin
s := 0;
t := m * m + 100;
for i := 1 to t do s := s + Random(3);
s := (n * s) div t;
m := m - n + s;
end;
until (m < 1)Or(m > 10);
Result := m;
end;
function Number(m:Integer):Integer;
var
i,j,n:Integer;
begin
n:=0;
for i := 1 to Num do
for j := 1 to Num do
if MapArray[i,j]=m then n:=n+1;
Result:=n;
end;
function BesideMap(i,j,m:Integer):Integer;
var
s:Integer;
begin
s:=0;
if MapArray[i-1,j]=m then s:=s+1;
if MapArray[i+1,j]=m then s:=s+1;
if MapArray[i,j-1]=m then s:=s+1;
if MapArray[i,j+1]=m then s:=s+1;
Result:=s;
end;
function BesideNum(i,j,m:Integer):Integer;
var
s:Integer;
begin
s:=0;
if NumArray[i-1,j]=m then s:=s+1;
if NumArray[i+1,j]=m then s:=s+1;
if NumArray[i,j-1]=m then s:=s+1;
if NumArray[i,j+1]=m then s:=s+1;
Result:=s;
end;
function LineLong(p,q,t:Integer):Integer; //墙长度
var
i,k,m:Integer;
begin
m:=0;
k:=t-1;
for i := 1 to k do
m:=m+Random(2);
k:=Random(t-m)+m;
m:=0;
for i := 1 to k do
m:=m+Random(2);
Result:=m;
end;
procedure PointDraw; //初始散点
var
i,m:Integer;
begin
m:=0;
for i := 1 to Num do
m:=m+Random(2);
m:=m-Trunc(Num/2);
if m>0 then
begin
for i := 1 to m do
MapArray[Random(Num)+1,Random(Num)+1]:=WallNum;
end;
end;
procedure LineDraw(p,q,s:Integer); //画一面墙
var
i,m,k,t:Integer;
begin
t:=0;
m:=0;
case s of
0:
begin
k:=p-1;
while m=0 do
begin
for i := 1 to 3 do
if MapArray[k,q+i-2]<>0 then m:=1;
if m=0 then
begin
t:=t+1;
if k=0 then break;
k:=k-1;
end;
end;
if t>1 then
begin
m:=LineLong(p-1,q,t);
for i := 1 to m do MapArray[p-i,q]:=WallNum;
end;
end;
1:
begin
k:=p+1;
while m=0 do
begin
for i := 1 to 3 do
if MapArray[k,q+i-2]<>0 then m:=1;
if m=0 then
begin
t:=t+1;
if k=Num-1 then break;
k:=k+1;
end;
end;
if t>1 then
begin
m:=LineLong(p+1,q,t);
for i := 1 to m do MapArray[p+i,q]:=WallNum;
end;
end;
2:
begin
k:=q-1;
while m=0 do
begin
for i := 1 to 3 do
if MapArray[p+i-2,k]<>0 then m:=1;
if m=0 then
begin
t:=t+1;
if k=0 then break;
k:=k-1;
end;
end;
if t>1 then
begin
m:=LineLong(p,q-1,t);
for i := 1 to m do MapArray[p,q-i]:=WallNum;
end;
end;
3:
begin
k:=q+1;
while m=0 do
begin
for i := 1 to 3 do
if MapArray[p+i-2,k]<>0 then m:=1;
if m=0 then
begin
t:=t+1;
if k=Num-1 then break;
k:=k+1;
end;
end;
if t>1 then
begin
m:=LineLong(p,q+1,t);
for i := 1 to m do MapArray[p,q+i]:=WallNum;
end;
end;
end;
end;
procedure WallCreat; //画所有墙
var
p,q,r,s: Integer;
begin
PointDraw;
for r :=1 to (Num+2)*(Num+2)*(Num+2) do
begin
p:=Random(Num+2);
q:=Random(Num+2);
s:=Random(4);
if ((p=Num+1)And(s<>0))Or((p=0)And(s<>1))Or((q=Num+1)And(s<>2))Or((q=0)And(s<>3)) then
continue;
if MapArray[p,q]<>0 then LineDraw(p,q,s);
end;
end;
procedure OffSetWall; // 某一特殊墙面的修改
var
i,j,s,t:Integer;
begin
for i := 2 to Num-1 do
for j := 2 to Num-1 do
begin
if MapArray[i,j]<>0 then continue;
s:=0;
if MapArray[i-1,j]<>0 then
begin
if MapArray[i-1,j-1]<>0 then continue;
if MapArray[i-1,j+1]<>0 then continue;
t:=0;
s:=s+1;
end;
if MapArray[i+1,j]<>0 then
begin
if MapArray[i+1,j-1]<>0 then continue;
if MapArray[i+1,j+1]<>0 then continue;
t:=1;
s:=s+1;
end;
if MapArray[i,j-1]<>0 then
begin
if MapArray[i-1,j-1]<>0 then continue;
if MapArray[i+1,j-1]<>0 then continue;
t:=2;
s:=s+1;
end;
if MapArray[i,j+1]<>0 then
begin
if MapArray[i-1,j+1]<>0 then continue;
if MapArray[i+1,j+1]<>0 then continue;
t:=3;
s:=s+1;
end;
if s<>1 then continue;
s:=0;
if MapArray[i-1,j-1]<>0 then s:=s+1;
if MapArray[i-1,j+1]<>0 then s:=s+1;
if MapArray[i+1,j-1]<>0 then s:=s+1;
if MapArray[i+1,j+1]<>0 then s:=s+1;
if s<>2 then continue;
case t of
0:
begin
if MapArray[i+2,j-1]=0 then
begin
MapArray[i+1,j-1]:=0;
MapArray[i+1,j]:=WallNum;
end
else if MapArray[i+2,j+1]=0 then
begin
MapArray[i+1,j+1]:=0;
MapArray[i+1,j]:=WallNum;
end;
end;
1:
begin
if MapArray[i-2,j-1]=0 then
begin
MapArray[i-1,j-1]:=0;
MapArray[i-1,j]:=WallNum;
end
else if MapArray[i-2,j+1]=0 then
begin
MapArray[i-1,j+1]:=0;
MapArray[i-1,j]:=WallNum;
end;
end;
2:
begin
if MapArray[i-1,j+2]=0 then
begin
MapArray[i-1,j+1]:=0;
MapArray[i,j+1]:=WallNum;
end
else if MapArray[i+1,j+2]=0 then
begin
MapArray[i+1,j+1]:=0;
MapArray[i,j+1]:=WallNum;
end;
end;
3:
begin
if MapArray[i-1,j-2]=0 then
begin
MapArray[i-1,j-1]:=0;
MapArray[i,j-1]:=WallNum;
end
else if MapArray[i+1,j-2]=0 then
begin
MapArray[i+1,j-1]:=0;
MapArray[i,j-1]:=WallNum;
end;
end;
end;
end;
end;
function OffSetSpace:Boolean; //区格填充,使之没有方块形
var
i,j,k,s:Integer;
t:Boolean;
begin
for k := 0 to Num*Num do
begin
for i := 1 to Num-1 do
for j := 1 to Num-1 do
begin
s:=0;
if MapArray[i,j]=0 then s:=s+1;
if MapArray[i,j+1]=0 then s:=s+1;
if MapArray[i+1,j]=0 then s:=s+1;
if MapArray[i+1,j+1]=0 then s:=s+1;
if s<>4 then continue;
t:=False;
if (MapArray[i-1,j]<>0)And(MapArray[i,j-1]<>0) then
begin
MapArray[i,j]:=10;
t:=True;
continue;
end;
if (MapArray[i-1,j+1]<>0)And(MapArray[i,j+2]<>0) then
begin
MapArray[i,j+1]:=10;
t:=True;
continue;
end;
if (MapArray[i+1,j-1]<>0)And(MapArray[i+2,j]<>0) then
begin
MapArray[i+1,j]:=10;
t:=True;
continue;
end;
if (MapArray[i+2,j+1]<>0)And(MapArray[i+1,j+2]<>0) then
begin
MapArray[i+1,j+1]:=10;
t:=True;
continue;
end;
end;
if Not t then break;
end;
Result:=t;
end;
function MainWay(p,q,t,n:Integer):Integer; //找主路径
var
i,j,k,m,s:Integer;
Label endMainWay;
begin
s:=1;
while s<>0 do
begin
case t of
0: p:=p-1;
1: p:=p+1;
2: q:=q-1;
3: q:=q+1;
end;
if MapArray[p,q]=2 then
begin
Result:=1;
break;
end;
if (MapArray[p-1,q]=2)Or(MapArray[p+1,q]=2)
Or(MapArray[p,q-1]=2)Or(MapArray[p,q+1]=2) then
begin
MapArray[p,q]:=12;
Result:=1;
break;
end;
s:=0;
if MapArray[p-1,q]<>0 then s:=s+1
else t:=0;
if MapArray[p+1,q]<>0 then s:=s+1
else t:=1;
if MapArray[p,q-1]<>0 then s:=s+1
else t:=2;
if MapArray[p,q+1]<>0 then s:=s+1
else t:=3;
case s of
1..2:
begin
MapArray[p,q]:=n;
while True do
begin
m:=2;
case Random(4) of
0:
if (MapArray[p-1,q]=0)Or(MapArray[p-1,q]=2) then m:=MainWay(p,q,0,n+1);
1:
if (MapArray[p+1,q]=0)Or(MapArray[p+1,q]=2) then m:=MainWay(p,q,1,n+1);
2:
if (MapArray[p,q-1]=0)Or(MapArray[p,q-1]=2) then m:=MainWay(p,q,2,n+1);
3:
if (MapArray[p,q+1]=0)Or(MapArray[p,q+1]=2) then m:=MainWay(p,q,3,n+1);
end;
if m=0 then
begin
for i := 1 to Num do
for j := 1 to Num do
if (MapArray[i,j]>10)And(MapArray[i,j]<20) then MapArray[i,j]:=0;
Result:=0;
goto endMainWay;
end;
if m=1 then
begin
for i := 1 to Num do
for j := 1 to Num do
if MapArray[i,j]=n+1 then MapArray[i,j]:=12;
Result:=1;
goto endMainWay;
end;
end;
end;
3: MapArray[p,q]:=n;
4:
begin
Result:=0;
break;
end;
end;
end;
endMainWay:
if Result<>1 then Result:=0;
end;
function FindWay(pSign:Integer):Integer; //确定树枝型路径
var
i,j,k,p,q,s,t:Integer;
begin
for k := 0 to Num*Num do
begin
s:=0;
for i := 1 to Num do
begin
for j := 1 to Num do
begin
if MapArray[i,j]<>0 then continue;
s:=0;
if MapArray[i-1,j]>2 then s:=s+1;
if MapArray[i+1,j]>2 then s:=s+1;
if MapArray[i,j-1]>2 then s:=s+1;
if MapArray[i,j+1]>2 then s:=s+1;
if s>2 then break;
end;
if s>2 then break;
end;
if s<3 then break
else
begin
p:=i;
q:=j;
while (s>2)And(MapArray[p,q]=0) do
begin
MapArray[p,q]:=pSign;
if MapArray[p-1,q]=0 then p:=p-1;
if MapArray[p+1,q]=0 then p:=p+1;
if MapArray[p,q-1]=0 then q:=q-1;
if MapArray[p,q+1]=0 then q:=q+1;
s:=0;
if (MapArray[p-1,q]>2)And(MapArray[p-1,q]<>12) then s:=s+1;
if (MapArray[p+1,q]>2)And(MapArray[p+1,q]<>12) then s:=s+1;
if (MapArray[p,q-1]>2)And(MapArray[p,q-1]<>12) then s:=s+1;
if (MapArray[p,q+1]>2)And(MapArray[p,q+1]<>12) then s:=s+1;
end;
pSign:=pSign+1;
end;
end;
Result:=pSign;
end;
procedure FindAllWay; //路径确定和区块划分
var
i,j,k,m,n,p,q,t:Integer;
pSign:Integer;
Label reFindWay,FindOut;
begin
pSign:=FindWay(20);
for i := 1 to Num do
begin
for j := 1 to Num do
begin
if MapArray[i,j]=1 then break;
end;
if MapArray[i,j]=1 then break;
end;
if MapArray[i-1,j]=0 then t:=0;
if MapArray[i+1,j]=0 then t:=1;
if MapArray[i,j-1]=0 then t:=2;
if MapArray[i,j+1]=0 then t:=3;
p:=i;
q:=j;
reFindWay:
while MainWay(p,q,t,12)=0 do;
for i := 1 to Num do
for j := 1 to Num do
if MapArray[p,q]=12 then
if BesideMap(p,q,12)=3 then goto reFindWay;
t:=1;
while t=1 do
begin
t:=0;
for i := 1 to Num do
for j := 1 to Num do
if MapArray[i,j]=0 then
begin
pSign:=FindWay(pSign);
MapArray[i,j]:=pSign;
t:=1;
pSign:=pSign+1;
goto FindOut;
end;
FindOut:
end;
for k := 20 to pSign do
begin
m:=0;
n:=0;
for i := 1 to Num do
for j := 1 to Num do
if MapArray[i,j]=k then
begin
m:=m+1;
if BesideMap(i,j,3)<3 then n:=n+1;
end;
if (m=1)And(n=1) then
begin
for i := 1 to Num do
begin
for j := 1 to Num do
if MapArray[i,j]=k then break;
if MapArray[i,j]=k then break;
end;
if (MapArray[i-1,j]>19)And(MapArray[i-1,j]<pSign+1) then MapArray[i,j]:=MapArray[i-1,j];
if (MapArray[i+1,j]>19)And(MapArray[i+1,j]<pSign+1) then MapArray[i,j]:=MapArray[i+1,j];
if (MapArray[i,j-1]>19)And(MapArray[i,j-1]<pSign+1) then MapArray[i,j]:=MapArray[i,j-1];
if (MapArray[i,j+1]>19)And(MapArray[i,j+1]<pSign+1) then MapArray[i,j]:=MapArray[i,j+1];
end;
end;
end;
procedure BackSpace;
var
i,j,k,s,t:Integer;
begin
CopyNum(1,3);
for k := 0 to Num*Num do
begin
t:=0;
for i := 1 to Num-1 do
for j := 1 to Num-1 do
begin
s:=0;
if (NumArray[i,j]=0)Or(NumArray[i,j]=10) then s:=s+1;
if (NumArray[i,j+1]=0)Or(NumArray[i,j+1]=10) then s:=s+1;
if (NumArray[i+1,j]=0)Or(NumArray[i+1,j]=10) then s:=s+1;
if (NumArray[i+1,j+1]=0)Or(NumArray[i+1,j+1]=10) then s:=s+1;
if s<>4 then continue;
s:=0;
if NumArray[i,j]=10 then s:=s+1;
if NumArray[i,j+1]=10 then s:=s+1;
if NumArray[i+1,j]=10 then s:=s+1;
if NumArray[i+1,j+1]=10 then s:=s+1;
if s<>4 then t:=t+1;
NumArray[i,j]:=10;
NumArray[i,j+1]:=10;
NumArray[i+1,j]:=10;
NumArray[i+1,j+1]:=10;
end;
if t=0 then break;
end;
end;
{procedure SolveWay;
var
i,j,k,m,n,l,nMax,s,t:Integer;
MaxArray:Array of Integer;
Label AgainSolve;
begin
t:=1;
for k := 1 to 9 do
t:=t+Random(2);
for i := 0 to Num*Num-1 do FindWayArray[i]:=-1;
s:=0;
for i := 0 to 9 do
for j := 1 to t do
begin
m:=i;
for k := 1 to t do
if Random(2)=0 then m:=m-1
else m:=m+1;
if (m>-1)And(m<10) then
begin
FindWayArray[s]:=m;
s:=s+1;
end;
end;
for i := 0 to Num*Num-1 do FindNumArray[i]:=0;
for n := 0 to 9 do
begin
CopyFloor(n);
if Number(0)>0 then FindAllWay;
CopyMap(n);
for l := 0 to Num*Num do
begin
if FindWayArray[l]=-1 then break;
if FindWayArray[l]<>n then continue;
nMax:=0;
for i := 1 to Num do
for j := 1 to Num do
if MapArray[i,j]>nMax then nMax:=MapArray[i,j];
SetLength(MaxArray,nMax-19);
AgainSolve:
for i := 0 to nMax-20 do
MaxArray[i]:=0;
for k := 0 to nMax-20 do
begin
while True do
begin
s:=20+Random(nMax-19);
if MaxArray[k]=0 then break;
end;
MaxArray[k]:=1;
t:=0;
for i := 1 to Num do
for j := 1 to Num do
begin
if MapArray[i,j]<>s then continue;
if MapArray[i-1,j]=12 then t:=1;
if MapArray[i+1,j]=12 then t:=1;
if MapArray[i,j-1]=12 then t:=1;
if MapArray[i,j+1]=12 then t:=1;
end;
if (t=1)And(Number(s)>0) then
begin
FindNumArray[l]:=s;
for i := 1 to Num do
for j := 1 to Num do
if MapArray[i,j]=s then MapArray[i,j]:=12;
break;
end;
if k=nMax-20 then goto AgainSolve;
end;
end;
end;
end; }
procedure AllSet;
var
i,j,m,p,q,s,sta:Integer;
b:Boolean;
begin
BackSpace;
//两个相邻的的方块
for i := 1 to Num do //被3夹着的变11
for j := 1 to Num do
begin
m:=MapArray[i,j];
if m<4 then continue;
if (MapArray[i-1,j]=3)And(MapArray[i+1,j]=3) then
begin
if (MapArray[i,j-1]=m)And(MapArray[i,j+1]<>3) then NumArray[i,j]:=11;
if (MapArray[i,j+1]=m)And(MapArray[i,j-1]<>3) then NumArray[i,j]:=11;
end;
if (MapArray[i,j-1]=3)And(MapArray[i,j+1]=3) then
begin
if (MapArray[i-1,j]=m)And(MapArray[i+1,j]<>3) then NumArray[i,j]:=11;
if (MapArray[i+1,j]=m)And(MapArray[i-1,j]<>3) then NumArray[i,j]:=11;
end;
end;
for i := 1 to Num do //被3夹着且周围有10的变12
for j := 1 to Num do
if (NumArray[i,j]>3)Or(NumArray[i,j]=0) then
begin
if BesideMap(i,j,3)<>2 then continue;
if (NumArray[i-1,j]=3)And(NumArray[i+1,j]=3) then
begin
if NumArray[i,j-1]=10 then NumArray[i,j]:=12;
if NumArray[i,j+1]=10 then NumArray[i,j]:=12;
end;
if (NumArray[i,j-1]=3)And(NumArray[i,j+1]=3) then
begin
if NumArray[i-1,j]=10 then NumArray[i,j]:=12;
if NumArray[i+1,j]=10 then NumArray[i,j]:=12;
end;
end;
for i := 1 to Num do //12边上的10变13或14
for j := 1 to Num do
begin
if NumArray[i,j]<>10 then continue;
if MapArray[i,j]=10 then NumArray[i,j]:=14;
if BesideNum(i,j,12)>0 then
begin
if (NumArray[i-1,j-1]=13)Or(NumArray[i-1,j+1]=13) then
begin
NumArray[i,j]:=14;
continue;
end;
case Random(3) of
0..1: NumArray[i,j]:=13;
2: NumArray[i,j]:=14;
end;
end;
end;
b:=True;
while b do //10边上有2个3和14或被3和14包围 ,10变14
begin
for i := 1 to Num do
for j := 1 to Num do