From 3dff805e9bf157e9481117b5e9ca74d808b1ffb8 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 26 Mar 2026 20:04:24 +0100 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=81=D0=BE=D0=BA=D0=BE=D0=B1=D0=B0=D0=BD=20=D0=B8=D0=B7=207-?= =?UTF-8?q?=D0=B9=20=D0=B3=D0=BB=D0=B0=D0=B2=D1=8B,=20=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D1=82=D1=8C=D0=B5=D0=B3=D0=BE=20=D1=83=D0=BF=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../7/3_sokoban/Unit1.pas" | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'Занимательное программирование/7/3_sokoban/Unit1.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/3_sokoban/Unit1.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/3_sokoban/Unit1.pas" index bdb2a92..22ad44d 100644 --- "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/3_sokoban/Unit1.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/3_sokoban/Unit1.pas" @@ -30,7 +30,7 @@ type end; const - WALL = 11; SPACE = 10; BOULDER = 1; + WALL = 11; SPACE = 10; SL = 14; SR = 15; SU = 12; SD = 13; { Индексы спрайтов. } BOULDER_SET = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']; PLACE_SET = ['1', '2', '3', '4', '5', '6', '7', '8', '9']; @@ -115,6 +115,9 @@ begin bitmap := TBitmap.Create; { объект для временного хранения рисунка } Positioned := 0; { считаем, что размещено 0 камней } + Form1.BackBuffer.Canvas.Brush.Color := clBlack; + Form1.BackBuffer.Canvas.Clear; + for j := 1 to 12 do for i := 1 to 20 do begin @@ -206,6 +209,7 @@ procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var dx, dy: Integer; { Смещения Сокобана (куда идем). } SprIdx: Integer; { Текущий номер его спрайта. } + TargetCell: Integer; begin if Busy then Exit; { Если обработчик занят, выходим. } @@ -241,8 +245,9 @@ begin dy := 0; SprIdx := Field[CurX, CurY] end; + TargetCell := PositionBy(dx, dy); - if PositionBy(dx, dy) = SPACE then { если целевая клетка пуста } + if TargetCell = SPACE then { если целевая клетка пуста } begin Field[CurX + dx, CurY + dy] := SprIdx; { переходим в нее } Field[CurX, CurY] := SPACE; { на старой позиции теперь ничего нет } @@ -250,10 +255,10 @@ begin CurY := CurY + dy; end { если целевая клетка содержит камень, а клетка, следующая за ней, пуста } - else if (PositionBy(dx, dy) = BOULDER) and (PositionBy(dx, dy, 2) = SPACE) then + else if (TargetCell > 0) and (TargetCell < SPACE) and (PositionBy(dx, dy, 2) = SPACE) then begin { двигаем камень: } Field[CurX + dx, CurY + dy] := SprIdx; { новая позиция Сокобана } - Field[CurX + 2 * dx, CurY + 2 * dy] := BOULDER; { новая позиция камня } + Field[CurX + 2 * dx, CurY + 2 * dy] := TargetCell; { новая позиция камня } Field[CurX, CurY] := SPACE; { на старой позиции - пусто } CurX := CurX + dx; CurY := CurY + dy; -- cgit v1.2.3