-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtetris.pas
More file actions
1345 lines (1093 loc) · 46.5 KB
/
tetris.pas
File metadata and controls
1345 lines (1093 loc) · 46.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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
program Tetris;
uses GraphWin; {System}
{ The constant below is the current version of the game, see the history
below in the comments. }
const Version = '1.41 (22/04/1998)';
{
INSTRUCTIONS
------------
INTRODUCTION
This is an implementation of the game Tetris, written in Turbo Pascal. It
supports an infinite number of players, although the speed will suffer. The
highest score is saved, and simple sound support exists.
THE KEYS
Currently all the keys are in lower case, although they can be modified
below, in the main program. You could easily fix it so the case is ignored,
if you wanted to.
/---------------------------------------\
|ACTION | PLAYER 1 | PLAYER 2 | PLAYER 3 |
|----------------------------------------|
| LEFT | z | j | 4 |
| RIGHT | x | l | 6 |
|ROTATE | c | i | 8 |
| DROP | <SPACE> | m | 2 |
\---------------------------------------/
OTHER BITS TO CHANGE
CONSTANTS Players The number of Players
Interactive Should it be a multiplayer
interactive?
Player<x> The position of the tetris bucket
Scale The size of the blocks
ASSIGNMENTS Speed (TGame.Create) The slowness of the game, reduce
to go faster.
WHY DID IT CRASH
* If you have added more buckets / enlarged them, and you start getting
mysterious crashes, try and increase the constant BoxesTotal.
* If you can't recompile, you need probably need GraphWin.tpu.
* If you're getting runtime errors, it probably can't find the highscore
file, try and add an empty (zero length) file called 'TetHi.dat' in the
same folder of the executeable.
WHAT CAN I DO?
Well, as well as playing the game, you could also try playing with the
constants, and other assignments. If you have some time, you could try and
implement some of the features in the to-do list below. For maschists, there
is always the documentation the really should be written.
To Do:
Make constructor TPiece.Create a pure virtual function, and make each
of the different Pieces types.
Make the area pushed up greater.
Raise start position of blocks
Remember what the cheats actually are.
Move hi-score code into the main program where in belongs - campaign
against globals!
Move sound support into procedures, to allow real sound later (different
effects for example.)
Make it cope with the high score file not being present.
Make a nice user interface with setup, restart, real high-score table,
GUI etc.
Add serial support for use in C102. ;-)
History:
1.0 First fully working version
1.1 17/03/1998 Added several cheats
1.2 19/03/1998 Now exits when all players are dead
Rotation of Square piece fixed
1.3 26/03/1998 Added high score.
1.4 02/04/1998 Added sound effects!
1.41 21/04/1998 Added some documentation.
If you manage to find where I put the cheats in this program, could you
tell me, as I have now forgotten where they were. Thanks.
}
{uses ToolHelp;}
type TColour = record
r, g, b:BYTE;
end;
TCoord = record
x, y:INTEGER;
end;
TRealCoord = record
x, y:REAL;
end;
const Scale =15;
Offset :TCoord=(x:00; y:70);
Left :TCoord=(x:-1; y: 0);
Right :TCoord=(x: 1; y: 0);
Up :TCoord=(x: 0; y:-1);
Down :TCoord=(x: 0; y: 1);
TopLeft :TCoord=(x: 0; y: 0);
SomeWhere :TCoord=(x: 5; y: 5);
Black :TColour=(r: 0; g: 0; b: 0);
Pink :TColour=(r:255; g:100; b: 0);
Red :TColour=(r:255; g: 0; b: 0);
Green :TColour=(r: 0; g:255; b: 0);
Blue :TColour=(r: 0; g: 0; b:255);
Cyan :TColour=(r: 0; g:255; b:255);
Grey :TColour=(r:128; g:128; b:128);
Yellow :TColour=(r:255; g: 0; b:255);
CheatActive :TColour=(r: 1; g: 0; b: 1);
LightBlue :TColour=(r:128; g: 20; b:128);
BoxesTotal =2000;
PieceSize =4;
var HiScoreF : FILE OF LONGINT;
HiScore : LONGINT;
{ Used ahead by TSolidSquare.SafeMove
}
function TestPosition(Pos:TCoord):BOOLEAN; forward;
FUNCTION Rad(Degrees:REAL) :REAL;
BEGIN
Rad:=(Degrees/180)*PI
END;
{ENDFN}
FUNCTION Pythagoras(Vec:TRealCoord) :REAL;
BEGIN
Pythagoras:=SQRT((Vec.x*Vec.x)+(Vec.y*Vec.y))
END;
{END FN}
FUNCTION Distance(Vec1, Vec2:TRealCoord) :REAL;
VAR Temp:TRealCoord;
BEGIN
Temp.x:=Vec1.x-Vec2.x;
Temp.y:=Vec1.y-Vec2.y;
Distance:=Pythagoras(Temp);
END;
function GStr(Num:INTEGER):STRING;
var Temp:STRING;
begin
Str(Num, Temp);
GStr:=Temp;
end;
{ *************************************************************************
**** Base graphics routines ****
*************************************************************************}
procedure SetGraphics (Pen, Brush:TColour; BrushT:INTEGER);
begin
SetPenColour(Pen.r, Pen.g, Pen.b);
SetBrushColour(Brush.r, Brush.g, Brush.b);
SetBrushStyle(BrushT);
end;
{endproc}
procedure PlotSquare (Location:TCoord);
begin
drawoblong((Location.x*Scale)+Offset.x , (Location.y*Scale)+Offset.y,
(Location.x*Scale)+Offset.x+Scale, (Location.y*Scale)+Offset.y+Scale);
end;
{endproc}
procedure EraseSquare (Location:TCoord);
begin
eraseoblong((Location.x*Scale)+Offset.x , (Location.y*Scale)+Offset.y,
(Location.x*Scale)+Offset.x+Scale, (Location.y*Scale)+Offset.y+Scale);
end;
{endproc}
procedure PlotString (Location:TCoord; text:STRING);
begin
drawtext((Location.x*Scale)+Offset.x, (Location.y*Scale)+Offset.y,text);
end;
{end proc}
procedure EraseString (Location:TCoord; text:STRING);
begin
erasetext((Location.x*Scale)+Offset.x, (Location.y*Scale)+Offset.y,text);
end;
{end proc}
{ *************************************************************************
**** The TSquare object ****
*************************************************************************}
type TSquare = object
PenColour:TColour;
BrushColour:TColour;
BrushType:INTEGER;
Place:TCoord;
procedure Move (OPlace:TCoord);
procedure MoveTo (NPlace:TCoord);
procedure SoftMove(NPlace:TCoord);
procedure SoftMoveTo(NPlace:TCoord);
constructor Create (NPenColour, NBrushColour:TColour; NBrushType:INTEGER; NPlace:TCoord);
destructor Destroy;
end;
procedure TSquare.move (OPlace:TCoord);
begin
if (OPlace.x=0) AND (OPlace.y=0) then
else
begin
SetGraphics(PenColour, BrushColour, BrushType);
EraseSquare(Place);
Place.x:=Place.x+OPlace.x;
Place.y:=Place.y+OPlace.y;
PlotSquare(Place);
end;
{endif}
end;
{end proc}
procedure TSquare.MoveTo(NPlace:TCoord);
begin
if NOT ((NPlace.x=Place.x) AND (NPlace.y=Place.y)) then
begin
SetGraphics(PenColour, BrushColour, BrushType);
EraseSquare(Place);
Place.x:=NPlace.x;
Place.y:=NPlace.y;
PlotSquare(Place);
end;
{endif}
end;
{end proc}
procedure TSquare.SoftMove(NPlace:TCoord);
begin
Place.x:=Place.x+NPlace.x;
Place.y:=Place.y+NPlace.y;
end;
{end proc}
procedure TSquare.SoftMoveTo(NPlace:TCoord);
begin
Place.x:=NPlace.x;
Place.y:=NPlace.y;
end;
{end proc}
constructor TSquare.Create (NPenColour, NBrushColour:TColour; NBrushType:INTEGER; NPlace:TCoord);
begin
PenColour:=NPenColour;
BrushColour:=NBrushColour;
BrushType:=NBrushType;
Place:=NPlace;
SetGraphics(PenColour, BrushColour, BrushType);
PlotSquare(Place);
end;
{endproc}
destructor TSquare.Destroy;
begin
SetGraphics(PenColour, BrushColour, BrushType);
EraseSquare(Place);
end;
{ *************************************************************************
**** The TSolidSquare object ****
*************************************************************************}
type TSolidSquare = object (TSquare)
Number:INTEGER;
Indestructable:BOOLEAN;
function SafeMove(OPlace:TCoord):BOOLEAN;
constructor Create (NPenColour, NBrushColour:TColour; NBrushType:INTEGER; NPlace:TCoord);
constructor Indes (NPenColour, NBrushColour:TColour; NBrushType:INTEGER; NPlace:TCoord);
destructor Destroy;
end;
var TSolidSquareList:ARRAY[1..BoxesTotal] of ^TSolidSquare;
function TSolidSquare.SafeMove (OPlace:TCoord):BOOLEAN;
var Finally:TCoord;
Result :BOOLEAN;
begin
Finally.x:=Place.x+OPlace.x;
Finally.y:=Place.y+OPlace.y;
Result:=TestPosition(Finally);
if (NOT Result) then move(OPlace);
SafeMove:=Result;
end;
{end fn}
function Collide(Ob:TSolidSquare):BOOLEAN;
var Search: INTEGER;
Test :^TSolidSquare;
Crash : BOOLEAN;
begin
Crash:=FALSE;
for Search:=1 to BoxesTotal do
begin
Test:=TSolidSquareList[Search];
if (Test<>nil) then
if (Test^.Number<>Ob.Number) then
begin
if ((Test^.Place.x=Ob.Place.x) AND (Test^.Place.y=Ob.Place.y)) then Crash:=TRUE;
end;
{end if}
{end if}
end;
{end for}
{WRITELN(Crash);}
Collide:=Crash;
end;
{end fn}
function TestPosition(Pos:TCoord):BOOLEAN;
var Search: INTEGER;
Test :^TSolidSquare;
Crash : BOOLEAN;
begin
Crash:=FALSE;
for Search:=1 to BoxesTotal do
begin
Test:=TSolidSquareList[Search];
if (Test<>nil) then
begin
if ((Test^.Place.x=Pos.x) AND (Test^.Place.y=Pos.y)) then Crash:=TRUE;
end;
{end if}
end;
{end for}
{WRITELN(Crash);}
TestPosition:=Crash;
end;
{end proc}
function DestroyMe(One:TCoord):BOOLEAN;
var Progress:INTEGER;
Caught :^TSolidSquare;
begin
for Progress:=1 to BoxesTotal do
if (TSolidSquareList[Progress]<>nil) then
if ((TSolidSquareList[Progress]^.Place.x=One.x) AND (TSolidSquareList[Progress]^.Place.y=One.y)) then
Caught:=TSolidSquareList[Progress];
DestroyMe:=NOT Caught^.Indestructable;
{dispose(Caught);}
{Caught^.Move(Left); }
end;
{end function}
constructor TSolidSquare.Create (NPenColour, NBrushColour:TColour; NBrushType:INTEGER; NPlace:TCoord);
var Search:INTEGER;
begin
Search:=1;
while (TSolidSquareList[Search]<>nil) do Search:=Search+1;
{TSolidSquareList:=Self;}
Number:=Search;
TSolidSquareList[Search]:=@Self;
TSquare.Create(NPenColour, NBrushColour, NBrushType, NPlace);
Indestructable:=FALSE;
end;
{end proc}
constructor TSolidSquare.Indes(NPenColour, NBrushColour:TColour; NBrushType:INTEGER; NPlace:TCoord);
begin
Create(NPenColour, NBrushColour, NBrushType, NPlace);
Indestructable:=TRUE;
end;
{end proc}
destructor TSolidSquare.Destroy;
begin
SetGraphics(PenColour, BrushColour, BrushType);
EraseSquare(Place);
TSolidSquareList[Number]:=nil;
end;
{end proc}
{ *************************************************************************
**** The Area Object ****
*************************************************************************}
type TSolidNess = (Solid, Ghostly, Dodgy);
type TArea = object
Start : TCoord;
Finish : TCoord;
function AnythingIn :BOOLEAN;
function AllFull :BOOLEAN;
procedure Fill(Pen, Brush:TColour; BrushType:INTEGER; SolidNess:TSolidNess);
procedure Move(Direction:TCoord);
procedure Zap;
constructor Create(S, F:TCoord);
constructor HLine(Place:TCoord; Len:INTEGER);
end;
function TArea.AnythingIn:BOOLEAN;
var Something :BOOLEAN;
Progress :TCoord;
begin
Something:=FALSE;
for Progress.x:=Start.x to Finish.x do
for Progress.y:=Start.y to Finish.y do
if TestPosition(Progress) then Something:=TRUE;
{end for}
{end for}
AnythingIn:=Something;
end;
{end function}
function TArea.AllFull:BOOLEAN;
var Full :BOOLEAN;
Progress :TCoord;
newob :^TSolidSquare;
begin
Full:=TRUE;
for Progress.x:=Start.x to Finish.x do
for Progress.y:=Start.y to Finish.y do
begin
{WRITELN(Progress.x, ' ',Progress.y); }
if (NOT TestPosition(Progress)) then begin
Full:=FALSE;
{WRITELN(Progress.x, ' ',Progress.y);}
{new(newob, Create(Red, Red, 1, Progress));}
end;
end;
{end for}
{end for}
AllFull:=Full;
end;
{end function}
{ Now with added obfustication absolutly free! }
procedure TArea.Fill(Pen, Brush:TColour; BrushType:INTEGER; SolidNess:TSolidNess);
var Progress : TCoord;
GhostOb :^TSquare;
SolidOb :^TSolidSquare;
begin
for Progress.x:=Start.x to Finish.x do
for Progress.y:=Start.y to Finish.y do
begin
if (SolidNess=Solid ) then new(SolidOb, Create(Pen, Brush, BrushType, Progress));
if (SolidNess=Ghostly) then new(GhostOb, Create(Pen, Brush, BrushType, Progress));
if (SolidNess=Dodgy ) then new(SolidOb, Indes (Pen, Brush, BrushType, Progress));
end;
{WRITELN('Finished');
READLN;
{Dummy}
end;
procedure TArea.Move(Direction:TCoord);
var Progress:INTEGER;
begin
for Progress:=1 to BoxesTotal do
if TSolidSquareList[Progress]<>nil then
with TSolidSquareList[Progress]^ do
if ((Place.x>=Start.x) AND (Place.y>=Start.y) AND
(Place.x<=Finish.x) AND (Place.y<=Finish.y)) then TSolidSquareList[Progress]^.Move(Direction);
end;
{end proc}
procedure TArea.Zap;
var Progress:INTEGER;
begin
for Progress:=1 to BoxesTotal do
if TSolidSquareList[Progress]<>nil then
with TSolidSquareList[Progress]^ do
if ((Place.x>=Start.x) AND (Place.y>=Start.y) AND
(Place.x<=Finish.x) AND (Place.y<=Finish.y)) then dispose(TSolidSquareList[Progress], Destroy);
{ end if}
{end with}
{end if}
{end if}
end;
{end proc}
constructor TArea.Create(S, F:TCoord);
begin
Start :=S;
Finish:=F;
end;
constructor TArea.HLine(Place:TCoord; Len:INTEGER);
var Sta, Fin:TCoord;
begin
Sta:=Place;
Fin.x:=Place.x+Len;
Fin.y:=Place.y;
Create(Sta, Fin);
end;
{ *************************************************************************
**** The TGfxString object ****
*************************************************************************}
type TGfxString = object
Place :TCoord;
Col :TColour;
Text :STRING;
procedure Change(Str:STRING);
constructor Create(Where:TCoord; Respray:TColour; Str:STRING);
destructor Destroy;
end;
procedure TGfxString.Change (Str:STRING);
begin
SetPenColour(Col.r, Col.g, Col.b);
EraseString(Place, Text);
Text:=Str;
PlotString(Place, Text);
end;
constructor TGfxString.Create(Where:TCoord; Respray:TColour; Str:STRING);
begin
{WRITELN('Hello Dave');}
Place:=Where;
Col:=Respray;
SetPenColour(Col.r, Col.g, Col.b);
SetGraphics(Black, Black, 0);
Text:=Str;
PlotString(Place,Str);
end;
destructor TGfxString.Destroy;
begin
SetPenColour(Col.r, Col.g, Col.b);
EraseString(Place, Text);
end;
{ *************************************************************************
**** The TScore object ****
*************************************************************************}
type TScore = object
Score :LONGINT;
Image :^TGfxString;
procedure Change(Scr:LONGINT);
procedure Increase(Inc:LONGINT);
function Read:LONGINT;
constructor Create(Where:TCoord; Scr:LONGINT);
constructor Reset (Where:TCoord);
destructor Destroy;
end;
procedure TScore.Change(Scr:LONGINT);
begin
if (Score<>Scr) then
begin
Score:=Scr;
Image^.Change(GStr(Score));
end;
{end if}
end;
{end proc}
procedure TScore.Increase(Inc:LONGINT);
var Temp:LONGINT;
begin
Temp:=Score+Inc;
Change(Temp);
end;
{end proc}
function TScore.Read:LONGINT;
begin
Read:=Score;
end;
{end function}
constructor TScore.Create(Where:TCoord; Scr:LONGINT);
begin
Score:=Scr;
new(Image, Create(Where, Black, GStr(Score)));
end;
constructor TScore.Reset(Where:TCoord);
begin
Create(Where,0);
end;
destructor TScore.Destroy;
begin
dispose(Image);
end;
{ *************************************************************************
**** The TPiece object ****
*************************************************************************}
type PieceType = (SquarePiece, LPiece, LongThinPiece, TeePiece, EssPiece,
EssPieceI, LPieceI);
type TPiece = object
Squares :array[1..PieceSize] of ^TSolidSquare;
Centre :TCoord;
Rotateable :BOOLEAN; {Squares shouldn't rotate }
procedure FillSquare(NPenColour, NBrushColour:TColour; NBrushType:INTEGER;
WhichOne, Location:TCoord);
function Move(Direction:TCoord; Update:BOOLEAN):BOOLEAN;
procedure Rotate;
function MoveTo(Target:TCoord):BOOLEAN;
constructor Any(Offset:TCoord);
constructor Create (Piece:PieceType; Offset:TCoord);
destructor Destroy;
destructor LeaveSquares;
end;
procedure TPiece.FillSquare (NPenColour, NBrushColour:TColour; NBrushType:INTEGER;
WhichOne, Location:TCoord);
var Position:TCoord;
Index :INTEGER;
begin
Position.x:=WhichOne.x+Location.x;
Position.y:=WhichOne.y+Location.y;
Index:=1;
while ((Squares[Index]<>nil) AND (Index<PieceSize)) do Index:=Index+1;
New(Squares[Index], Create(NPenColour, NBrushColour, NBrushType, Position));
end;
{end proc}
function TPiece.Move(Direction:TCoord; Update:BOOLEAN):BOOLEAN;
var Pos :INTEGER;
Inverted :TCoord;
dummy :BOOLEAN;
Failed :BOOLEAN;
const GetDown :TCoord=(x:1; y:-1);
begin
{WRITE(CHR(7)); }
Failed:=FALSE;
{ To iterate is human, to recurse if divine }
for Pos:=1 to PieceSize do
begin
if Squares[Pos]<>nil then
Squares[Pos]^.SoftMove(Direction);
{end if}
end;
{end for}
for Pos:=1 to PieceSize do
begin
if Squares[Pos]<>nil then
if Collide(Squares[Pos]^) then Failed:=TRUE;
{end if}
end;
{end for}
Inverted.x:=0-Direction.x;
Inverted.y:=0-Direction.y;
{
Centre.x:=Centre.x+Direction.x;
Centre.y:=Centre.y+Direction.y;
}
for Pos:=1 to PieceSize do
begin
if Squares[Pos]<>nil then
Squares[Pos]^.SoftMove(Inverted);
{end if}
end;
{end for}
Move:=Failed;
if NOT Failed then
begin
if Update then Centre.x:=Centre.x+Direction.x;
if Update then Centre.y:=Centre.y+Direction.y;
for Pos:=1 to PieceSize do
if Squares[Pos]<>nil then
Squares[Pos]^.Move(Direction);
{end if}
{end for}
end;
{end if}
end;
procedure TPiece.Rotate;
var Index :INTEGER;
var NewPlace :TCoord;
VNewPlace :TCoord;
Failed :BOOLEAN;
begin
{WriteMoo(CHR(7));}
if Rotateable then
begin
Failed:=FALSE;
for Index:=1 to PieceSize do
if (Squares[Index]<>nil) then
begin
NewPlace.x:=Squares[Index]^.Place.x-Centre.x;
NewPlace.y:=Squares[Index]^.Place.y-Centre.y;
VNewPlace.x:=0-NewPlace.y;
VNewPlace.y:=NewPlace.x;
NewPlace.x:=VNewPlace.x+Centre.x;
NewPlace.y:=VNewPlace.y+Centre.y;
Squares[Index]^.MoveTo(NewPlace);
{WRITELN;}
end;
{end if}
{end for}
for Index:=1 to PieceSize do
if (Squares[Index]<>nil) then
if Collide(Squares[Index]^) then Failed:=TRUE;
{endif}
{end for}
if Failed then TPiece.Rotate;
end;
{end if}
end;
function TPiece.MoveTo(Target:TCoord):BOOLEAN;
var Movement:TCoord;
begin
Movement.x:=Target.x-Centre.x;
Movement.y:=Target.y-Centre.y;
MoveTo:=Self.Move(Movement, TRUE);
end;
{end proc}
constructor TPiece.Any(Offset:TCoord);
var Temp:INTEGER;
begin
Temp:=Random(7);
if KeyPressed then
begin
if (Readkey='e') then
Temp:=CheatActive.r;
{end if}
end;
{end if}
case Temp of
0: Create(SquarePiece, Offset);
1: Create(LongThinPiece, Offset);
2: Create(LPiece, Offset);
3: Create(TeePiece, Offset);
4: Create(EssPiece, Offset);
5: Create(EssPieceI, Offset);
6: Create(LPieceI, Offset);
end;
end;
constructor TPiece.Create(Piece:PieceType; Offset:TCoord);
var Pos : TCoord;
Dodge: array[1..4, 1..4] of TCoord;
begin
for Pos.x:=1 to 4 do
for Pos.y:=1 to 4 do
begin
Squares[Pos.x]:=nil;
Dodge[Pos.x, Pos.y].x:=Pos.x;
Dodge[Pos.x, Pos.y].y:=Pos.y;
end;
{end next}
{end next}
Centre.x:=Offset.x+2;
Centre.y:=Offset.y+2;
Rotateable:=TRUE;
case Piece of
SquarePiece: begin
FillSquare(Black, Red, 1, Dodge[1, 1], Offset);
FillSquare(Black, Red, 1, Dodge[1, 2], Offset);
FillSquare(Black, Red, 1, Dodge[2, 1], Offset);
FillSquare(Black, Red, 1, Dodge[2, 2], Offset);
Rotateable:=FALSE;
end;
LongThinPiece: begin
FillSquare(Black, Green, 1, Dodge[2, 1], Offset);
FillSquare(Black, Green, 1, Dodge[2, 2], Offset);
FillSquare(Black, Green, 1, Dodge[2, 3], Offset);
FillSquare(Black, Green, 1, Dodge[2, 4], Offset);
end;
LPiece: begin
FillSquare(Black, Blue, 1, Dodge[1,1], Offset);
FillSquare(Black, Blue, 1, Dodge[2,1], Offset);
FillSquare(Black, Blue, 1, Dodge[3,1], Offset);
FillSquare(Black, Blue, 1, Dodge[3,2], Offset);
end;
TeePiece: begin
FillSquare(Black, Pink, 1, Dodge[1,2], Offset);
FillSquare(Black, Pink, 1, Dodge[2,2], Offset);
FillSquare(Black, Pink, 1, Dodge[3,2], Offset);
FillSquare(Black, Pink, 1, Dodge[2,3], Offset);
end;
EssPiece: begin
FillSquare(Black, Cyan, 1, Dodge[1,2], Offset);
FillSquare(Black, Cyan, 1, Dodge[2,2], Offset);
FillSquare(Black, Cyan, 1, Dodge[2,3], Offset);
FillSquare(Black, Cyan, 1, Dodge[3,3], Offset);
end;
EssPieceI: begin
FillSquare(Black, LightBlue, 1, Dodge[3,2], Offset);
FillSquare(Black, LightBlue, 1, Dodge[2,2], Offset);
FillSquare(Black, LightBlue, 1, Dodge[2,3], Offset);
FillSquare(Black, LightBlue, 1, Dodge[1,3], Offset);
end;
LPieceI: begin
FillSquare(Black, Yellow, 1, Dodge[1,2], Offset);
FillSquare(Black, Yellow, 1, Dodge[2,2], Offset);
FillSquare(Black, Yellow, 1, Dodge[3,2], Offset);
FillSquare(Black, Yellow, 1, Dodge[3,1], Offset);
end;
end;
end;
destructor TPiece.Destroy;
var Pos:INTEGER;
begin
WriteMoo(CHR(7));
for Pos:=1 to PieceSize do
if Squares[Pos]<>nil then
Dispose(Squares[Pos], Destroy);
{end if}
{end for}
end;
destructor TPiece.LeaveSquares;
begin
end;
{ *************************************************************************
**** TGame object ****
*************************************************************************}
type TGame = object
Frame :INTEGER;
Offset :TCoord;
Size :TCoord;
Start :TCoord;
ToStart :TCoord;
Next :TCoord;
Score :LONGINT;
Fast :BOOLEAN;
Speed :INTEGER;
CurrentPiece :^TPiece;
NextPiece :^TPiece;
CeasedToBe :BOOLEAN;
ToTake :INTEGER;
Points :^TScore;
procedure Poll;
procedure GoLeft;
procedure GoRight;
procedure Drop;
procedure Rot;
function TakeLines:INTEGER;
procedure PushUp;
procedure PushDown;
function SpareLines:BOOLEAN;
function Alive:BOOLEAN;
constructor Create(Where:TCoord);
end;
var Cheat:BOOLEAN;
procedure TGame.Poll;
var AreaObject:^TArea;
Bot, Top:TCoord;
ToGo:INTEGER;
Line:TCoord;
Highest:TCoord;
begin
if CeasedToBe then
begin
{Bugger All}
end
else
begin
Sleep(0.01);
if (Frame=Speed) OR Fast then
begin
if (CurrentPiece^.Move(Down, TRUE)) then
begin
Fast:=FALSE;
dispose(CurrentPiece, LeaveSquares);
Line.x:=Offset.x+1;
Line.y:=Offset.y-1;
Top.x:=Offset.x+1;
Top.y:=Offset.y-Size.y;
Bot.x:=Offset.x+Size.x-1;
Bot.y:=Offset.y-2;
Points^.Increase(10);
while (Line.y>(Offset.y-Size.y)) do
begin
new(AreaObject, HLine(Line, Size.x-2));
if AreaObject^.AllFull AND (DestroyMe(Line)) then
begin
AreaObject^.Zap;
{AreaObject^.Fill(Green, Pink, 1);}
dispose(AreaObject);
new(AreaObject, Create(Top, Bot));
{AreaObject^.Fill(Green, Pink, 1);
{Dummy}
AreaObject^.Move(Down);
dispose(AreaObject);
Points^.Increase(100);
ToTake:=ToTake+1;
end
else
begin
Bot.y:=Bot.y-1;
Line.y:=Line.y-1;
dispose(AreaObject);
end;
end;
CurrentPiece:=NextPiece;
{WRITELN(Start.x,' ',Start.y);}