Compare commits
2 Commits
5f2ecbabdf
...
d0e5be4cd2
Author | SHA1 | Date |
---|---|---|
mian | d0e5be4cd2 | 2 years ago |
mian | fbcee326b2 | 2 years ago |
5 changed files with 201 additions and 188 deletions
@ -1,151 +1,154 @@ |
|||||||
unit moversProc; |
|
||||||
|
|
||||||
interface |
Unit moversProc; |
||||||
|
|
||||||
uses dataUnit; |
Interface |
||||||
|
|
||||||
procedure moveMovers(var g: GameState); |
Uses dataUnit; |
||||||
|
|
||||||
implementation |
Procedure moveMovers(Var g: GameState); |
||||||
|
|
||||||
function turnMover(c: char; d: integer): char; |
Implementation |
||||||
const |
|
||||||
|
Function turnMover(c: char; d: integer): char; |
||||||
|
|
||||||
|
Const |
||||||
period = ord(high(TMoverDir))+1; |
period = ord(high(TMoverDir))+1; |
||||||
var |
|
||||||
|
Var |
||||||
j, x: integer; |
j, x: integer; |
||||||
i :TMoverType; |
i : TMoverType; |
||||||
begin |
Begin |
||||||
for i := low(TMoverType) to high(TMoverType) do |
For i := low(TMoverType) To high(TMoverType) Do |
||||||
for j := ord(low(TMoverDir)) to ord(high(TMoverDir)) do |
For j := ord(low(TMoverDir)) To ord(high(TMoverDir)) Do |
||||||
if c = movers[i, TMoverDir(j)] then |
If c = movers[i, TMoverDir(j)] Then |
||||||
begin |
Begin |
||||||
x := (j+d) mod period; |
x := (j+d) Mod period; |
||||||
Exit(movers[i, TMoverDir(x)]); |
Exit(movers[i, TMoverDir(x)]); |
||||||
end; |
End; |
||||||
Exit(c); |
Exit(c); |
||||||
end; |
End; |
||||||
|
|
||||||
procedure rotateStep(var rstep, cstep: integer; clockWise: boolean); |
Procedure rotateStep(Var rstep, cstep: integer; clockWise: boolean); |
||||||
begin |
Begin |
||||||
cstep := cstep + rstep; |
cstep := cstep + rstep; |
||||||
rstep := cstep - rstep; |
rstep := cstep - rstep; |
||||||
cstep := cstep - rstep; |
cstep := cstep - rstep; |
||||||
if clockWise then |
If clockWise Then |
||||||
cstep := -cstep |
cstep := -cstep |
||||||
else |
Else |
||||||
rstep := -rstep; |
rstep := -rstep; |
||||||
end; |
End; |
||||||
|
|
||||||
|
Procedure moveMover(Var g: GameState; row, col, rstep, cstep: integer); |
||||||
|
|
||||||
procedure moveMover(var g: GameState; row, col, rstep, cstep: integer); |
Var |
||||||
var |
rns : integer = 0; |
||||||
rns : integer = 0; |
cns : integer = 0; |
||||||
cns : integer = 0; |
Begin |
||||||
begin |
|
||||||
|
|
||||||
(* I don't move if I'm cought by a magnet *) |
(* I don't move if I'm cought by a magnet *) |
||||||
If (rstep <> 0) and (g.map[row - rstep, col] = 'Z') then Exit; |
If (rstep <> 0) And (g.map[row - rstep, col] = magnety) Then Exit; |
||||||
If (cstep <> 0) and (g.map[row, col - cstep] = 'N') then Exit; |
If (cstep <> 0) And (g.map[row, col - cstep] = magnetx) Then Exit; |
||||||
|
|
||||||
(* I don't move beyond the map *) |
(* I don't move beyond the map *) |
||||||
if (col + cstep > g.mapWidth) or (col + cstep < 1) or |
If (col + cstep > g.mapWidth) Or (col + cstep < 1) Or |
||||||
(row + rstep > g.mapHeight) or (row + rstep < 1) then |
(row + rstep > g.mapHeight) Or (row + rstep < 1) Then |
||||||
begin |
Begin |
||||||
if g.map[row,col] in pushers then |
If g.map[row,col] In pushers Then |
||||||
g.map[row, col] := turnMover(g.map[row,col], 2); |
g.map[row, col] := turnMover(g.map[row,col], 2); |
||||||
Exit; |
Exit; |
||||||
end; |
End; |
||||||
|
|
||||||
(* Turners turn me *) |
(* Turners turn me *) |
||||||
case g.map[row + rstep, col + cstep] of |
Case g.map[row + rstep, col + cstep] Of |
||||||
'a': |
'a': |
||||||
begin |
Begin |
||||||
g.map[row, col] := turnMover(g.map[row,col], 1); |
g.map[row, col] := turnMover(g.map[row,col], 1); |
||||||
rotateStep(rstep, cstep, True); |
rotateStep(rstep, cstep, True); |
||||||
end; |
End; |
||||||
'c': |
'c': |
||||||
begin |
Begin |
||||||
g.map[row, col] := turnMover(g.map[row,col], -1); |
g.map[row, col] := turnMover(g.map[row,col], -1); |
||||||
rotateStep(rstep, cstep, False); |
rotateStep(rstep, cstep, False); |
||||||
end; |
End; |
||||||
end; |
End; |
||||||
|
|
||||||
(* Simple movement *) |
(* Simple movement *) |
||||||
if g.map[row + rstep, col + cstep] = empty then |
If g.map[row + rstep, col + cstep] = empty Then |
||||||
begin |
Begin |
||||||
g.map[row + rstep, col + cstep] := g.map[row,col]; |
g.map[row + rstep, col + cstep] := g.map[row,col]; |
||||||
g.map[row, col] := empty; |
g.map[row, col] := empty; |
||||||
Exit; |
Exit; |
||||||
end; |
End; |
||||||
|
|
||||||
|
|
||||||
(* Pushers turn around and push pushables *) |
(* Pushers turn around and push pushables *) |
||||||
if (g.map[row,col] in pushers) then |
If (g.map[row,col] In pushers) Then |
||||||
begin |
Begin |
||||||
if (g.map[row + rstep, col + cstep] in pushable) and |
If (g.map[row + rstep, col + cstep] In pushable) And |
||||||
(g.map[row + 2 * rstep, col + 2 * cstep] = empty) then |
(g.map[row + 2 * rstep, col + 2 * cstep] = empty) Then |
||||||
begin |
Begin |
||||||
g.map[row + 2 * rstep, col + 2 * cstep] := g.map[row + rstep, col + cstep]; |
g.map[row + 2 * rstep, col + 2 * cstep] := g.map[row + rstep, col + cstep]; |
||||||
g.map[row + rstep, col + cstep] := empty; |
g.map[row + rstep, col + cstep] := empty; |
||||||
end; |
End; |
||||||
g.map[row, col] := turnMover(g.map[row,col], 2); |
g.map[row, col] := turnMover(g.map[row,col], 2); |
||||||
Exit; |
Exit; |
||||||
end; |
End; |
||||||
|
|
||||||
(* Gliders slip on slipery things*) |
(* Gliders slip on slipery things*) |
||||||
if (g.map[row,col] in gliders) and |
If (g.map[row,col] In gliders) And |
||||||
(g.map[row + rstep, col + cstep] in slipery) then |
(g.map[row + rstep, col + cstep] In slipery) Then |
||||||
begin |
Begin |
||||||
if cstep <> 0 then |
If cstep <> 0 Then |
||||||
rns := 2 * random(1) - 1 |
rns := 2 * random(1) - 1 |
||||||
else |
Else |
||||||
cns := 2 * random(1) - 1; |
cns := 2 * random(1) - 1; |
||||||
|
|
||||||
if (g.map[row + rns, col + cns] = empty) and |
If (g.map[row + rns, col + cns] = empty) And |
||||||
(g.map[row + rstep + rns, col + cstep + cns] = empty) then |
(g.map[row + rstep + rns, col + cstep + cns] = empty) Then |
||||||
begin |
Begin |
||||||
g.map[row + rstep + rns, col + cstep + cns] := g.map[row,col]; |
g.map[row + rstep + rns, col + cstep + cns] := g.map[row,col]; |
||||||
g.map[row, col] := empty; |
g.map[row, col] := empty; |
||||||
end |
End |
||||||
else if (g.map[row - rns, col - cns] = empty) and |
Else If (g.map[row - rns, col - cns] = empty) And |
||||||
(g.map[row + rstep - rns, col + cstep - cns] = empty) then |
(g.map[row + rstep - rns, col + cstep - cns] = empty) Then |
||||||
begin |
Begin |
||||||
g.map[row + rstep - rns, col + cstep - cns] := g.map[row,col]; |
g.map[row + rstep - rns, col + cstep - cns] := g.map[row,col]; |
||||||
g.map[row, col] := empty; |
g.map[row, col] := empty; |
||||||
end; |
End; |
||||||
end; |
End; |
||||||
end; |
End; |
||||||
|
|
||||||
procedure moveMovers(var g: GameState); |
Procedure moveMovers(Var g: GameState); |
||||||
|
|
||||||
var |
Var |
||||||
idx, row, col, Width, Height: integer; |
idx, row, col, Width, Height: integer; |
||||||
begin |
Begin |
||||||
Width := g.mapWidth; |
Width := g.mapWidth; |
||||||
Height := g.mapHeight; |
Height := g.mapHeight; |
||||||
for idx := 0 to Height * Width - 1 do |
For idx := 0 To Height * Width - 1 Do |
||||||
begin |
Begin |
||||||
(* for up movers *) |
(* for up movers *) |
||||||
row := idx div Width + 1; |
row := idx Div Width + 1; |
||||||
col := idx mod Width + 1; |
col := idx Mod Width + 1; |
||||||
if (g.map[row, col] in UpMovers) then |
If (g.map[row, col] In UpMovers) Then |
||||||
moveMover(g, row, col, -1, 0); |
moveMover(g, row, col, -1, 0); |
||||||
(* for left movers *) |
(* for left movers *) |
||||||
col := idx div Height + 1; |
col := idx Div Height + 1; |
||||||
row := idx mod Height + 1; |
row := idx Mod Height + 1; |
||||||
if (g.map[row, col] in LeftMovers) then |
If (g.map[row, col] In LeftMovers) Then |
||||||
moveMover(g, row, col, 0, -1); |
moveMover(g, row, col, 0, -1); |
||||||
(* for down movers *) |
(* for down movers *) |
||||||
row := Height - idx div Width + 1; |
row := Height - idx Div Width + 1; |
||||||
col := Width - idx mod Width + 1; |
col := Width - idx Mod Width + 1; |
||||||
if (g.map[row, col] in DownMovers) then |
If (g.map[row, col] In DownMovers) Then |
||||||
moveMover(g, row, col, 1, 0); |
moveMover(g, row, col, 1, 0); |
||||||
(* for Right movers *) |
(* for Right movers *) |
||||||
col := Width - idx div Height + 1; |
col := Width - idx Div Height + 1; |
||||||
row := Height - idx mod Height + 1; |
row := Height - idx Mod Height + 1; |
||||||
if (g.map[row, col] in RightMovers) then |
If (g.map[row, col] In RightMovers) Then |
||||||
moveMover(g, row, col, 0, 1); |
moveMover(g, row, col, 0, 1); |
||||||
end; |
End; |
||||||
end; |
End; |
||||||
|
|
||||||
end. |
End. |
||||||
|
|
||||||
|
Loading…
Reference in new issue