From 8987b96aeb0937290320e6d9ed2e18ff706f3723 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 10 Apr 2026 09:56:05 +0200 Subject: =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=BE=D0=BD=D1=87=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B5=D1=82=D1=80=D0=B8=D1=81=20=D0=B8=D0=B7=207-=D0=B9?= =?UTF-8?q?=20=D0=B3=D0=BB=D0=B0=D0=B2=D1=8B,=20=D1=88=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=83=D0=BF=D1=80=D0=B0=D0=B6=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../7/6_tetris/unit2.pas" | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/7/6_tetris/unit2.pas" (limited to 'Занимательное программирование/7/6_tetris/unit2.pas') diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/7/6_tetris/unit2.pas" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/7/6_tetris/unit2.pas" new file mode 100644 index 0000000..2ac9fea --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/7/6_tetris/unit2.pas" @@ -0,0 +1,78 @@ +unit Unit2; + +{$mode ObjFPC} + +interface + +uses + Classes, SysUtils, Graphics; + +type + IGameHandler = interface + procedure DoIteration; + procedure Reset; + procedure Finish; + function IsFinished: Boolean; + end; + + TActionThread = class(TThread) + public + GameHandler: IGameHandler; + + constructor Create(AGameHandler: IGameHandler); + procedure Execute; override; + end; + +const + FieldHeight = 20; + FieldWidth = 10; { высота и ширина игрового поля } + Delay = 6; { Задержка падения фигуры (в кадрах). } + LinesPerLevel = 10; + +var + ActionThread: TActionThread; + MSecsPerFrame: Integer; { миллисекунд на кадр } + + Key_Space, Key_Left, Key_Right, Key_Down: Boolean; { состояния клавиш } + Bitmaps: array[0..4] of TBitmap; { "строительные блоки" } + Field: array[-1..FieldWidth, 0..FieldHeight] of Integer; { игровое поле } + Pieces: array[1..7, 0..3, 0..3] of Integer = ( + ((1,1,1,1), (0,0,0,0), (0,0,0,0), (0,0,0,0)), + ((1,1,0,0), (0,1,1,0), (0,0,0,0), (0,0,0,0)), + ((1,1,1,0), (0,0,1,0), (0,0,0,0), (0,0,0,0)), + ((1,1,0,0), (1,1,0,0), (0,0,0,0), (0,0,0,0)), + ((1,0,0,0), (1,1,0,0), (1,0,0,0), (0,0,0,0)), + ((0,0,1,0), (1,1,1,0), (0,0,0,0), (0,0,0,0)), + ((0,1,1,0), (1,1,0,0), (0,0,0,0), (0,0,0,0)) + ); + +implementation + +constructor TActionThread.Create(AGameHandler: IGameHandler); +begin + inherited Create(false); + GameHandler := AGameHandler +end; + +procedure TActionThread.Execute; +var + OldTime: TDateTime; + ToWait: Integer; +begin + while not GameHandler.IsFinished do + begin + OldTime := Now; + Synchronize(@GameHandler.DoIteration); + { Синхронизация с таймером. } + ToWait := Round(MSecsPerFrame - (Now - OldTime) * MSecsPerDay); + if ToWait > 0 then + Sleep(ToWait) + end; +end; + +exports + MSecsPerFrame, Bitmaps, Field, Pieces, + Key_Space, Key_Left, Key_Right, Key_Down; + +end. + -- cgit v1.2.3