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; |
||||
const |
||||
Implementation |
||||
|
||||
Function turnMover(c: char; d: integer): char; |
||||
|
||||
Const |
||||
period = ord(high(TMoverDir))+1; |
||||
var |
||||
|
||||
Var |
||||
j, x: integer; |
||||
i :TMoverType; |
||||
begin |
||||
for i := low(TMoverType) to high(TMoverType) do |
||||
for j := ord(low(TMoverDir)) to ord(high(TMoverDir)) do |
||||
if c = movers[i, TMoverDir(j)] then |
||||
begin |
||||
x := (j+d) mod period; |
||||
Exit(movers[i, TMoverDir(x)]); |
||||
end; |
||||
i : TMoverType; |
||||
Begin |
||||
For i := low(TMoverType) To high(TMoverType) Do |
||||
For j := ord(low(TMoverDir)) To ord(high(TMoverDir)) Do |
||||
If c = movers[i, TMoverDir(j)] Then |
||||
Begin |
||||
x := (j+d) Mod period; |
||||
Exit(movers[i, TMoverDir(x)]); |
||||
End; |
||||
Exit(c); |
||||
end; |
||||
End; |
||||
|
||||
procedure rotateStep(var rstep, cstep: integer; clockWise: boolean); |
||||
begin |
||||
Procedure rotateStep(Var rstep, cstep: integer; clockWise: boolean); |
||||
Begin |
||||
cstep := cstep + rstep; |
||||
rstep := cstep - rstep; |
||||
cstep := cstep - rstep; |
||||
if clockWise then |
||||
If clockWise Then |
||||
cstep := -cstep |
||||
else |
||||
Else |
||||
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 |
||||
rns : integer = 0; |
||||
cns : integer = 0; |
||||
begin |
||||
Var |
||||
rns : integer = 0; |
||||
cns : integer = 0; |
||||
Begin |
||||
|
||||
(* I don't move if I'm cought by a magnet *) |
||||
If (rstep <> 0) and (g.map[row - rstep, col] = 'Z') then Exit; |
||||
If (cstep <> 0) and (g.map[row, col - cstep] = 'N') then Exit; |
||||
If (rstep <> 0) And (g.map[row - rstep, col] = magnety) Then Exit; |
||||
If (cstep <> 0) And (g.map[row, col - cstep] = magnetx) Then Exit; |
||||
|
||||
(* I don't move beyond the map *) |
||||
if (col + cstep > g.mapWidth) or (col + cstep < 1) or |
||||
(row + rstep > g.mapHeight) or (row + rstep < 1) then |
||||
begin |
||||
if g.map[row,col] in pushers then |
||||
g.map[row, col] := turnMover(g.map[row,col], 2); |
||||
Exit; |
||||
end; |
||||
If (col + cstep > g.mapWidth) Or (col + cstep < 1) Or |
||||
(row + rstep > g.mapHeight) Or (row + rstep < 1) Then |
||||
Begin |
||||
If g.map[row,col] In pushers Then |
||||
g.map[row, col] := turnMover(g.map[row,col], 2); |
||||
Exit; |
||||
End; |
||||
|
||||
(* Turners turn me *) |
||||
case g.map[row + rstep, col + cstep] of |
||||
Case g.map[row + rstep, col + cstep] Of |
||||
'a': |
||||
begin |
||||
g.map[row, col] := turnMover(g.map[row,col], 1); |
||||
rotateStep(rstep, cstep, True); |
||||
end; |
||||
Begin |
||||
g.map[row, col] := turnMover(g.map[row,col], 1); |
||||
rotateStep(rstep, cstep, True); |
||||
End; |
||||
'c': |
||||
begin |
||||
g.map[row, col] := turnMover(g.map[row,col], -1); |
||||
rotateStep(rstep, cstep, False); |
||||
end; |
||||
end; |
||||
Begin |
||||
g.map[row, col] := turnMover(g.map[row,col], -1); |
||||
rotateStep(rstep, cstep, False); |
||||
End; |
||||
End; |
||||
|
||||
(* Simple movement *) |
||||
if g.map[row + rstep, col + cstep] = empty then |
||||
begin |
||||
If g.map[row + rstep, col + cstep] = empty Then |
||||
Begin |
||||
g.map[row + rstep, col + cstep] := g.map[row,col]; |
||||
g.map[row, col] := empty; |
||||
Exit; |
||||
end; |
||||
End; |
||||
|
||||
|
||||
(* Pushers turn around and push pushables *) |
||||
if (g.map[row,col] in pushers) then |
||||
begin |
||||
if (g.map[row + rstep, col + cstep] in pushable) and |
||||
(g.map[row + 2 * rstep, col + 2 * cstep] = empty) then |
||||
begin |
||||
g.map[row + 2 * rstep, col + 2 * cstep] := g.map[row + rstep, col + cstep]; |
||||
g.map[row + rstep, col + cstep] := empty; |
||||
end; |
||||
g.map[row, col] := turnMover(g.map[row,col], 2); |
||||
Exit; |
||||
end; |
||||
If (g.map[row,col] In pushers) Then |
||||
Begin |
||||
If (g.map[row + rstep, col + cstep] In pushable) And |
||||
(g.map[row + 2 * rstep, col + 2 * cstep] = empty) Then |
||||
Begin |
||||
g.map[row + 2 * rstep, col + 2 * cstep] := g.map[row + rstep, col + cstep]; |
||||
g.map[row + rstep, col + cstep] := empty; |
||||
End; |
||||
g.map[row, col] := turnMover(g.map[row,col], 2); |
||||
Exit; |
||||
End; |
||||
|
||||
(* Gliders slip on slipery things*) |
||||
if (g.map[row,col] in gliders) and |
||||
(g.map[row + rstep, col + cstep] in slipery) then |
||||
begin |
||||
if cstep <> 0 then |
||||
rns := 2 * random(1) - 1 |
||||
else |
||||
cns := 2 * random(1) - 1; |
||||
|
||||
if (g.map[row + rns, col + cns] = empty) and |
||||
(g.map[row + rstep + rns, col + cstep + cns] = empty) then |
||||
begin |
||||
g.map[row + rstep + rns, col + cstep + cns] := g.map[row,col]; |
||||
g.map[row, col] := empty; |
||||
end |
||||
else if (g.map[row - rns, col - cns] = empty) and |
||||
(g.map[row + rstep - rns, col + cstep - cns] = empty) then |
||||
begin |
||||
g.map[row + rstep - rns, col + cstep - cns] := g.map[row,col]; |
||||
g.map[row, col] := empty; |
||||
end; |
||||
end; |
||||
end; |
||||
|
||||
procedure moveMovers(var g: GameState); |
||||
|
||||
var |
||||
If (g.map[row,col] In gliders) And |
||||
(g.map[row + rstep, col + cstep] In slipery) Then |
||||
Begin |
||||
If cstep <> 0 Then |
||||
rns := 2 * random(1) - 1 |
||||
Else |
||||
cns := 2 * random(1) - 1; |
||||
|
||||
If (g.map[row + rns, col + cns] = empty) And |
||||
(g.map[row + rstep + rns, col + cstep + cns] = empty) Then |
||||
Begin |
||||
g.map[row + rstep + rns, col + cstep + cns] := g.map[row,col]; |
||||
g.map[row, col] := empty; |
||||
End |
||||
Else If (g.map[row - rns, col - cns] = empty) And |
||||
(g.map[row + rstep - rns, col + cstep - cns] = empty) Then |
||||
Begin |
||||
g.map[row + rstep - rns, col + cstep - cns] := g.map[row,col]; |
||||
g.map[row, col] := empty; |
||||
End; |
||||
End; |
||||
End; |
||||
|
||||
Procedure moveMovers(Var g: GameState); |
||||
|
||||
Var |
||||
idx, row, col, Width, Height: integer; |
||||
begin |
||||
Begin |
||||
Width := g.mapWidth; |
||||
Height := g.mapHeight; |
||||
for idx := 0 to Height * Width - 1 do |
||||
begin |
||||
For idx := 0 To Height * Width - 1 Do |
||||
Begin |
||||
(* for up movers *) |
||||
row := idx div Width + 1; |
||||
col := idx mod Width + 1; |
||||
if (g.map[row, col] in UpMovers) then |
||||
moveMover(g, row, col, -1, 0); |
||||
row := idx Div Width + 1; |
||||
col := idx Mod Width + 1; |
||||
If (g.map[row, col] In UpMovers) Then |
||||
moveMover(g, row, col, -1, 0); |
||||
(* for left movers *) |
||||
col := idx div Height + 1; |
||||
row := idx mod Height + 1; |
||||
if (g.map[row, col] in LeftMovers) then |
||||
moveMover(g, row, col, 0, -1); |
||||
col := idx Div Height + 1; |
||||
row := idx Mod Height + 1; |
||||
If (g.map[row, col] In LeftMovers) Then |
||||
moveMover(g, row, col, 0, -1); |
||||
(* for down movers *) |
||||
row := Height - idx div Width + 1; |
||||
col := Width - idx mod Width + 1; |
||||
if (g.map[row, col] in DownMovers) then |
||||
moveMover(g, row, col, 1, 0); |
||||
row := Height - idx Div Width + 1; |
||||
col := Width - idx Mod Width + 1; |
||||
If (g.map[row, col] In DownMovers) Then |
||||
moveMover(g, row, col, 1, 0); |
||||
(* for Right movers *) |
||||
col := Width - idx div Height + 1; |
||||
row := Height - idx mod Height + 1; |
||||
if (g.map[row, col] in RightMovers) then |
||||
moveMover(g, row, col, 0, 1); |
||||
end; |
||||
end; |
||||
|
||||
end. |
||||
|
||||
col := Width - idx Div Height + 1; |
||||
row := Height - idx Mod Height + 1; |
||||
If (g.map[row, col] In RightMovers) Then |
||||
moveMover(g, row, col, 0, 1); |
||||
End; |
||||
End; |
||||
|
||||
End. |
||||
|
Loading…
Reference in new issue