1 | unit UTetris;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UGame, UGraphics, fgl;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TShape = class
|
---|
12 | Body: array of Byte;
|
---|
13 | end;
|
---|
14 |
|
---|
15 | { TShapes }
|
---|
16 |
|
---|
17 | TShapes = class(TFPGObjectList<TShape>)
|
---|
18 | function AddNew(Body: array of Byte): TShape;
|
---|
19 | end;
|
---|
20 |
|
---|
21 | { TTetris }
|
---|
22 |
|
---|
23 | TTetris = class(TGame)
|
---|
24 | Shapes: TShapes;
|
---|
25 | Space: array of array of TColor;
|
---|
26 | procedure Paint(Canvas: TCanvas);
|
---|
27 | constructor Create; override;
|
---|
28 | destructor Destroy; override;
|
---|
29 | end;
|
---|
30 |
|
---|
31 | implementation
|
---|
32 |
|
---|
33 | { TShapes }
|
---|
34 |
|
---|
35 | function TShapes.AddNew(Body: array of Byte): TShape;
|
---|
36 | var
|
---|
37 | I: Integer;
|
---|
38 | begin
|
---|
39 | Result := TShape.Create;
|
---|
40 | SetLength(Result.Body, Length(Body));
|
---|
41 | for I := 0 to Length(Result.Body) - 1 do
|
---|
42 | Result.Body[I] := Body[I];
|
---|
43 | Add(Result);
|
---|
44 | end;
|
---|
45 |
|
---|
46 | { TTetris }
|
---|
47 |
|
---|
48 | procedure TTetris.Paint(Canvas: TCanvas);
|
---|
49 | begin
|
---|
50 | with Canvas do begin
|
---|
51 | Rectangle(Bounds(0, 0, Size.Width, Size.Height));
|
---|
52 | end;
|
---|
53 | end;
|
---|
54 |
|
---|
55 | constructor TTetris.Create;
|
---|
56 | begin
|
---|
57 | inherited;
|
---|
58 | Shapes := TShapes.Create;
|
---|
59 | Shapes.AddNew([2, 2, 2, 2]);
|
---|
60 | Shapes.AddNew([0, 6, 6, 0]);
|
---|
61 | Shapes.AddNew([2, 2, 6, 0]);
|
---|
62 | Shapes.AddNew([2, 6, 2, 0]);
|
---|
63 | Shapes.AddNew([2, 6, 4, 0]);
|
---|
64 | end;
|
---|
65 |
|
---|
66 | destructor TTetris.Destroy;
|
---|
67 | begin
|
---|
68 | Shapes.Free;
|
---|
69 | inherited;
|
---|
70 | end;
|
---|
71 |
|
---|
72 | end.
|
---|
73 |
|
---|