-
Notifications
You must be signed in to change notification settings - Fork 0
/
fiveline.pas
1289 lines (1125 loc) · 28 KB
/
fiveline.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
(* RetroNick's version of popular fiveline puzzle/logic game *)
(* This Program is free and open source. Do what ever you like with *)
(* the code. Code has been ported from the DOS version *)
(* *)
(* If you can't sleep at night please visit my github and youtube *)
(* channel. A sub and follow would be nice :) *)
(* *)
(* Play Online *)
(* https://retronick.neocities.org/fiveline/game.html *)
(* *)
(* https://github.com/RetroNick2020 *)
(* https://www.youtube.com/channel/UCLak9dN2fgKU9keY2XEBRFQ *)
(* https://twitter.com/Nickshardware *)
(* [email protected] *)
(* *)
unit fiveline;
Interface
uses web,graph,palette,pathfind,squeue;
Const
ProgramName ='Fiveline v1.1';
ProgramAuthor = 'RetroNick';
ProgramReleaseDate = 'October 5 - 2021';
HSize = 9; (*if you cange hsize or vsize make sure to change in*)
VSize = 9; (*pathfind unit also*)
GBItemRadius = 10;
GBSQWidth = 30;
GBSQHeight = 30;
GBSQThick = 4;
GBItemEmpty = 0;
GBItemCrossHair = 1;
GBItemLocked = 2;
GBItemUnLocked = 3;
GBItemBorder = 4;
GBItemBorderRemove = 5;
GBItemRed = 10;
GBItemGreen = 11;
GBItemBrown = 12;
GBItemCyan = 13;
GBItemLightBlue = 14;
GBItemLightGray = 15;
GBItemBrick = 16;
UP = 72;
DOWN = 80;
LEFT = 75;
RIGHT = 77;
ENTER = 13;
CHEAT = 100;
QUIT = 101;
START = 102;
KEY0 = 103;
KEY1 = 104;
KEY2 = 105;
KEY3 = 106;
KEY4 = 107;
KEY5 = 108;
KEY6 = 109;
type
GameBoardRec = record
Item : integer;
end;
GameBoard = array[0..HSize-1,0..VSize-1] of GameBoardRec;
(*used for storing path when performing a MoveTo command*)
(*move piece another valid position*)
pathpoints = record
x,y : integer;
end;
(*used for storing all the item/color lines that are 5 items (or more) wide*)
itempoints = record
x,y,stepx,stepy,item,count : integer;
end;
ItemLockRec = record
isLocked : boolean;
x,y : integer;
end;
CrossHairRec = record
isVisible : boolean;
x,y : integer;
lastx,lasty : integer;
end;
DrawItemRec = Record
x,y,item,delay : integer;
end;
apathpoints = array of pathpoints;
aitempoints = array[0..1000] of itempoints;
aqueuedrawitems = array[1..1000] of drawitemrec;
DrawQueueRec = Record
Queue : aqueuedrawitems;
Count : integer;
TickDelay : integer;
Processing : boolean;
end;
scoreRec = Record
xoff,yoff : integer;
score : longint;
mx : integer;
pos : integer;
end;
helpRec = record
xoff,yoff : integer;
end;
GBPosRec = Record
xoff,yoff : integer;
end;
var
GB : GameBoard;
GBPos : GBPosRec;
GBItemLock : ItemLockRec;
GBCrossHair : CrossHairRec;
GBRowsCleared : Boolean;
aiCounter : integer;
GBDraw : DrawQueueRec;
score : ScoreRec;
help : helpRec;
cheatmode : boolean;
gameover : boolean;
Procedure ProcessKeys(k : integer);
Procedure fivelineInit;
procedure DrawQueueProcessTimer;
implementation
Procedure delay(ms : integer);
begin
end;
function IntToStr(num : longint) : string;
var
TStr :string;
begin
Str(num,TStr);
IntToStr:=TStr;
end;
Procedure InitGameBoard;
var
i, j : integer;
begin
for j:=0 to vsize-1 do
begin
for i:=0 to hsize-1 do
begin
GB[i,j].Item:=GBItemEmpty;
end;
end;
end;
Procedure InitItemLock;
begin
GBItemLock.isLocked:=false;
GBItemLock.x:=0;
GBItemLock.y:=0;
end;
Procedure InitCrossHair;
begin
GBCrossHair.x:=4;
GBCrossHair.y:=4;
GBCrossHair.isVisible:=true;
end;
Procedure InitAiQueue;
begin
aiCounter:=0;
end;
procedure GB_Bar(x,y,x2,y2 : integer);
begin
Bar(x+GBPos.xoff,y+GBPos.yoff,x2+GBPos.xoff,y2+GBPos.yoff);
end;
procedure GB_Rectangle(x,y,x2,y2 : integer);
begin
Rectangle(x+GBPos.xoff,y+GBPos.yoff,x2+GBPos.xoff,y2+GBPos.yoff);
end;
procedure GB_Line(x,y,x2,y2 : integer);
begin
Line(x+GBPos.xoff,y+GBPos.yoff,x2+GBPos.xoff,y2+GBPos.yoff);
end;
procedure GB_FillEllipse(x,y,r1,r2 : integer);
begin
FillEllipse(x+GBPos.xoff,y+GBPos.yoff,r1,r2);
end;
procedure DrawFilledRect(x,y : integer);
begin
GB_Bar(x*GBSQWidth+1,y*GBSQHeight+1,
x*GBSQWidth+GBSQWidth-1,y*GBSQHeight+GBSQHeight-1);
end;
procedure DrawRect(x,y,Thick : integer);
var
i : integer;
begin
for i:=1 to Thick do
begin
GB_Rectangle(x*GBSQWidth+i+1,y*GBSQHeight+i+1,x*GBSQWidth+GBSQWidth-i-1,y*GBSQHeight+GBSQHeight-i-1);
end;
end;
procedure DrawCross(x,y,w,h,wthick,hthick : integer);
var
xoff,yoff,wtoff,htoff : integer;
begin
xoff:=(GBSQWidth-w) div 2;
yoff:=(GBSQHeight-h) div 2;
wtoff:=(GBSQHeight-wthick) div 2;
htoff:=(GBSQWidth-hthick) div 2;
(* - *)
GB_Bar(x*GBSQWidth+xoff,y*GBSQHeight+wtoff,
x*GBSQWidth+xoff+w, y*GBSQHeight+wtoff+wthick);
(* | *)
GB_Bar(x*GBSQWidth+htoff,y*GBSQHeight+yoff,
x*GBSQWidth+htoff+hthick,y*GBSQHeight+yoff+h);
end;
Procedure DrawFillEllip(x,y,r : integer);
var
xoff,yoff : integer;
begin
xoff:=GBSQWidth div 2;
yoff:=GBSQHeight div 2;
GB_FillEllipse(x*GBSQWidth+xoff,y*GBSQHeight+yoff,r,r);
end;
Procedure DrawGameBoardItem(x,y,item : integer);
begin
if item=GBItemEmpty then
begin
SetFillStyle(SolidFill,Blue);
DrawFilledRect(x,y);
end
else if item=GBItemLocked then
begin
SetColor(Brown);
DrawRect(x,y,GBSQThick);
end
else if item=GBItemUnLocked then
begin
SetColor(Blue);
DrawRect(x,y,GBSQThick);
end
else if item=GBItemBorder then
begin
SetColor(Yellow);
DrawRect(x,y,GBSQThick);
end
else if item=GBItemBorderRemove then
begin
SetColor(Blue);
DrawRect(x,y,GBSQThick);
end
else if item=GBItemBrick then
begin
SetFillStyle(xHatchFill,Yellow);
DrawFilledRect(x,y);
end
else if item=GBItemCrossHair then
begin
SetFillStyle(SolidFill,Black);
DrawCross(x,y,13,13,3,3);
end
else if item=GBItemRed then
begin
SetColor(Black);
SetFillStyle(SolidFill,Red);
DrawFillEllip(x,y,GBItemRadius);
end
else if item=GBItemGreen then
begin
SetColor(Black);
SetFillStyle(SolidFill,Green);
DrawFillEllip(x,y,GBItemRadius);
end
else if item=GBItemBrown then
begin
SetColor(Black);
SetFillStyle(SolidFill,Brown);
DrawFillEllip(x,y,GBItemRadius);
end
else if item=GBItemCyan then
begin
SetColor(Black);
SetFillStyle(SolidFill,Cyan);
DrawFillEllip(x,y,GBItemRadius);
end
else if item=GBItemLightGray then
begin
SetColor(Black);
SetFillStyle(SolidFill,LightGray);
DrawFillEllip(x,y,GBItemRadius);
end
else if item=GBItemLightBlue then
begin
SetColor(Black);
SetFillStyle(SolidFill,lightblue);
DrawFillEllip(x,y,GBItemRadius);
end;
end;
Procedure InitDrawQueue;
begin
GBDraw.Count:=0;
GBDraw.Processing:=false;
GBDraw.TickDelay:=0;
end;
Procedure QueueDrawItem(x,y,item,delay : integer);
begin
if GBDraw.Count < 1000 then
begin
inc(GBDraw.Count);
GBDraw.Queue[GBDraw.Count].x:=x;
GBDraw.Queue[GBDraw.Count].y:=y;
GBDraw.Queue[GBDraw.Count].item:=item;
GBDraw.Queue[GBDraw.Count].delay:=delay;
end;
end;
Procedure GetQueueDrawItem(var di : drawitemrec);
var
i : integer;
begin
if GBDraw.Count > 0 then
begin
di:=GBDraw.Queue[1];
for i:=2 to GBDraw.Count do
begin
GBDraw.Queue[i-1]:=GBDraw.Queue[i];
end;
dec(GBDraw.Count);
end;
end;
function GetQueueDrawCount : integer;
begin
GetQueueDrawCount:=GBDraw.Count;
end;
procedure DrawQueueProcessTimer;
var
di : drawitemrec;
begin
if (GBDraw.Processing = false) and (GBDraw.Count > 0) then
begin
GetQueueDrawItem(di);
DrawGameBoardItem(di.x,di.y,di.item);
GBDraw.Processing := true;
GBDraw.TickDelay:=di.delay;
end
else
begin
if GBDraw.Processing then
begin
if GBDraw.TickDelay > 0 then
begin
Dec(GBDraw.TickDelay);
end
else
begin
GBDraw.Processing:=false;
end;
end;
end;
end;
procedure DrawCrossHair;
begin
// DrawGameBoardItem(GBCrossHair.x,GBCrossHair.y,GBItemCrossHair);
QueueDrawItem(GBCrossHair.x,GBCrossHair.y,GBItemCrossHair,0);
end;
procedure DrawLocked;
begin
if GBItemLock.isLocked then
begin
//DrawGameBoardItem(GBItemLock.x,GBItemLock.y,GBItemLocked);
QueueDrawItem(GBItemLock.x,GBItemLock.y,GBItemLocked,0);
end
else
begin
//DrawGameBoardItem(GBItemLock.x,GBItemLock.y,GBItemUnLocked);
QueueDrawItem(GBItemLock.x,GBItemLock.y,GBItemUnLocked,0);
end;
end;
procedure MoveCrossHairLeft;
begin
if GBCrossHair.x > 0 then
begin
(* erase cross hair by redrawing item at location x,y*)
// DrawGameBoardItem(GBCrossHair.x,
// GBCrossHair.y,
// GB[GBCrossHair.x,GBCrossHair.y].Item);
QueueDrawItem(GBCrossHair.x,
GBCrossHair.y,
GB[GBCrossHair.x,GBCrossHair.y].Item,0);
(* update current *)
dec(GBCrossHair.x);
DrawCrossHair;
end;
end;
procedure MoveCrossHairRight;
begin
if GBCrossHair.x < (HSIZE-1) then
begin
(*erase cross hair by redrawing item at location x,y*)
//DrawGameBoardItem(GBCrossHair.x,
// GBCrossHair.y,
// GB[GBCrossHair.x,GBCrossHair.y].Item);
QueueDrawItem(GBCrossHair.x,
GBCrossHair.y,
GB[GBCrossHair.x,GBCrossHair.y].Item,0);
(*update current x*)
inc(GBCrossHair.x);
(*draw cross hair at updated x,y*)
DrawCrossHair;
end;
end;
procedure MoveCrossHairDown;
begin
if GBCrossHair.y < (VSIZE-1) then
begin
(*erase cross hair by redrawing item at location x,y*)
//DrawGameBoardItem(GBCrossHair.x,
// GBCrossHair.y,
// GB[GBCrossHair.x,GBCrossHair.y].Item);
QueueDrawItem(GBCrossHair.x,
GBCrossHair.y,
GB[GBCrossHair.x,GBCrossHair.y].Item,0);
(*update current y*)
inc(GBCrossHair.y);
(*draw cross hair at updated x,y*)
DrawCrossHair;
end;
end;
procedure MoveCrossHairUp;
begin
if GBCrossHair.y > 0 then
begin
(*erase cross hair by redrawing item at location x,y*)
//DrawGameBoardItem(GBCrossHair.x,
// GBCrossHair.y,
// GB[GBCrossHair.x,GBCrossHair.y].Item);
QueueDrawItem(GBCrossHair.x,
GBCrossHair.y,
GB[GBCrossHair.x,GBCrossHair.y].Item,0);
(*update current y*)
dec(GBCrossHair.y);
(*draw cross hair at updated x,y*)
DrawCrossHair;
end;
end;
Procedure DrawGameGrid;
var
i,j : integer;
begin
SetFillStyle(SolidFill,Blue);
GB_Bar(0,0,HSize*GBSQWidth,Vsize*GBSQHeight);
SetColor(white);
GB_Rectangle(0,0,HSize*GBSQWidth,VSize*GBSQHeight);
for i:=1 to HSize-1 do
begin
GB_line(i*GBSQWidth,0,i*GBSQWidth,VSize*GBSQHeight);
end;
for j:=1 to VSize-1 do
begin
GB_line(0,j*GBSQHeight,HSize*GBSQWidth,j*GBSQHeight);
end;
end;
Procedure DrawGameBoardItems;
var
i,j : integer;
begin
for j:=0 to VSIZE-1 do
begin
for i:=0 to HSIZE-1 do
begin
DrawGameBoardItem(i,j,GB[i,j].Item);
end;
end;
DrawLocked;
DrawCrossHair;
end;
Procedure DrawGameBoard;
begin
DrawGameGrid;
DrawGameBoardItems;
end;
(*as long it is not empty it should be moveable*)
Function canSelectItem(x,y : integer) : Boolean;
begin
canSelectItem:=(GB[x,y].Item <> GBItemEmpty);
end;
(*from selected position*)
function canMoveTo(x,y : integer) : Boolean;
begin
canMoveTo:=(GB[x,y].Item = GBItemEmpty);
end;
Procedure MoveGameBoardItem(startx,starty,endx,endy : integer);
begin
GB[endx,endy].Item:=GB[startx,starty].Item;
GB[startx,starty].Item:=GBItemEmpty;
end;
function isPosInRange(x,y : integer) : boolean;
var
maxx,maxy : integer;
begin
maxx:=HSIZE-1;
maxy:=VSIZE-1;
isPosInRange:=(x>=0) and (x<=maxx) and (y>=0) and (y<=maxy);
end;
function isColorSame(Var TGB : GameBoard;x1,y1,x2,y2 : integer) : boolean;
var
c1,c2 : integer;
begin
c1:=TGB[x1,y1].Item;
c2:=TGB[x2,y2].Item;
IsColorSame:=(c1>0) and (c1=c2);
end;
(*looks for continous color in any direction*)
(*stepx and stepy can be 0 or 1 or -1*)
function FindColorCount(Var TGB : GameBoard;startx,starty,stepx,stepy,count : integer) : integer;
var
i,c : integer;
xpos,ypos : integer;
begin
xpos:=startx;
ypos:=starty;
c:=1;
for i:=1 to count-1 do
begin
if isPosInRange(xpos,ypos) and isPosInRange(xpos+stepx,ypos+stepy) then
begin
if isColorSame(TGB,xpos,ypos,xpos+stepx,ypos+stepy) then
begin
inc(c);
end
else
begin
FindColorCount:=c;
exit;
end;
end;
inc(xpos,stepx);
inc(ypos,stepy);
end;
FindColorCount:=c;
end;
procedure AddRowsToQueue(x,y,stepx,stepy,count : integer;
var apoints : aitempoints);
begin
apoints[aiCounter].item:=GB[x,y].Item;
apoints[aiCounter].x:=x;
apoints[aiCounter].y:=y;
apoints[aiCounter].stepx:=stepx;
apoints[aiCounter].stepy:=stepy;
apoints[aiCounter].count:=count;
inc(aiCounter);
end;
Procedure SetGameBoardPos(xpos,ypos : integer);
begin
GBPos.xoff:=xpos;
GBPos.yoff:=ypos;
end;
Procedure SetGameHelpPos(xpos,ypos : integer);
begin
help.xoff:=xpos;
help.yoff:=ypos;
end;
Procedure SetGameScorePos(xpos,ypos : integer);
begin
score.xoff:=xpos;
score.yoff:=ypos;
end;
procedure DrawTitle;
begin
SetTextStyle(DefaultFont,HorizDir,2);
SetColor(white);
OutTextXY(10,10,ProgramName);
OutTextXY(10,30,'By '+ProgramAuthor);
SetTextStyle(DefaultFont,HorizDir,1);
OutTextXY(10,50,'Released on '+ProgramReleaseDate);
end;
procedure DrawGameOver;
Procedure TM;
begin
SetTextStyle(DefaultFont,HorizDir,2);
SetColor(Yellow);
OutTextXY(GBPos.xoff+65,GBPos.yoff+160,'Game Over');
end;
begin
window.setTimeout(@TM,1000);
end;
procedure DrawHelp;
var
w,h : integer;
begin
w:=400;
h:=250;
SetTextStyle(DefaultFont,HorizDir,1);
SetColor(Yellow);
SetFillStyle(SolidFill,Blue);
Bar(help.xoff,help.yoff,help.xoff+w,help.yoff+h);
OutTextXY(help.xoff+10,help.yoff+10, 'How To Play Fiveline');
SetColor(White);
OutTextXY(help.xoff+10,help.yoff+30, 'Arrange five or more balls of same');
OutTextXY(help.xoff+10,help.yoff+44, 'color in any direction to remove');
OutTextXY(help.xoff+10,help.yoff+58, 'from board. Each failed attempt ');
OutTextXY(help.xoff+10,help.yoff+72, 'will introduce more balls to the');
OutTextXY(help.xoff+10,help.yoff+86, 'board. Use arrow keys and Enter');
OutTextXY(help.xoff+10,help.yoff+100,'key to select your ball. Move ');
OutTextXY(help.xoff+10,help.yoff+114,'crosshair to an empty location and');
OutTextXY(help.xoff+10,help.yoff+128,'press ENTER to move your ball.');
OutTextXY(help.xoff+10,help.yoff+142,'Only balls with a valid path can');
OutTextXY(help.xoff+10,help.yoff+156,'be moved!');
SetColor(Yellow);
OutTextXY(help.xoff+10,help.yoff+176,'R = Restart Game');
OutTextXY(help.xoff+10,help.yoff+196,'X or Q = QUIT');
OutTextXY(help.xoff+10,help.yoff+216,'C = Enable/Disable cheat mode');
if cheatmode then
begin
SetColor(Green);
OutTextXY(help.xoff+10,help.yoff+230,'Keys 0 1 2 3 4 5 6 are Enabled');
end;
end;
Procedure DisplayScore(justscore : boolean);
var
w,h : integer;
begin
w:=400;
h:=70;
SetColor(White);
SetFillStyle(SolidFill,Blue);
if justscore = false then
begin
Bar(Score.xoff,score.yoff,Score.xoff+w,score.yoff+h);
SetTextStyle(DefaultFont,HorizDir,2);
OutTextXY(Score.xoff+10,score.yoff+8,'SCORE:');
end;
(*erase previouse score and line points*)
SetFillStyle(SolidFill,Blue);
Bar(Score.xoff,score.yoff+28,Score.xoff+w,score.yoff+h);
SetTextStyle(DefaultFont,HorizDir,2);
OutTextXY(Score.xoff+10,score.yoff+30,IntToStr(score.score));
SetColor(Yellow);
OutTextXY(Score.xoff+10,score.yoff+50,IntToStr(score.pos)+'x'+IntToStr(score.mx));
end;
procedure UpdateScore(pos, count : integer);
procedure TM;
begin
score.pos:=pos;
score.mx:=abs(4-count)*10; (*5 line rows = 10 points per ball, 6 line = 20, 7 line =30*)
Inc(score.Score,score.mx);
DisplayScore(true);
end;
begin
window.setTimeout(@TM,pos*300);
end;
procedure DrawRowBoarder(x,y,stepx,stepy,count : integer; item : integer);
var
i : integer;
begin
for i:=1 to count do
begin
// DrawGameBoardItem(x,y,item);
QueueDrawItem(x,y,item,10);
inc(x,stepx);
inc(y,stepy);
(*update score as we are removing the row*)
if item = GBItemEmpty then UpdateScore(i,count);
// Delay(DBDelay);
end;
end;
procedure DrawRowOfColors(var apoints : aitempoints;item : integer);
var
i : integer;
begin
for i:=0 to aiCounter-1 do
begin
DrawRowBoarder(apoints[i].x,apoints[i].y,
apoints[i].stepx,apoints[i].stepy,
apoints[i].count,item);
end;
end;
procedure DeleteRowFromBoard(var TGB : GameBoard; x,y,stepx,stepy,count : integer);
var
i : integer;
begin
for i:=1 to count do
begin
TGB[x,y].Item:=GBItemEmpty;
inc(x,stepx);
inc(y,stepy);
end;
end;
//TODO:
// this is a work arround to performing TGB:=GB in FindRowOfColors
// the second/third/fourth assignment doesn't take affect
// maybe a compiler bug. need to test - yes confirmed this is a bug.
// using pas2js 2.0.6 - should be fixed in next version
procedure copygbtotgb(var SGB, TGB : GameBoard);
var i,j : integer;
begin
for j:=0 to VSize-1 do
begin
for i:=0 to HSize-1 do
begin
TGB[i,j]:=SGB[i,j];
end;
end;
end;
function FindRowOfColors(var apoints : aitempoints) : integer;
var
TGB : GameBoard;
i,j : integer;
count : integer;
rowcount : integer;
begin
rowcount:=0;
// (*Make Copy GM*)
// TGB:=GB;
copygbtotgb(GB,TGB);
//(*horizonatal check*)
for j:=0 to VSize-1 do
//(*//VSIZE-1 0 to 8*)
begin
for i:=0 to HSize-5 do
//(*HSIZE-5 0 to 4*)
begin
count:=FindColorCount(TGB,i,j,1,0,9);
if count > 4 then
begin
inc(rowcount);
AddRowsToQueue(i,j,1,0,count,apoints);
// (*Remove Line from from TGB - solves 6 to 9 in a row duplicate problem*)
DeleteRowFromBoard(TGB,i,j,1,0,count);
end;
end;
end;
// (*Make Copy GM Again - not a mistake*)
// TGB:=GB;
copygbtotgb(GB,TGB);
// (*vertical check*)
for i:=0 to HSize-1 do
//(*HSIZE-1 0 to 8*)
begin
for j:=0 to VSize-5 do
//(*VSIZE-5 0 to 4*)
begin
count:=FindColorCount(TGB,i,j,0,1,9);
if count > 4 then
begin
inc(rowcount);
AddRowsToQueue(i,j,0,1,count,apoints);
// (*Remove Line from from TGB - solves 6 to 9 in a row duplicate problem*)
DeleteRowFromBoard(TGB,i,j,0,1,count);
end;
end;
end;
// (*Make Copy GM 3rd time*)
// TGB:=GB;
copygbtotgb(GB,TGB);
// (*horizonatal down/right*)
for j:=0 to VSize-5 do
//(*VSIZE-5 0 to 4*)
begin
for i:=0 to HSize-5 do
//(*HSIZE-5 0 to 4*)
begin
count:=FindColorCount(TGB,i,j,1,1,9);
if count > 4 then
begin
inc(rowcount);
AddRowsToQueue(i,j,1,1,count,apoints);
// (*Remove Line from from TGB - solves 6 to 9 in a row duplicate problem*)
DeleteRowFromBoard(TGB,i,j,1,1,count);
end;
end;
end;
// (*Make Copy GM 4th time*)
// TGB:=GB;
copygbtotgb(GB,TGB);
// (*horizonatal down/left*)
for j:=0 to VSize-5 do
//(*VSIZE-5 0 to 4*)
begin
for i:=4 to HSize-1 do
//(*HSIZE-1 4 to 8*)
begin
count:=FindColorCount(TGB,i,j,-1,1,9);
if count > 4 then
begin
inc(rowcount);
AddRowsToQueue(i,j,-1,1,count,apoints);
// (*Remove Line from from TGB - solves 6 to 9 in a row duplicate problem*)
DeleteRowFromBoard(TGB,i,j,-1,1,count);
end;
end;
end;
FindRowOfColors:=rowcount;
end;
Function ValidMovesLeft : integer;
var
count,i,j : integer;
begin
count:=0;
for j:=0 to VSize-1 do
begin
for i:=0 to Hsize-1 do
begin
if GB[i,j].Item = GBItemEmpty then inc(count);
end;
end;
ValidMovesLeft:=count;
end;
Function isGameOver : boolean;
begin
isGameOver:=(ValidMovesLeft = 0);
end;
Procedure GetXYForMoveX(mvx : integer;var x,y : integer);
var
i,j : integer;
count : integer;
begin
count:=0;
x:=-1;
y:=-1;
for j:=0 to VSize-1 do
begin
for i:=0 to Hsize-1 do
begin
if GB[i,j].Item = GBItemEmpty then inc(count);
if count = mvx then
begin
x:=i;
y:=j;
exit;
end;
end;
end;
end;
Procedure GetRandomSpot(var x,y : integer);
var
r : integer;
vcount : integer;
begin
x:=-1;
y:=-1;
vcount:=ValidMovesLeft;
if vcount > 0 then
begin
r:=random(vcount)+1;
GetXYForMoveX(r,x,y);
end;
end;
Function GetRandomItem : integer;
begin
GetRandomItem:=random(6)+GBItemRed;
end;
(*for debug / cheat mode*)
Procedure PlotItem(item : integer);
begin
GB[GBCrossHair.x,GBCrossHair.y].Item:=item;
DrawGameBoardItem(GBCrossHair.x,GBCrossHair.y,item);
DrawCrossHair;
end;
Procedure LockItem;
begin
if GB[GBCrossHair.x,GBCrossHair.y].Item<>GBItemEmpty then
begin
if GBItemLock.isLocked then
begin
GBItemLock.isLocked:=false;
DrawLocked; (*erase current lock*)
end;
GBItemLock.x:=GBCrossHair.x;
GBItemLock.y:=GBCrossHair.y;
GBItemLock.isLocked:=true;
DrawLocked;
end;
end;
(* Copy GameBoard data to PGrid in a format that our path finding algorithm*)
(* can make use of it. each color ball is considered a wall/obstacle.*)
Procedure CopyGbToPga(Var PGrid : PGA);
var
i,j : integer;
begin
For j:=0 to VSize-1 do
begin
for i:=0 to HSize-1 do
begin
if GB[i,j].Item<>GBItemEmpty then PlaceWall(PGrid,i,j);
end;
end;
end;
function isPathToItem(sx,sy,tx,ty : integer) : boolean;