CLI-based maze-game: Difference between revisions
Content deleted Content added
m →{{header|Wren}}: Minor tidy |
|||
(10 intermediate revisions by 6 users not shown) | |||
Line 1:
{{draft task}}
;Task:
Create a complete but CLI-controlled maze-game!
Use the CLI interface only. The symbols:
Line 30 ⟶ 31:
Note: I apologize of my bad English, I'm very sorry...
<br><br>
=={{header|Furor}}==
<syntaxhighlight lang="furor">
###sysinclude terminal.uh
###sysinclude into.uh
Line 655 ⟶ 656:
}
// ---------------------------------------------------------
</syntaxhighlight>
{{out}}
<pre>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X | X X X X . X X X X X X X
X XXXXX XXX X X XXXXX o XXX X X XXX X XXXXX XbXXX X X X-o-X XXXXXXX*X
X X X . X X X X X | X X X X | X X X X X X X X X * X
X X XXX XXX X X X X X X XXX X X X X o | XXX X XXX X*X XXX X X XXXXX X
X X X X X X X X | X | o X . X X X X X
X X XXXXX XXX XXXXXXXXXXX XXX o XXXXX | XXXXXXXXXXX X X XXXXXXXXXXXXX
X X X X X * X X X | X X X X X X X X X
X X XXXXX XXX X X XXXXX X XXX X X XXX X XXXXX X XXX X X XXXXX -o-XXXX
X X @ X X * X X X X X $ X
X XX-o-XXXXXX XXXXXXXXXXX XXX XXXXXXX X-o-XXXXXXXXXXXXXXXXXXXXXXXXXXX
X X X X X X X X X X X X X X X X
X XXXXX XXX X X XXXXX$X XXX X X XXX | XXXXX X XXXbX X*XXXXX X-o-XXX
X-o- X X X X . X X X X X X o X X . X X X X X
X XXXXX XXX X X XXXXX X XXX X X X X | XXXXX X XXX X X XXXXX XX-o-XX
X X X X* X X bX X X X X
X XXXXXXXXXXX XXXXXXXXXXX XXX XXXXXXX XXX-o-XXXXXXXXXXXXXXXXXXXXXXXXX
X X X X . X X X X X X X X X X X X X X X X
X X.X XXX XXX X X X X X X XXX X X X X X X XXX X XXX X X XXX X XXXXXXX
X X X X X X X .X X X X X
X XXX-o-XXXXXXXXXXXXXXXXX XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XX
X X X X X X X X X X X X X X X X X X * X
X X XXX XXX X X X X X X XXX X X X X X X X X X XXX X X XXX X X XXXXX X
X | X X * X X X X X X X X X X X X X X
X o -o-XX XXX XXXXXXXXXXX XXX X XXXXX X XXXXXXXXXXX X X XXXXXXXXXXXXX
X | X X X X X X
XXXXXXXXXXX XXX-o-XXXXX XXX XXXXXXX XXXXXXX-o-XXXXXXXXXXXXXXXXXXXXX X
X X X X X X X X X X X X X X X XbX X X
X X XXX XXX X X XXX X X XXX X X X X X X XXX X XXX X X XXXXX X-o-XXX X
X X X X X X X *b * * X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Collected treasure = 1 Bombs = 3
</pre>
=={{header|Julia}}==
{{trans|Nim}}
<syntaxhighlight lang="julia">using Ansillary
using Crayons
using Random
const Mx = 69 # No of columns (1..Mx), must be odd.
const My = 31 # No of rows (1..My), must be odd.
const Treasure = '$'
const TreasureDb = 3 # How many $ signs will be placed.
const Way = ' '
const Wall = 'X'
const Doors = 20 # No of doors.
const DoorCenter = 'o'
const DoorWingVertical = '|'
const DoorWingHorizontal = '-'
const Hero = '@'
const DeadHero = '+'
const NumberOfBombs = 5
const Bomb = 'b'
const NumberOfMonsters = 20
const Monster = '*'
const WeakMonster = '.'
const MonsterWeaknessProbability = 25
# The higher the above number, the lower the chance that a strong monster will become weak.
const MonsterIntensifiesProbability = 5
# The higher the number above, the lower the chance that a weak monster will get stronger.
const HelpText = """
Maze game.
The object of the game is to get all the treasures. The symbol of the treasure is the \$ sign.
Help (display this text): press ? or h
Exit: press Esc or q
You can detonate a bomb by pressing b, but only as long as your bomb remains.
A bomb destroys every wall around the player (the outermost, framing of the maze
except for its walls), but it won't kill monsters.
The bomb does not destroy diagonally, only vertically and horizontally.
The bomb will not destroy the doors or the treasure.
You can also find bombs in the maze, represented by the letter b. If you step on them,
you get the bomb with it, so that the number of your bombs increases for later use.
The game ends when you have acquired all the treasures.
The maze has not only walls but also revolving doors.
The revolving door, if horizontal, looks like this: -o-
If vertical, like this:
|
o
|
The center of the revolving door is represented by the character o, the wings by the line.
The revolving door can be rotated if you move into a door wing in the right direction with
your character, as long as nothing stands in the way of door rotation.
The player is represented by @ in the game, and his starting point is always in the lower left corner.
There is a possibility of a little cheating in the game: each press of the letter c increases the
number of remaining bombs by one.
(This help screen closes after 10 seconds.)
"""
const Position = NamedTuple{(:x, :y)}
mutable struct Game
grid::Matrix{Char}
scoords::Vector{Position}
showhelp::Bool
terminate::Bool
counterschanged::Bool
treasurecounter::Int
bombs::Int
x::Int
y::Int
end
const NoPosition = Position((0, 0))
const Dy = [-1, 1, 0, 0]
const Dx = [0, 0, -1, 1]
@enum Direction Left Right Up Down
const gamelock = ReentrantLock()
""" Game constructor for game initialization """
function Game()
grid = fill(Way, My, Mx)
grid[[begin, end], begin:end] .= Wall
grid[begin+1:end-1, [begin, end]] .= Wall
colflags = [isodd(n) for n in 1:Mx]
rowflags = [isodd(n) for n in 1:My]
while any(colflags) || any(rowflags)
direction = rand([Left, Right, Up, Down])
j = rand(1:(direction in [Left, Right] ? My : Mx)) ÷ 2 * 2 + 1 # if even, add one
if direction == Left && rowflags[j]
for r in 1:Mx-1
if grid[j, r] != Wall && grid[j, r+1] != Wall
grid[j, r] = Wall
end
end
rowflags[j] = false
elseif direction == Right && rowflags[j]
for r in Mx:-1:3
if grid[j, r-1] != Wall && grid[j, r-2] != Wall
grid[j, r-1] = Wall
end
end
rowflags[j] = false
elseif direction == Up && colflags[j]
for c in My:-1:3
if grid[c-1, j] != Wall && grid[c-2, j] != Wall
grid[c-1, j] = Wall
end
end
colflags[j] = false
elseif direction == Down && colflags[j]
for c in 1:My-1
if grid[c, j] != Wall && grid[c+1, j] != Wall
grid[c, j] = Wall
end
end
colflags[j] = false
end
end
doorsplaced = 0
while doorsplaced < Doors
x = rand(3:Mx-2)
y = rand(3:My-2)
if grid[y, x] != Way && grid[y-1, x-1] == Way && grid[y-1, x+1] == Way &&
grid[y+1, x-1] == Way && grid[y+1, x+1] == Way # corners free?
if grid[y-1, x] == Wall && grid[y-2, x] == Wall && grid[y+1, x] == Wall &&
grid[y+2, x] == Wall && grid[y, x-1] == Way && grid[y, x+1] == Way
grid[y, x] = DoorCenter
grid[y-1, x] = DoorWingVertical
grid[y+1, x] = DoorWingVertical
doorsplaced += 1
elseif grid[y, x-1] == Wall && grid[y, x-2] == Wall && grid[y, x+1] == Wall &&
grid[y, x+2] == Wall && grid[y+1, x] == Way && grid[y-1, x] == Way
grid[y, x] = DoorCenter
grid[y, x-1] = DoorWingHorizontal
grid[y, x+1] = DoorWingHorizontal
doorsplaced += 1
end
end
end
# note all monsters start as weak (weak ones count == NumberofMonsters)
scoords = Position[]
stuff = [(TreasureDb, Treasure), (NumberOfBombs, Bomb),(NumberOfMonsters, WeakMonster)]
for (n, what) in stuff
iterations = 1
cnt = n
while cnt > 0
x = rand(1:Mx)
y = rand(1:My)
if grid[y, x] == Way
grid[y, x] = what
cnt -= 1
what == WeakMonster && push!(scoords, Position((x, y)))
end
iterations += 1
@assert iterations <= 10_000 # (sanity check)
end
end
grid[end-1, begin+1] = Hero
return Game(grid, scoords, false, false, true, 0, 3, 2, My - 1)
end
function draw!(game)
while true
lock(gamelock)
if game.showhelp
Screen.clear!(Screen.All())
Cursor.move!(Cursor.Coordinate(1, 1))
print(HelpText)
sleep(10)
Screen.clear!(Screen.All())
game.showhelp = false
game.counterschanged = true
end
Cursor.move!(Cursor.Coordinate(1, 1))
for row in eachrow(game.grid)
s = join(row) # colorize
s = replace(s, Treasure => "$(crayon"light_green")$Treasure$(crayon"white")")
s = replace(s, Monster => "$(crayon"light_red")$Monster$(crayon"white")")
s = replace(s, Hero => "$(crayon"light_yellow")$Hero$(crayon"white")")
s = replace(s, Bomb => "$(crayon"light_blue")$Bomb$(crayon"white")")
println(s)
end
if game.counterschanged
print("\n\nCollected treasures = $(game.treasurecounter) Bombs = $(game.bombs)\n")
game.counterschanged = false
end
unlock(gamelock)
game.terminate && break
sleep(0.05)
end
end
function monsterstepfinder(game, sx, sy)
result = NoPosition
for i in shuffle(1:4)
nx = sx + Dx[i]
ny = sy + Dy[i]
if ny in 1:My && nx in 1:Mx && game.grid[ny, nx] in [Way, Hero]
result = Position((nx, ny))
end
end
return result
end
function monstermove!(game)
cnt = 0
while true
active = rand(1:NumberOfMonsters)
pos = game.scoords[active]
sx, sy = pos.x, pos.y
if sy in 1:My && sx in 1:Mx
ch = game.grid[sy, sx]
if ch == Monster
if rand(1:MonsterWeaknessProbability) == 1
game.grid[sy, sx] = WeakMonster
else
monster = monsterstepfinder(game, sx, sy)
if monster != NoPosition && monster.y in 1:My && monster.x in 1:Mx
if game.grid[monster.y, monster.x] == Hero
game.grid[monster.y, monster.x] = DeadHero
game.terminate = true
break
end
end
game.grid[sy, sx] = Way
if monster.y in 1:My && monster.x in 1:Mx
game.grid[monster.y, monster.x] = Monster
game.scoords[active] = monster
end
end
elseif ch == WeakMonster
if rand(1:MonsterIntensifiesProbability) == 1
game.grid[sy, sx] = Monster
else
monster = monsterstepfinder(game, sx, sy)
if monster != NoPosition && monster.y in 1:My && monster.x in 1:Mx
if game.grid[monster.y, monster.x] != Hero
game.grid[monster.y, monster.x] = WeakMonster
game.scoords[active] = monster
else
game.scoords[active] = NoPosition
end
end
end
end
end
sleep(0.2)
end
end
function rotatedoor!(game, nx, ny)
for i in 1:4
wy = Dy[i]
wx = Dx[i]
cy = ny + wy
cx = nx + wx
if game.grid[cy, cx] == DoorCenter
if game.grid[cy-1, cx-1] == Way &&
game.grid[cy-1, cx+1] == Way &&
game.grid[cy+1, cx-1] == Way &&
game.grid[cy+1, cx+1] == Way # four corners empty
py = Dy[end-i+1]
px = Dx[end-i+1]
if game.grid[cy+py, cx+px] == Way &&
game.grid[cy-py, cx-px] == Way # swung door empty
door = game.grid[ny, nx]
flip = door == DoorWingVertical ? DoorWingHorizontal : DoorWingVertical
game.grid[cy+py, cx+px] = flip
game.grid[cy-py, cx-px] = flip
game.grid[cy+wy, cx+wx] = Way
game.grid[cy-wy, cx-wx] = Way
end
end
break
end
end
end
function keyboard!(game)
cnt = 0
Screen.raw() do
for event in Inputs.Events()
key = lowercase(string(event))
sleep(0.01)
if key in ["esc", "q"]
game.terminate = true
break
elseif key == "b"
if game.bombs > 0
lock(gamelock)
game.bombs -= 1
game.counterschanged = true
for i in 1:4
nx = game.x + Dx[i]
ny = game.y + Dy[i]
if ny in 2:My-1 && nx in 2:Mx-1 && game.grid[ny, nx] == Wall
game.grid[ny, nx] = Way
end
end
unlock(gamelock)
end
elseif key == "c"
game.bombs += 1
game.counterschanged = true
elseif key in ["?", "h"]
game.showhelp = true
else
chindex = findfirst(==(key), ["up", "down", "left", "right"])
if chindex != nothing
nx = game.x + Dx[chindex]
ny = game.y + Dy[chindex]
if ny in 2:My-1 && nx in 2:Mx-1
ch = game.grid[ny, nx]
if ch in [DoorWingVertical, DoorWingHorizontal]
lock(gamelock)
game.grid[game.y, game.x] = Way # (temp. "ghost" him)
rotatedoor!(game, nx, ny)
game.grid[game.y, game.x] = Hero
unlock(gamelock)
ch = game.grid[ny, nx] # (maybe unaltered)
elseif ch == Monster
lock(gamelock)
game.grid[game.y, game.x] = Way
game.grid[ny, nx] = DeadHero
game.y = ny
game.x = nx
game.terminate = true
unlock(gamelock)
break
elseif ch == Treasure
game.treasurecounter += 1
game.counterschanged = true
ch = Way
if game.treasurecounter == TreasureDb
lock(gamelock)
game.grid[game.y, game.x] = Way
game.grid[ny, nx] = Hero
game.y = ny
game.x = nx
game.terminate = true
unlock(gamelock)
break
end
elseif ch == Bomb
game.bombs += 1
game.counterschanged = true
ch = Way
end
if ch in [Way, WeakMonster]
lock(gamelock)
game.grid[game.y, game.x] = Way
game.grid[ny, nx] = Hero
game.y = ny
game.x = nx
unlock(gamelock)
end
end
end
end
sleep(0.01)
end
end
end
function play()
print(Crayon(background=(0,0,0), foreground=(250,250,250))) # white on black
Screen.clear!(Screen.All())
game = Game()
@async draw!(game)
@async keyboard!(game)
@async monstermove!(game)
while !game.terminate
sleep(1)
end
if game.treasurecounter == TreasureDb
print("\nYOU WON! Congratulations!\n")
elseif game.grid[game.y, game.x] == DeadHero
print("\nYOU PERISHED!\n")
end
end
play()
</syntaxhighlight>{{out}}
<pre>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X . X X X . X X X . X X X .X
X XXX XXX XXX.XXXXXXX XXXXXXX X.XXXXX X X XXX XXXXX X X XXX XXX X XXX
X X X X X X X X X X X | X X X X X X
XXX XXX XXX XXXXXXX XXX X X X XXX X X X XXX XXXXX o X XXX XXX X XXX X
X X X b X X. X X X | X $ X X
X XXX XXX-o-XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXX-o-XXXXXXX
X X ..X X.X X.X X X X X X
XXX XXX XXX.XXXXXXXXXXXXXXX X XXXXXbX X XXX XXXXX XXX XXX XXX.X XXX X
X X X X X X . X X
XXXXXXXXXXXXXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXXXXXXXXXXXXXXXX X
X X . X X X X X X .X X b X X
X XXX XXX XXX XXXXXXX XXXXXXX X XXXXX X X XXX XXXXX.X X XXX XXX X XXX
X X X X X X X X X X X X X X X X X X
XXX XXX XXX XXXXXXX.XXX-o-X X XXXXX X X XXX XXXXX.X X XXX XXX X XXX X
X X . X X X X X X
X XXXXXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X $ X
X XXX XXXXXXXXXXX-o-XXXXXXXXXXX XXXXXXXXXX-o-XXXX-o-X-o-XXXXXXXXXXXXX
X b X $ .. X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXX-o-XXXXXX X
Xb X . X
XXX XXXXXXXXXXXXXXXXXXXXX-o-X.XXXXX-o-XXXXX-o-XXX XXXXXXXXX-o-XXXXX X
X X .. X . X
X XXXXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXXXXXXXX
X X
XXXXXXXXXXXXXXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X
X X X X X X X X X X X X X X X X X X X
X X X X X X X XXX X X X X X X X X X X X X X X X X X X X XXX X*X X XXX
X@X X X X X X X X X X X X X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Collected treasures = 0 Bombs = 3
</pre>
=={{header|Peri}}==
<syntaxhighlight lang="Peri">
###sysinclude standard.uh
###sysinclude system.uh
###sysinclude into.uh
###sysinclude math.uh
###sysinclude args.uh
###sysinclude str.uh
###sysinclude io.uh
###define VÁRAKOZIK 40000
// Minél nagyobb a fenti szám, annál lassabban mozognak a szörnyek.
###define MERETX 69
// A labirintus oszlopainak számozása 0 és MERETX-1 közt történik.
// MERETX muszáj hogy páratlan szám legyen.
###define MERETY 31
// A labirintus sorainak számozása 0 és MERETY-1 közt történik.
// MERETY muszáj hogy páratlan szám legyen.
###define TREASURE '$
###define TREASUREDB 3
// A treasuredb jelenti, hány $ jel lesz elhelyezve
###define WAY 32
###define FAL 'X
###define wayszín 0
###define wayháttérszín 0
// Az alábbi doors az ajtók számát jelzi a labirintus falaiban.
###define doors 20
###define AJTÓKÖZEPE 'o
###define AJTÓSZÁRNYFÜGGŐLEGES '|
###define AJTÓSZÁRNYVÍZSZINTES '-
###define AJTÓszín $e
###define AJTÓhszin 0
###define FALszín $1b
###define FALháttérszín FALszín
###define HŐS '@
###define HALOTTHŐS '+
###define HŐSszín 9
###define HŐSháttérszín 0
###define kincsszín $b
###define kincsháttérszín 0
// Ennyi bombát lehet találni a labirintusban:
###define bombákszáma 5
###define bomba 'b
###define bombaszín $a6
###define bombahszin 0
###define szörnyekszáma 20
###define szörny '*
###define szörnyszín $d
###define szörnyhszin 0
###define gyengeszörny '.
###define gyengeszörnyszín $cd
###define gyengeszörnyhszin 0
###define szörnygyengülvalószínűség 25
// A fenti szám minél magasabb, annál kisebb az esélye hogy egy erős szörny gyengévé válik.
###define szörnyerősödikvalószínűség 5
// A fenti szám minél magasabb, annál kisebb az esélye annak, hogy egy gyenge szörny megerősödik.
#g argc 2 > {
."Labirintusjáték. Készítette: Viola Zoltán alias Harold King alias Fossil Codger.\n"
."(fossilcodger@gmail.com)\n"
."A program a Peri programnyelven íródott, azt a programnyelvet is én, Viola Zoltán írtam.\n"
."A játék célja: az összes kincs megszerzése. A kincs jelképe a $ jel.\n"
."Kilépés: az Esc 2-szer lenyomva, vagy a q.\n"
."A b lenyomásával robbanthatsz, de csak amíg maradt bombád.\n"
."Egy bomba minden falat lerombol a játékos körül (a labirintus legszélső, keretező"
." falait kivéve), de a szörnyeket nem öli meg.\n"
."A bomba átlósan se rombol, csak függőlegesen és vízszintesen!\n"
."A bomba nem pusztítja el az ajtókat, és a kincset se.\n"
."Bombákat találhatsz is a labirintusban, ezeket a b betű jelképezi. Ha rájuk lépsz,\n"
."azzal megszerezted a bombát, azaz a bombáid száma növekszik, később ezeket\n"
."felhasználhatod.\n"
."A játék akkor ér véget, ha az összes kincset megszerezted.\n"
."A labirintusban nem csak falak, de forgóajtók is vannak.\n"
."A forgóajtó ha vízszintes, így néz ki: -o-\n"
."Ha meg függőleges akkor így:\n"
."|\n"
."o\n"
."|\n"
."A forgóajtó közepét az o karakter, a szárnyait a vonal jelképezi.\n"
."A forgóajtó elfordítható, ha a szárnyának a megfelelő irányból nekimész a karaktereddel,\n"
."és ha semmi se áll az elforgatás útjában.\n"
."A játékost a @ jelképezi a játékban, s kiindulási helye mindig a bal alsó sarokban van.\n"
."Van a játékban kis csalásra is lehetőség: a B (nagy bé betű) minden lenyomása eggyel\n"
."megnöveli a bombáid mennyiségét.\n"
end
}
3 sto bombs // A bombák száma.
randinit // A véletlenszámgenerátor inicializálása
MERETY MERETX [[mem...]]! sto pálya
100 shared sto messagestring // kommunikációs terület a forkolt programrészeknek
szörnyekszáma shared sto sxkoord
szörnyekszáma shared sto sykoord
// ---------------------------------------------
// Elkészítjük az üres területet, falakkal körülhatárolva.
// Kitölti úttal az egész pályát, de a széleit falakkal.
MERETY yciklus: {{ MERETX {{
{{}}§yciklus {{}} WAY inv [[pálya]][]
}} }}
MERETY {{ {{}} 0 FAL inv [[pálya]][] {{}} MERETX -- FAL inv [[pálya]][] }}
MERETX {{ 0 {{}} FAL inv [[pálya]][] MERETY -- {{}} FAL inv [[pálya]][] }}
// ---------------------------------------------
// Ez legenerálja véletlenszerűen a labirintust
#g // Végig egész számokkal dolgozunk
// Az alábbi 2 sorban memóriát foglalunk 2 stringnek, amik
// segédváltozókként funkcionálnak majd, flagek tárolását végzik:
MERETX mem !maximize sto oszlopflag
MERETY mem !maximize sto sorflag
// ***********************************************************
// Az oszlopok és sorok első és utolsó pozícióit bejelöljük,
// mondván hogy ott már van fal.
//
@oszlopflag 0 1 inv []
@oszlopflag oszlopflag~ -- 1 inv []
@sorflag 0 1 inv []
@sorflag sorflag~ -- 1 inv []
// ***********************************************************
// Az alábbi 2 ciklusban az oszlopok és sorok flagjait tároló
// stringek minden páratlanadik pozícióját bejelöljük, ez jelzi
// később, hogy azokkal a sorokkal illetve oszlopokkal nem kell
// törődnie. Fal ugyanis csak páros indexű helyeken építhető.
//
MERETX -- {{ {{}} 2 !/ { {{<}} } @oszlopflag {{+}} 1 inv [] }}
MERETY -- {{ {{}} 2 !/ { {{<}} } @sorflag {{+}} 1 inv [] }}
// ***********************************************************
nextrandom:
// ...............................................
// E két ciklus csekkolja le, van-e még olyan
// sor illetve oszlop, amit nem vizsgáltunk végig.
oszlopflag {~ {~?~} else §kell ~}
sorflag {~ {~?~} else §kell ~}
// ...............................................
// Elhelyezzük a forgóajtókat:
doors {{
newrandomneed:
MERETX random sto xx
MERETY random sto yy @yy @xx [[pálya]][] WAY == then §newrandomneed
// Most már biztos hogy itt fal van.
@xx 2 < then §newrandomneed @yy 2 < then §newrandomneed
@xx MERETX 3 - > then §newrandomneed @yy MERETY 3 - > then §newrandomneed
// Megnézzük, függőleges ajtót betehetünk-e.
@yy -- @xx [[pálya]][] FAL == // Ha az aktuális pozíció fölött is fal van
@yy ++ @xx [[pálya]][] FAL == // Ha az aktuális pozíció alatt is fal van
@yy -- @xx -- [[pálya]][] WAY == // balfelső sarok szabad
@yy -- @xx ++ [[pálya]][] WAY == // jobbfelső sarok szabad
@yy ++ @xx -- [[pálya]][] WAY == // balalsó sarok szabad
@yy ++ @xx ++ [[pálya]][] WAY == // jobbalsó sarok szabad
@yy @xx -- [[pálya]][] WAY == // bal szomszéd szabad
@yy @xx ++ [[pálya]][] WAY == // jobb szomszéd szabad
& & & & & & & else §vízszintesteszt
@yy @xx AJTÓKÖZEPE inv [[pálya]][]
@yy -- @xx AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
@yy ++ @xx AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
{{<}}
vízszintesteszt:
// Megnézzük, vízszintes ajtót betehetünk-e.
@yy @xx -- [[pálya]][] FAL == // Ha az aktuális pozíció mellett balra is fal van
@yy @xx ++ [[pálya]][] FAL == // Ha az aktuális pozíció mellett jobbra is fal van
@yy -- @xx -- [[pálya]][] WAY == // balfelső sarok szabad
@yy -- @xx ++ [[pálya]][] WAY == // jobbfelső sarok szabad
@yy ++ @xx -- [[pálya]][] WAY == // balalsó sarok szabad
@yy ++ @xx ++ [[pálya]][] WAY == // jobbalsó sarok szabad
@yy ++ @xx [[pálya]][] WAY == // fent szabad
@yy -- @xx [[pálya]][] WAY == // lent szabad
& & & & & & & else §newrandomneed
@yy @xx AJTÓKÖZEPE inv [[pálya]][]
@yy @xx -- AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
@yy @xx ++ AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
}}
// Elhelyezzük a kincseket.
TREASUREDB {{ sbr §newrandomnumber @yy @xx TREASURE inv [[pálya]][] }}
// Elhelyezzük a bombákat.
bombákszáma {{ sbr §newrandomnumber @yy @xx bomba inv [[pálya]][] }}
// Elhelyezzük a szörnyeket. Kezdetben mind gyengék.
szörnyekszáma {{ sbr §newrandomnumber @yy @xx gyengeszörny inv [[pálya]][]
@sxkoord {{}} @xx inv [] @sykoord {{}} @yy inv []
}}
// ...............................................
@oszlopflag inv mem @sorflag inv mem // Az ideiglenes változók
// memóriaterületének felszabadítása
goto §indulajáték
kell:
4 random // Választunk egy irányt véletlenszerűen
goto §jumpingtable[] // és elugrunk a megfelelő rutinra
bal: // balról jobbra
MERETY random 2 / 2 * sto aktrand // így biztos páros szám
@sorflag @aktrand [] inv {
MERETX -- {{
@aktrand {{}} [[pálya]][] FAL == then {{<}}
@aktrand {{+}} [[pálya]][] FAL == then {{<}}
@aktrand {{}} FAL inv [[pálya]][]
}}
@sorflag @aktrand 1 inv []
}
goto §nextrandom
jobb: // jobbról balra
MERETY random 2 / 2 * sto aktrand
@sorflag @aktrand [] inv {
MERETX -- {{
@aktrand {{-}} [[pálya]][] FAL == then {{<}}
@aktrand {{--}} [[pálya]][] FAL == then {{<}}
@aktrand {{-}} FAL inv [[pálya]][]
}}
@sorflag @aktrand 1 inv []
}
goto §nextrandom
lent: // Lentről fel
MERETX random 2 / 2 * sto aktrand
@oszlopflag @aktrand [] inv {
MERETY -- {{
{{-}} @aktrand [[pálya]][] FAL == then {{<}}
{{--}} @aktrand [[pálya]][] FAL == then {{<}}
{{-}} @aktrand FAL inv [[pálya]][]
}}
@oszlopflag @aktrand 1 inv []
}
goto §nextrandom
fent: // Fentről le
MERETX random 2 / 2 * sto aktrand
@oszlopflag @aktrand [] inv {
MERETY -- {{
{{}} @aktrand [[pálya]][] FAL == then {{<}}
{{+}} @aktrand [[pálya]][] FAL == then {{<}}
{{}} @aktrand FAL inv [[pálya]][]
}}
@oszlopflag @aktrand 1 inv []
}
goto §nextrandom
newrandomnumber:
MERETX random sto xx MERETY random sto yy @yy @xx [[pálya]][] WAY != then §newrandomnumber
rts
indulajáték:
."Indul a játék\n"
// ---------------------------------------------
// ********************************************************************
//
// Ki- és bejáratok generálása, ha szükséges:
//
MERETY 2 - dup sto yy sto newy 0 dup sto xx sto newx
@yy @xx HŐS inv [[pálya]][] // A hős karakterének letevése
// ********************************************************************
cursoroff
cls
§kirajzol fork sto kirajzoló
§szörnymozgat fork sto szörnymozgató
kirajzolni:
@newy sto yy @newx sto xx
kirajzol2:
@messagestring 6 [] then §meghaltahős
@messagestring 1 @bombs inv []
@messagestring 2 @kincsszámláló inv []
@kincsszámláló TREASUREDB #g == {
100000 inv sleep
@messagestring 5 1 inv [] // Üzenetküldés a szörnymozgatás leállítására
@messagestring 0 1 inv [] // üzenetküldés a kirajzolónak hogy álljon le
@szörnymozgató wait
@kirajzoló wait
."YOU WON! Congratulations!\n"
goto §vége
}
@pálya @yy @xx [][] HALOTTHŐS == {
100000 inv sleep
meghaltahős:
@messagestring 5 1 inv [] // Üzenetküldés a szörnymozgatás leállítására
@messagestring 0 1 inv [] // üzenetküldés a kirajzolónak hogy álljon le
@szörnymozgató wait
@kirajzoló wait
."YOU PERISHED! :(\n"
goto §vége
}
// Billentyűzetinput
newinputchar: #g 11 into sto kar
@kar $ffffffffffffffff == then §kirajzol2
@kar 128 < { @kar 27 == then §vége2
@kar 'q == then §vége2
@kar 'B == { ++() bombs goto §kirajzol2 }
@kar 'b == { @bombs else §newinputchar // Ha elfogyott a bomba, hiába minden...
--() bombs
@xx 1 > { @yy @xx -- [[pálya]][] FAL == { @yy @xx -- WAY inv [[pálya]][] } }
@yy 1 > { @xx { @yy -- @xx [[pálya]][] FAL == { @yy -- @xx WAY inv [[pálya]][] } } }
@xx MERETX 2 - < { @yy @xx ++ [[pálya]][] FAL == { @yy @xx ++ WAY inv [[pálya]][] } }
@yy MERETY 2 - < { @xx { @yy ++ @xx [[pálya]][] FAL == { @yy ++ @xx WAY inv [[pálya]][] } } }
goto §kirajzol2
}
goto §newinputchar }
@kar $ff & sto kk
@xx sto newx @yy sto newy
@kk 1 == { // kurzorfel
--() newy @newy else §newinputchar
@xx else §lépés
@yy 1 == then §newinputchar
// -o-
// @
@newy @newx [[pálya]][] AJTÓSZÁRNYVÍZSZINTES ==
@newy @newx ++ [[pálya]][] AJTÓKÖZEPE ==
@newy -- @newx [[pálya]][] WAY ==
@newy -- @newx ++ [[pálya]][] WAY ==
@newy ++ @newx 2 + [[pálya]][] WAY ==
@newy ++ @newx ++ [[pálya]][] WAY ==
& & & & & {
@newy @newx WAY inv [[pálya]][]
@newy @newx 2 + WAY inv [[pálya]][]
@newy -- @newx ++ AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
@newy ++ @newx ++ AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
goto §lépés
}
// -o-
// @
@newy @newx [[pálya]][] AJTÓSZÁRNYVÍZSZINTES ==
@newy @newx -- [[pálya]][] AJTÓKÖZEPE ==
@newy -- @newx [[pálya]][] WAY ==
@newy -- @newx -- [[pálya]][] WAY ==
@newy ++ @newx 2 - [[pálya]][] WAY ==
@newy ++ @newx -- [[pálya]][] WAY ==
& & & & & {
@newy @newx WAY inv [[pálya]][]
@newy @newx 2 - WAY inv [[pálya]][]
@newy -- @newx -- AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
@newy ++ @newx -- AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
goto §lépés
}
goto §lépés
} // kurzorfel vége
@kk 2 == { // kurzorle
++() newy @newy MERETY -- >= then §newinputchar
@xx else §lépés
// @
// -o-
@newy @newx [[pálya]][] AJTÓSZÁRNYVÍZSZINTES ==
@newy @newx ++ [[pálya]][] AJTÓKÖZEPE ==
@newy ++ @newx [[pálya]][] WAY ==
@newy ++ @newx ++ [[pálya]][] WAY ==
@newy -- @newx 2 + [[pálya]][] WAY ==
@newy -- @newx ++ [[pálya]][] WAY ==
& & & & & {
@newy @newx WAY inv [[pálya]][]
@newy @newx 2 + WAY inv [[pálya]][]
@newy -- @newx ++ AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
@newy ++ @newx ++ AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
goto §lépés
}
// @
// -o-
@newy @newx [[pálya]][] AJTÓSZÁRNYVÍZSZINTES ==
@newy @newx -- [[pálya]][] AJTÓKÖZEPE ==
@newy ++ @newx [[pálya]][] WAY ==
@newy ++ @newx -- [[pálya]][] WAY ==
@newy -- @newx 2 - [[pálya]][] WAY ==
@newy -- @newx -- [[pálya]][] WAY ==
& & & & & {
@newy @newx WAY inv [[pálya]][]
@newy @newx 2 - WAY inv [[pálya]][]
@newy -- @newx -- AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
@newy ++ @newx -- AJTÓSZÁRNYFÜGGŐLEGES inv [[pálya]][]
goto §lépés
}
goto §lépés
} // kurzorle vége
@kk 3 == { // kurzorjobbra
++() newx @newx MERETX >= then §newinputchar
@xx MERETX -- == then §newinputchar
@xx else §lépés
// @|
// o
// |
//@newy 2 + MERETY >= then §lépés
@newy @newx [[pálya]][] AJTÓSZÁRNYFÜGGŐLEGES ==
@newy ++ @newx [[pálya]][] AJTÓKÖZEPE == & else §jobbra2
@newy @newx ++ [[pálya]][] WAY ==
@newy ++ @newx ++ [[pálya]][] WAY ==
@newy ++ @newx -- [[pálya]][] WAY ==
@newy 2 + @newx -- [[pálya]][] WAY ==
& & & {
@newy @newx WAY inv [[pálya]][]
@newy 2 + @newx WAY inv [[pálya]][]
@newy ++ @newx -- AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
@newy ++ @newx ++ AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
goto §lépés
}
// |
// o
// @|
jobbra2:
@newy -- else §lépés
@newy @newx [[pálya]][] AJTÓSZÁRNYFÜGGŐLEGES ==
@newy -- @newx [[pálya]][] AJTÓKÖZEPE ==
@newy @newx ++ [[pálya]][] WAY ==
@newy -- @newx ++ [[pálya]][] WAY ==
@newy -- @newx -- [[pálya]][] WAY ==
@newy 2 - @newx -- [[pálya]][] WAY ==
& & & & & {
@newy @newx WAY inv [[pálya]][]
@newy 2 - @newx WAY inv [[pálya]][]
@newy -- @newx -- AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
@newy -- @newx ++ AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
goto §lépés
}
goto §lépés
} // kurzorjobbra vége
@kk 4 == { // kurzorbalra
@xx else §newinputchar
--() newx @newx else §newinputchar
// |@
// o
// |
//@newy 2 + MERETY >= then §lépés
@newy @newx [[pálya]][] AJTÓSZÁRNYFÜGGŐLEGES ==
@newy ++ @newx [[pálya]][] AJTÓKÖZEPE == & else §balra2
@newy @newx -- [[pálya]][] WAY ==
@newy ++ @newx -- [[pálya]][] WAY ==
@newy ++ @newx ++ [[pálya]][] WAY ==
@newy 2 + @newx ++ [[pálya]][] WAY ==
& & & {
@newy @newx WAY inv [[pálya]][]
@newy 2 + @newx WAY inv [[pálya]][]
@newy ++ @newx -- AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
@newy ++ @newx ++ AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
goto §lépés
}
// |
// o
// |@
balra2:
//@newy -- else §lépés
@newy @newx [[pálya]][] AJTÓSZÁRNYFÜGGŐLEGES ==
@newy -- @newx [[pálya]][] AJTÓKÖZEPE == & else §lépés
@newy @newx -- [[pálya]][] WAY ==
@newy -- @newx ++ [[pálya]][] WAY ==
@newy -- @newx -- [[pálya]][] WAY ==
@newy 2 - @newx ++ [[pálya]][] WAY ==
& & & {
@newy @newx WAY inv [[pálya]][]
@newy 2 - @newx WAY inv [[pálya]][]
@newy -- @newx -- AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
@newy -- @newx ++ AJTÓSZÁRNYVÍZSZINTES inv [[pálya]][]
goto §lépés
}
goto §lépés
} // kurzorbalra vége
goto §newinputchar
// ====================================================================
// ====================================================================
lépés:
@newy @newx [[pálya]][] FAL == then §newinputchar
@newy @newx [[pálya]][] AJTÓKÖZEPE == then §newinputchar
@newy @newx [[pálya]][] AJTÓSZÁRNYVÍZSZINTES == then §newinputchar
@newy @newx [[pálya]][] AJTÓSZÁRNYFÜGGŐLEGES == then §newinputchar
@newy @newx [[pálya]][] TREASURE == { ++() kincsszámláló }
@newy @newx [[pálya]][] bomba == { ++() bombs }
@newy @newx [[pálya]][] szörny == { @yy @xx WAY inv [[pálya]][]
@newy @newx HALOTTHŐS inv [[pálya]][]
goto §kirajzolni }
@yy @xx WAY inv [[pálya]][]
@newy @newx HŐS inv [[pálya]][]
goto §kirajzolni
// ********************************************************************
vége2:
// üzenetküldés a child processeknek hogy álljanak le
@messagestring 0 1 inv []
@messagestring 5 1 inv []
// Várakozás a child processek befejeződésére:
@szörnymozgató wait
@kirajzoló wait
vége:
@messagestring inv mem
@sxkoord inv mem
@sykoord inv mem
@pálya inv mem
,,, cursoron
end
// ********************************************************************
kirajzol:
closestdin // Nem várunk semmi billentyűzetinputot
{.. // végtelenciklus
// ..................................................................
@messagestring 0 [] { end } // Parancs érkezett szeppuku elkövetésére...
// ..................................................................
topleft
#k MERETY yloop: {{ MERETX {{
{{}}§yloop {{}} [[pálya]][] WAY == { wayszín tint wayháttérszín inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] FAL == { FALszín tint FALháttérszín inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] AJTÓSZÁRNYFÜGGŐLEGES == { AJTÓszín tint AJTÓhszin inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] AJTÓSZÁRNYVÍZSZINTES == { AJTÓszín tint AJTÓhszin inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] AJTÓKÖZEPE == { AJTÓszín tint AJTÓhszin inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] bomba == { bombaszín tint bombahszin inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] szörny == { szörnyszín tint szörnyhszin inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] gyengeszörny == {
gyengeszörnyszín tint gyengeszörnyhszin inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] HŐS == { HŐSszín tint HŐSháttérszín inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] HALOTTHŐS == { HŐSszín tint HŐSháttérszín inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
{{}}§yloop {{}} [[pálya]][] 'a >= {{}}§yloop {{}} [[pálya]][] 'z <= &
{ kincsszín tint kincsháttérszín inv tint {{}}§yloop {{}} [[pálya]][] print {{<}} }
,,, @pálya {{}}§yloop {{}} [][] print
}} ,,, NL }} NL
."Collected treasure = " #g @messagestring 2 [] print ." Bombs = " @messagestring 1 [] printnl
VÁRAKOZIK inv sleep
..}
// ********************************************************************
szörnymozgat:
closestdin closestdout closestderr // Nem várunk semmi billentyűzetinputot és nem is írunk sehova
randinit
{.. // végtelenciklus
6000 inv sleep
// .....................................................................
@messagestring 5 [] { end } // Parancs érkezett szeppuku elkövetésére...
// .....................................................................
szörnyekszáma random sto akts
@sxkoord @akts [] !sto sx @sykoord @akts [] !sto sy #g | inv { {.<.} }
@sy @sx [[pálya]][] szörny == {
szörnygyengülvalószínűség random 1 == { @pálya @sy @sx gyengeszörny inv [][] {.<.} }
sbr §szörnylépéskeres
#g
@szörnyy @szörnyx | else {.<.} // Ha nem talált helyet ahova mozoghatna
@szörnyy @szörnyx [[pálya]][] HŐS == { @pálya @szörnyy @szörnyx HALOTTHŐS inv [][] @messagestring 6 1 inv [] 1000 inv sleep {.<.} }
@pálya @sy @sx WAY inv [][] @pálya @szörnyy @szörnyx szörny inv [][]
@sxkoord @akts @szörnyx inv [] @sykoord @akts @szörnyy inv []
{.<.}
}
@sy @sx [[pálya]][] gyengeszörny == {
szörnyerősödikvalószínűség random 1 == { @pálya @sy @sx szörny inv [][] {.<.} }
sbr §szörnylépéskeres
#g
@szörnyy @szörnyx | else {.<.} // Ha nem talált helyet ahova mozoghatna
@pálya @sy @sx WAY inv [][]
@szörnyy @szörnyx [[pálya]][] HŐS != { // Ha gyenge szörny találkozik a hőssel, a szörnynek vége, nem rajzoljuk ki
@pálya @szörnyy @szörnyx gyengeszörny inv [][]
}{ zero szörnyx zero szörnyy }
@sxkoord @akts @szörnyx inv [] @sykoord @akts @szörnyy inv []
{.<.}
}
..}
// ..................................................................
szörnylépéskeres:
zero szörnyy zero szörnyx
24 random sto kvartett // Választunk egy iránykvartettet
#g 4 {{
@kvartett 4 * {{}} + §irányok[] sto sirány
@sirány 0 == { // fel
@sy else {{<}}
@sy -- @sx [[pálya]][] WAY ==
@sy -- @sx [[pálya]][] HŐS == | { @sy -- sto szörnyy @sx sto szörnyx rts }
{{<}}
} // fel vége
@sirány 1 == { // le
@sy ++ MERETY -- >= then {{<}}
@sy ++ @sx [[pálya]][] WAY ==
@sy ++ @sx [[pálya]][] HŐS == | { @sy ++ sto szörnyy @sx sto szörnyx rts }
{{<}}
} // le vége
@sirány 2 == { // balra
@sx else {{<}}
@sy @sx -- [[pálya]][] WAY ==
@sy @sx -- [[pálya]][] HŐS == | { @sy sto szörnyy @sx -- sto szörnyx rts }
{{<}}
} // balra vége
@sirány 3 == { // jobbra
@sx ++ MERETX -- >= then {{<}}
@sy @sx ++ [[pálya]][] WAY ==
@sy @sx ++ [[pálya]][] HŐS == | { @sy sto szörnyy @sx ++ sto szörnyx rts }
{{<}}
} // jobbra vége
}}
rts
irányok:
0 1 2 3 0 1 3 2 0 2 1 3 0 2 3 1 0 3 1 2 0 3 2 1
1 0 2 3 1 0 3 2 1 2 0 3 1 2 3 0 1 3 0 2 1 3 2 0
2 1 0 3 2 1 3 0 2 0 1 3 2 0 3 1 2 3 1 0 2 3 0 1
3 1 2 0 3 1 0 2 3 2 1 0 3 2 0 1 3 0 1 2 3 0 2 1
// ********************************************************************
{ „kk” }
{ „xx” }
{ „yy” }
{ „sx” }
{ „sy” }
{ „kar” }
{ „newx” }
{ „newy” }
{ „akts” }
{ „bombs” }
{ „pálya” }
{ „sirány” }
{ „sxkoord” }
{ „sykoord” }
{ „szörnyx” }
{ „szörnyy” }
{ „kvartett” }
{ „kirajzoló” }
{ „messagestring” }
{ „szörnymozgató” }
{ „kincsszámláló” }
// ---------------------------------------------
// ..........................................................
{ „initflag” }
{ „oszlopflag” }
{ „sorflag” }
{ „aktrand” }
jumpingtable: §bal §jobb §lent §fent
// ---------------------------------------------------------
</syntaxhighlight>
{{out}}
<pre>
Line 697 ⟶ 1,776:
{{libheader|nim-ncurses}}
This translation uses the binding for “ncurses” and have been tested on Linux (Manjaro).
<
import ncurses
Line 1,067 ⟶ 2,146:
play()</
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #000080;font-style:italic;">-- demo/rosetta/CLI_maze.exw</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (wait_key(), get_key(), position(), clear_screen(), etc)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">W</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">WINDOWS</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">UP</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">W</span><span style="color: #0000FF;">?</span><span style="color: #000000;">328</span><span style="color: #0000FF;">:</span><span style="color: #000000;">259</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">DOWN</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">W</span><span style="color: #0000FF;">?</span><span style="color: #000000;">336</span><span style="color: #0000FF;">:</span><span style="color: #000000;">258</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">LEFT</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">W</span><span style="color: #0000FF;">?</span><span style="color: #000000;">331</span><span style="color: #0000FF;">:</span><span style="color: #000000;">260</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">RGHT</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">W</span><span style="color: #0000FF;">?</span><span style="color: #000000;">333</span><span style="color: #0000FF;">:</span><span style="color: #000000;">261</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">ESC</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">#1B</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">MX</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">69</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- No of columns (1..MX), must be odd.</span>
<span style="color: #000000;">MY</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- No of rows (1..MY), must be odd.</span>
<span style="color: #000000;">TREASURE</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'$'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">TREASUREDB</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- treasuredb means how many $ signs will be placed</span>
<span style="color: #000000;">WAY</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">WALL</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'X'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">DOORS</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">20</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- No of doors</span>
<span style="color: #000000;">DOOR_CENTER</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'o'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">DOOR_WING_VERTICAL</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'|'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">DOOR_WING_HORIZONTAL</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'-'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">HERO</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'@'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">DEAD_HERO</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'+'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">NUMBER_OF_BOMBS</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">BOMB</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'b'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">NUMBER_OF_MONSTERS</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">20</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">MONSTER</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'*'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">WEAK_MONSTER</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'.'</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">MONSTER_WEAKNESS_PROBABILITY</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">25</span><span style="color: #0000FF;">,</span>
<span style="color: #000080;font-style:italic;">-- The higher the above number, the lower the chance that a strong monster will become weak.</span>
<span style="color: #000000;">MONSTER_INTENSIFIES_PROBABILITY</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span>
<span style="color: #000080;font-style:italic;">-- The higher the number above, the lower the chance that a weak monster will get stronger.</span>
<span style="color: #000000;">help_text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Maze game.
The object of the game is to get all the treasures. The symbol of the treasure is the $ sign.
Help (display this text): press ? or h
Exit: press Esc or q
You can detonate a bomb by pressing b, but only as long as your bomb remains.
A bomb destroys every wall around the player (the outermost, framing of the maze
except for its walls), but it won't kill monsters.
The bomb does not destroy diagonally, only vertically and horizontally.
The bomb will not destroy the doors or the treasure.
You can also find bombs in the maze, represented by the letter b. If you step on them,
you got the bomb with it, that is, the number of your bombs increases, for later use.
The game ends when you have acquired all the treasures.
The maze has not only walls but also revolving doors.
The revolving door, if horizontal, looks like this: -o-
If vertical, like this:
|
o
|
The center of the revolving door is represented by the character o, the wings by the line.
The revolving door can be rotated if you take your wing in the right direction with your character,
and if nothing stands in the way of rotation.
The player is represented by @ in the game, and his starting point is always in the lower left corner.
There is a possibility of a little cheating in the game: each press of the letter c is one increases
the amount of your bombs.
"""</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">bombs</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">treasure_counter</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">tb</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">WALL</span><span style="color: #0000FF;">,</span><span style="color: #000000;">MX</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">inw</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WALL</span><span style="color: #0000FF;">&</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">WAY</span><span style="color: #0000FF;">,</span><span style="color: #000000;">MX</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)&</span><span style="color: #000000;">WALL</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">grid</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">tb</span><span style="color: #0000FF;">}&</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">inw</span><span style="color: #0000FF;">,</span><span style="color: #000000;">MY</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)&{</span><span style="color: #000000;">tb</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">sxkoord</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">NUMBER_OF_MONSTERS</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">sykoord</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">NUMBER_OF_MONSTERS</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">gen_flags</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span><span style="color: #000000;">l</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">l</span> <span style="color: #008080;">by</span> <span style="color: #000000;">2</span> <span style="color: #008080;">do</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">generatemaze</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">colflag</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">gen_flags</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MX</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">rowflag</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">gen_flags</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MY</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #000000;">colflag</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">or</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rowflag</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">direction</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">j</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">direction</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">2</span><span style="color: #0000FF;">?</span><span style="color: #000000;">MY</span><span style="color: #0000FF;">:</span><span style="color: #000000;">MX</span><span style="color: #0000FF;">))/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">2</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">switch</span> <span style="color: #000000;">direction</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">case</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">:</span> <span style="color: #000080;font-style:italic;">-- left</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">rowflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">MX</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">][</span><span style="color: #000000;">r</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">][</span><span style="color: #000000;">r</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">][</span><span style="color: #000000;">r</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WALL</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">rowflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">case</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">:</span> <span style="color: #000080;font-style:italic;">-- right</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">rowflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">=</span><span style="color: #000000;">MX</span> <span style="color: #008080;">to</span> <span style="color: #000000;">3</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">][</span><span style="color: #000000;">r</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">][</span><span style="color: #000000;">r</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">][</span><span style="color: #000000;">r</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WALL</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">rowflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">case</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">:</span> <span style="color: #000080;font-style:italic;">-- up</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">colflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #000000;">MY</span> <span style="color: #008080;">to</span> <span style="color: #000000;">3</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WALL</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">colflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">case</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">:</span> <span style="color: #000080;font-style:italic;">-- down</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">colflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">MY</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">WALL</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WALL</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">colflag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">switch</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">doors_placed</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">doors_placed</span><span style="color: #0000FF;"><</span><span style="color: #000000;">DOORS</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MX</span><span style="color: #0000FF;">-</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">2</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MY</span><span style="color: #0000FF;">-</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">2</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">!=</span> <span style="color: #000000;">WAY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #000080;font-style:italic;">-- top left corner free</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #000080;font-style:italic;">-- top right corner free</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #000080;font-style:italic;">-- left corner free</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- right corner free
-- Let's see if we can put a vertical door.</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall above the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall above the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall below the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall below the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #000080;font-style:italic;">-- left neighbor free</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- right neighbor free</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">DOOR_CENTER</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">DOOR_WING_VERTICAL</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">DOOR_WING_VERTICAL</span>
<span style="color: #000000;">doors_placed</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000080;font-style:italic;">-- Let's see if we can put a horizontal door.</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall left of the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall left of the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall right of the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span> <span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WALL</span> <span style="color: #000080;font-style:italic;">-- wall right of the current position</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #000080;font-style:italic;">-- above neighbor free</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">WAY</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- below neighbor free</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span> <span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">DOOR_CENTER</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">DOOR_WING_HORIZONTAL</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">DOOR_WING_HORIZONTAL</span>
<span style="color: #000000;">doors_placed</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">stuff</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">TREASUREDB</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">TREASURE</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">NUMBER_OF_BOMBS</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">BOMB</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">NUMBER_OF_MONSTERS</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">WEAK_MONSTER</span><span style="color: #0000FF;">}}</span> <span style="color: #000080;font-style:italic;">-- At first, all monsters are weak.</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">stuff</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">what</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">stuff</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">iter</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MX</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MY</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]==</span><span style="color: #000000;">WAY</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">what</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">what</span><span style="color: #0000FF;">=</span><span style="color: #000000;">WEAK_MONSTER</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">sxkoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">x</span>
<span style="color: #000000;">sykoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">y</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">n</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">iter</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">iter</span><span style="color: #0000FF;">></span><span style="color: #000000;">10000</span> <span style="color: #008080;">then</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> <span style="color: #000080;font-style:italic;">-- (sanity check)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">terminate</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">showhelp</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">draw</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">cursor</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NO_CURSOR</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">showhelp</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">clear_screen</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">help_text</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">clear_screen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">showhelp</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">grid</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)&</span><span style="color: #008000;">"\n\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Collected treasure = %d Bombs = %d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">treasure_counter</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bombs</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">terminate</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">task_yield</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">dy</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">dx</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">HV</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">DOOR_WING_HORIZONTAL</span><span style="color: #0000FF;">,</span><span style="color: #000000;">DOOR_WING_VERTICAL</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">rotate_door</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">4</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">wy</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dy</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">wx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">cy</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">+</span><span style="color: #000000;">wy</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">cx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">wx</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">DOOR_CENTER</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WAY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WAY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WAY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WAY</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- four corners empty</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">py</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dy</span><span style="color: #0000FF;">[-</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">px</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dx</span><span style="color: #0000FF;">[-</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">py</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">px</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WAY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">py</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">-</span><span style="color: #000000;">px</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WAY</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- swung door empty</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">door</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">flip</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">HV</span><span style="color: #0000FF;">[-</span><span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">door</span><span style="color: #0000FF;">,</span><span style="color: #000000;">HV</span><span style="color: #0000FF;">)]</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">py</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">px</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">flip</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">py</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">-</span><span style="color: #000000;">px</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">flip</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">wy</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">wx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">wy</span><span style="color: #0000FF;">][</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">-</span><span style="color: #000000;">wx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">exit</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">MY</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">keyboard</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nx</span>
<span style="color: #008080;">while</span> <span style="color: #008080;">not</span> <span style="color: #000000;">terminate</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">lower</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_key</span><span style="color: #0000FF;">())</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #000000;">task_yield</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">ESC</span> <span style="color: #008080;">or</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #008000;">'q'</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #008000;">'b'</span> <span style="color: #008080;">and</span> <span style="color: #000000;">bombs</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">bombs</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">4</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">ny</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">nx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;"><</span><span style="color: #000000;">MY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;"><</span><span style="color: #000000;">MX</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WALL</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WAY</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #008000;">'c'</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">bombs</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #008000;">'?'</span> <span style="color: #008080;">or</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #008000;">'h'</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">showhelp</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">UP</span><span style="color: #0000FF;">,</span><span style="color: #000000;">DOWN</span><span style="color: #0000FF;">,</span><span style="color: #000000;">LEFT</span><span style="color: #0000FF;">,</span><span style="color: #000000;">RGHT</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ch</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">ny</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">nx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;"><</span><span style="color: #000000;">MY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;"><</span><span style="color: #000000;">MX</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">DOOR_WING_VERTICAL</span>
<span style="color: #008080;">or</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">DOOR_WING_HORIZONTAL</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span> <span style="color: #000080;font-style:italic;">-- (temp. "ghost" him)</span>
<span style="color: #000000;">rotate_door</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">HERO</span>
<span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">]</span> <span style="color: #000080;font-style:italic;">-- (maybe unaltered)</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">MONSTER</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">DEAD_HERO</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ny</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">nx</span>
<span style="color: #008080;">exit</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">TREASURE</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">treasure_counter</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">treasure_counter</span><span style="color: #0000FF;">=</span><span style="color: #000000;">TREASUREDB</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">terminate</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">BOMB</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">bombs</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">WAY</span>
<span style="color: #008080;">or</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">WEAK_MONSTER</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">HERO</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ny</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">nx</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000000;">terminate</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">get_key</span><span style="color: #0000FF;">()!=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span> <span style="color: #000080;font-style:italic;">-- (purge kbd buffer)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">sy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">sx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">monster_y</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">monster_x</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">monster_step_finder</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">monster_y</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #000000;">monster_x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">shuffle</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ny</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">sy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dy</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">nx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">sx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">dx</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">ny</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">MY</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">nx</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">MX</span>
<span style="color: #008080;">and</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ny</span><span style="color: #0000FF;">][</span><span style="color: #000000;">nx</span><span style="color: #0000FF;">],{</span><span style="color: #000000;">WAY</span><span style="color: #0000FF;">,</span><span style="color: #000000;">HERO</span><span style="color: #0000FF;">})</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">monster_y</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ny</span>
<span style="color: #000000;">monster_x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">nx</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">true</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">monster_move</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">while</span> <span style="color: #008080;">not</span> <span style="color: #000000;">terminate</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">active</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">NUMBER_OF_MONSTERS</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">sx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">sxkoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">sy</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">sykoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">sx</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sy</span><span style="color: #0000FF;">][</span><span style="color: #000000;">sx</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">MONSTER</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MONSTER_WEAKNESS_PROBABILITY</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sy</span><span style="color: #0000FF;">][</span><span style="color: #000000;">sx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WEAK_MONSTER</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">monster_step_finder</span><span style="color: #0000FF;">()</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">monster_y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">monster_x</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">HERO</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">monster_y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">monster_x</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">DEAD_HERO</span>
<span style="color: #000000;">terminate</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span>
<span style="color: #008080;">exit</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sy</span><span style="color: #0000FF;">][</span><span style="color: #000000;">sx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">monster_y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">monster_x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">MONSTER</span>
<span style="color: #000000;">sxkoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">monster_x</span>
<span style="color: #000000;">sykoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">monster_y</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">WEAK_MONSTER</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">MONSTER_INTENSIFIES_PROBABILITY</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sy</span><span style="color: #0000FF;">][</span><span style="color: #000000;">sx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">MONSTER</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">monster_step_finder</span><span style="color: #0000FF;">()</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sy</span><span style="color: #0000FF;">][</span><span style="color: #000000;">sx</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">WAY</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">monster_y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">monster_x</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">HERO</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">monster_y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">monster_x</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">WEAK_MONSTER</span>
<span style="color: #000000;">sxkoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">monster_x</span>
<span style="color: #000000;">sykoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">monster_y</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">sxkoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #000000;">sykoord</span><span style="color: #0000FF;">[</span><span style="color: #000000;">active</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">task_yield</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">generatemaze</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">HERO</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">draw_id</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">task_create</span><span style="color: #0000FF;">(</span><span style="color: #000000;">draw</span><span style="color: #0000FF;">,{}),</span>
<span style="color: #000000;">mstr_id</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">task_create</span><span style="color: #0000FF;">(</span><span style="color: #000000;">monster_move</span><span style="color: #0000FF;">,{})</span>
<span style="color: #000000;">task_schedule</span><span style="color: #0000FF;">(</span><span style="color: #000000;">draw_id</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">0.2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.2</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">task_schedule</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mstr_id</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">0.1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.1</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">keyboard</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">treasure_counter</span><span style="color: #0000FF;">=</span><span style="color: #000000;">TREASUREDB</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"YOU WON! Congratulations!\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">y</span><span style="color: #0000FF;">][</span><span style="color: #000000;">x</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">DEAD_HERO</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"YOU PERISHED!\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
=={{header|Wren}}==
{{trans|Nim}}
{{trans|Phix}}
{{libheader|ncurses}}
{{libheader|Wren-dynamic}}
{{libheader|Wren-str}}
{{libheader|Wren-iterate}}
An embedded script so we can use the ncurses library.
<syntaxhighlight lang="wren">/* CLI-based_maze_game.wren */
import "./dynamic" for Enum, Tuple, Struct
import "./str" for Char
import "./iterate" for Stepped
import "random" for Random
// all methods assume stdscr
class NC {
foreign static initScr()
foreign static cbreak()
foreign static nocbreak()
foreign static keypad(bf)
foreign static echo()
foreign static noecho()
foreign static cursSet(visibility)
foreign static erase()
foreign static addStr(str)
foreign static getch()
foreign static move(y, x)
foreign static refresh()
foreign static endwin()
}
var KeyUp = 259
var KeyDown = 258
var KeyLeft = 260
var KeyRight = 261
var Mx = 69 // no of columns (0..Mx-1), must be odd
var My = 31 // no of rows (0..My-1), must be odd
var Treasure = Char.code("$")
var TreasureDb = 3 // how many $ signs will be placed
var Way = Char.code(" ")
var Wall = Char.code("X")
var Doors = 20 // no of doors
var DoorCenter = Char.code("o")
var DoorWingVertical = Char.code("|")
var DoorWingHorizontal = Char.code("-")
var Hero = Char.code("@")
var DeadHero = Char.code("+")
var NumberOfBombs = 5
var Bomb = Char.code("b")
var NumberOfMonsters = 20
var Monster = Char.code("*")
var WeakMonster = Char.code(".")
// the higher this is, the lower the chance that a string monster will become weak
var MonsterWeaknessProbability = 25
// the higher this is, the lower the chance that a weak monster will get stronger
var MonsterIntensifiesProbability = 5
var HelpText = """
Maze game.
The object of the game is to get all the treasures. The symbol of the treasure is the $ sign.
Line 1,124 ⟶ 2,628:
and if nothing stands in the way of rotation.
The player is represented by @ in the game, and his starting point is always in the lower left corner.
There is a possibility of a little cheating in the game: each press of the letter c
the amount of your bombs.
"""
var Direction = Enum.create("Direction", ["left", "right", "up", "down"])
var Position = Tuple.create("Position", ["x", "y"])
var gameFields = ["grid", "scoords", "showHelp", "terminate", "treasureCounter", "bombs", "x", "y"]
var Game = Struct.create("Game", gameFields)
var None = Position.new(0, 0)
var Dy = [-1, 1, 0, 0]
var Dx = [0, 0, -1, 1]
var rand = Random.new()
var genFlags = Fn.new { |n|
var flags = List.filled(n, false)
for (i in Stepped.new(0...n, 2)) flags[i] = true
return flags
}
var initGame = Fn.new {
var grid = List.filled(My, null)
for (y in 0...My) grid[y] = List.filled(Mx, Wall)
for (y in 1...My-1)
for (x in 1...Mx-1) grid[y][x] =
}
var colFlags = genFlags.call(Mx)
var rowFlags = genFlags.call(My)
while (colFlags.any { |f| f } || rowFlags.any { |f| f }) {
var dir = rand.int(4)
var j = rand.int((dir <= Direction.right) ? My : Mx)
if (j % 2 == 1) j = j + 1
if (dir == Direction.left) {
if (rowFlags[j]) {
for (r in 0...Mx-1) {
if (grid[j][r] != Wall && grid[j][r+1] != Wall) grid[j][r] = Wall
}
rowFlags[j] = false
}
} else if (dir == Direction.right) {
if (rowFlags[j]) {
for (r in Mx-1..2) {
if (grid[j][r-1] != Wall && grid[j][r-2] != Wall) grid[j][r-1] = Wall
}
rowFlags[j] = false
}
} else if (dir == Direction.up) {
if (colFlags[j]) {
for (c in My-1..2) {
if (grid[c-1][j] != Wall && grid[c-2][j] != Wall) grid[c-1][j] = Wall
}
colFlags[j] = false
}
} else if (dir == Direction.down) {
if (colFlags[j]) {
for (c in 0...My-1) {
if (grid[c][j] != Wall && grid[c+1][j] != Wall) grid[c][j] = Wall
}
colFlags[j] = false
}
}
}
var doorsPlaced = 0
while (doorsPlaced < Doors) {
var x = rand.int(2, Mx - 2)
var y = rand.int(2, My - 2)
if (grid[y][x] != Way &&
grid[y-1][x-1] == Way && // top left corner free
grid[y-1][x+1] == Way && // top right corner free
grid[y+1][x-1] == Way && // left corner free
grid[y+1][x+1] == Way) { // right corner free
// let's see if we can put a vertical door
if (grid[y-1][x] == Wall && // wall above the current position
grid[y-2][x] == Wall && // wall above the current position
grid[y+1][x] == Wall && // wall below the current position
grid[y+2][x] == Wall && // wall below the current position
grid[y][x-1] == Way && // left neighbor free
grid[y][x+1] == Way) { // right neighbor free
grid[y][x] = DoorCenter
grid[y-1][x] = DoorWingVertical
grid[y+1][x] = DoorWingVertical
doorsPlaced = doorsPlaced + 1
// let's see if we can put a horizontal door
} else if (grid[y][x-1] == Wall && // wall left of the current position
grid[y][x-2] == Wall && // wall left of the current position
grid[y][x+1] == Wall && // wall right of the current position
grid[y][x+2] == Wall && // wall right of the current position
grid[y+1][x] == Way && // above neighbor free
grid[y-1][x] == Way) { // below neighbor free
grid[y][x] = DoorCenter
grid[y][x-1] = DoorWingHorizontal
grid[y][x+1] = DoorWingHorizontal
doorsPlaced = doorsPlaced + 1
}
}
}
var scoords = List.filled(NumberOfMonsters, null)
for (i in 0...NumberOfMonsters) scoords[i] = Position.new(0, 0)
var stuff = [
[TreasureDb, Treasure],
[NumberOfBombs, Bomb],
[NumberOfMonsters, WeakMonster] // at first, all monsters are weak
]
for (s in stuff) {
var n = s[0]
var what = s[1]
var iter = 1
while (n >= 0) {
var x = rand.int(Mx)
var y = rand.int(My)
if (grid[y][x] == Way) {
grid[y][x] = what
if (what =
n =
iter = iter +
if (iter > 10000)
}
grid[My - 2][1] = Hero
return Game.new(grid, scoords, false, false, 0, 3, 1, My - 2)
}
var draw = Fn.new { |game|
NC.cursSet(0)
while (true) {
if (game.showHelp) {
NC.erase()
NC.addStr(HelpText)
NC.getch()
NC.erase()
game.showHelp = false
}
NC.erase()
NC.move(0, 0)
for (row in game.grid) NC.addStr(row.map { |c| String.fromByte(c) }.join() + "\n")
NC.addStr("\n\nCollected treasure = %(game.treasureCounter) Bombs = %(game.bombs)\n")
NC.refresh()
Fiber.yield()
}
}
var monsterStepFinder = Fn.new { |game, sx, sy|
var result = None
rand.shuffle(m)
for (i in m)
var nx = sx
var ny = sy
if (ny >= 0 && ny < My && nx >= 0 && nx < Mx && [Way, Hero].contains(game.grid[ny][nx])) {
}
return result
}
var monsterMove = Fn.new { |game|
while
var active = rand.int(NumberOfMonsters)
var pos = game.scoords[active]
var sx = pos.x
var sy = pos.y
if (sx != 0) {
var ch = game.grid[sy][sx]
if (ch == Monster) {
if (rand.int(MonsterWeaknessProbability) == 0) {
game.grid[sy][sx] = WeakMonster
} else {
var monster = monsterStepFinder.call(game, sx, sy)
if (monster.x != 0 && monster.y != 0) {
if (game.grid[monster.y][monster.x] == Hero) {
game.grid[monster.y][monster.x] = DeadHero
game.terminate = true
break
}
}
game.grid[sy][sx] = Way
game.grid[monster.y][monster.x] = Monster
game.scoords[active] = monster
}
} else if (ch == WeakMonster) {
if (rand.int(MonsterIntensifiesProbability) == 0) {
game.grid[sy][sx] = Monster
} else {
var monster = monsterStepFinder.call(game, sx, sy)
if (monster.x != 0 && monster.y != 0) {
if (game.grid[monster.y][monster.x] == Hero) {
game.grid[monster.y][monster.x] = WeakMonster
game.scoords[active] = monster
break
} else {
game.scoords[active] = None
}
}
}
}
}
Fiber.yield()
}
}
var rotateDoor = Fn.new { |game, nx, ny|
for (i
if (game.grid[cy
if
if
var flip = DoorWingVertical ? DoorWingHorizontal :
game.grid[cy+py][cx+px] = flip
game.grid[cy-py][cx-px] = flip
game.grid[cy+wy][cx+wx] =
game.grid[cy-wy][cx-wx] =
}
while (true) {
var key = NC.getch()
if (game.bombs
var nx = game.x +
game.bombs
} else {
if
if (ny >= 1
if (ch == DoorWingVertical || ch == DoorWingHorizontal)
game.grid[game.y][game.x] =
} else if
} else if (ch
} else if (ch =
if (ch == Way
game.grid[game.y][game.x] =
}
Fiber.yield()
}
}
var play = Fn.new {
NC.initScr()
NC.cbreak()
NC.keypad(true)
NC.noecho()
var game = initGame.call()
var fDraw = Fiber.new(draw)
var fKeyboard = Fiber.new(keyboard)
var fMonsterMove = Fiber.new(monsterMove)
while (true) {
fDraw.call(game)
if (game.terminate) break
fKeyboard.call(game)
if (!game.terminate) fMonsterMove.call(game)
}
if (game.treasureCounter == TreasureDb) {
NC.addStr("\nYOU WON! Congratulations!\n")
NC.refresh()
NC.getch()
} else if (game.grid[game.y][game.x] == DeadHero) {
NC.addStr("\nYOU PERISHED!\n")
NC.refresh()
NC.getch()
}
}
play.call()
NC.echo()
NC.nocbreak()
NC.endwin()
NC.cursSet(1)</syntaxhighlight>
<br>
We now embed this in the following C program, build and run it.
<syntaxhighlight lang="c">/* gcc CLI-based_maze_game.c -o CLI-based_maze_game -lncurses -lwren -lm */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include <unistd.h>
#include "wren.h"
/* C <=> Wren interface functions */
void C_initScr(WrenVM* vm) {
initscr();
}
void C_cbreak(WrenVM* vm) {
int res = cbreak();
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_nocbreak(WrenVM* vm) {
int res = nocbreak();
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_keypad(WrenVM* vm) {
bool bf = wrenGetSlotBool(vm, 1);
int res = keypad(stdscr, bf);
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_echo(WrenVM* vm) {
int res = echo();
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_noecho(WrenVM* vm) {
int res = noecho();
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_cursSet(WrenVM* vm) {
int visibility = (int)wrenGetSlotDouble(vm, 1);
int res = curs_set(visibility);
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_erase(WrenVM* vm) {
int res = erase();
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_addStr(WrenVM* vm) {
const char *str = wrenGetSlotString(vm, 1);
int res = addstr(str);
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_getch(WrenVM* vm) {
int ch = getch();
wrenSetSlotDouble(vm, 0, (double)ch);
}
void C_move(WrenVM* vm) {
int y = (int)wrenGetSlotDouble(vm, 1);
int x = (int)wrenGetSlotDouble(vm, 2);
int res = move(y, x);
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_refresh(WrenVM* vm) {
int res = refresh();
wrenSetSlotDouble(vm, 0, (double)res);
}
void C_endwin(WrenVM* vm) {
int res = endwin();
wrenSetSlotDouble(vm, 0, (double)res);
}
WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,
const char* module,
const char* className,
bool isStatic,
const char* signature) {
if (strcmp(module, "main") == 0) {
if (strcmp(className, "NC") == 0) {
if (isStatic && strcmp(signature, "initScr()") == 0) return C_initScr;
if (isStatic && strcmp(signature, "cbreak()") == 0) return C_cbreak;
if (isStatic && strcmp(signature, "nocbreak()") == 0) return C_nocbreak;
if (isStatic && strcmp(signature, "keypad(_)") == 0) return C_keypad;
if (isStatic && strcmp(signature, "echo()") == 0) return C_echo;
if (isStatic && strcmp(signature, "noecho()") == 0) return C_noecho;
if (isStatic && strcmp(signature, "cursSet(_)") == 0) return C_cursSet;
if (isStatic && strcmp(signature, "erase()") == 0) return C_erase;
if (isStatic && strcmp(signature, "addStr(_)") == 0) return C_addStr;
if (isStatic && strcmp(signature, "getch()") == 0) return C_getch;
if (isStatic && strcmp(signature, "move(_,_)") == 0) return C_move;
if (isStatic && strcmp(signature, "refresh()") == 0) return C_refresh;
if (isStatic && strcmp(signature, "endwin()") == 0) return C_endwin;
}
}
return NULL;
}
static void writeFn(WrenVM* vm, const char* text) {
printf("%s", text);
}
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE:
printf("[%s line %d] [Error] %s\n", module, line, msg);
break;
case WREN_ERROR_STACK_TRACE:
printf("[%s line %d] in %s\n", module, line, msg);
break;
case WREN_ERROR_RUNTIME:
printf("[Runtime Error] %s\n", msg);
break;
}
}
char *readFile(const char *fileName) {
FILE *f = fopen(fileName, "r");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
rewind(f);
char *script = malloc(fsize + 1);
fread(script, 1, fsize, f);
fclose(f);
script[fsize] = 0;
return script;
}
static void loadModuleComplete(WrenVM* vm, const char* module, WrenLoadModuleResult result) {
if( result.source) free((void*)result.source);
}
WrenLoadModuleResult loadModule(WrenVM* vm, const char* name) {
WrenLoadModuleResult result = {0};
if (strcmp(name, "random") != 0 && strcmp(name, "meta") != 0) {
result.onComplete = loadModuleComplete;
char fullName[strlen(name) + 6];
strcpy(fullName, name);
strcat(fullName, ".wren");
result.source = readFile(fullName);
}
return result;
}
int main(int argc, char **argv) {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = &writeFn;
config.errorFn = &errorFn;
config.bindForeignMethodFn = &bindForeignMethod;
config.loadModuleFn = &loadModule;
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "CLI-based_maze_game.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) {
case WREN_RESULT_COMPILE_ERROR:
printf("Compile Error!\n");
break;
case WREN_RESULT_RUNTIME_ERROR:
printf("Runtime Error!\n");
usleep(10000000); // allow time to read it
timeout(-1);
nocbreak();
echo();
endwin();
break;
case WREN_RESULT_SUCCESS:
break;
}
wrenFreeVM(vm);
free(script);
return 0;
}</syntaxhighlight>
{{out}}
Sample opening screen.
<pre>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X . X b . X X X X
XXXXX X X XXX XXXXX X XXXXX XXXXX X-o-X X X X XXXXXXX X-o-X XXXXX X X
X X X X X X X X X X X X X X X X
X XXXXX X X XXXbXXXXX X XXXXXXXXXXX XXXXX X XXX XXXXXXX XXXXX XXXXX X
X X X X X X X X X X X . . X X
XXXXX XXXXXXX XXX-o-XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX X X
X X $ X X . X . X X X X
X XXXXX X X XXX XXXXX X XXXXX XXXXX XXXXX X X X XXXXX X.XXXXX XXXXX X
X X X X X X X . X X X X X X X X X X
XXXXX X X XXX XXXXX XXXXXXXXXXXXX X-o-X X XXX XX-o-XX XXXXX XXXXX X X
X X X X X X X X X X X X .X X X
X.XXXXX X X$XXX XXXXX X XXXXX XXX X XXXXX X X X$XXXXX X XXXXX XXXXX X
X X | X X X X X X X X X X X X X X
X XXXXX o XXXXX X-o-XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX XXXXXXXXXXX X
X X | Xb X X . X X X X
X XXXXX X X XXX XXXXX X XXXXX XXXXX XXXXX X X X XXXXX X XXXXX XXXXX X
X X X X X X X X X X X X b X X
X XXXXXXXXX-o-XXXXXXXXXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXX-o-XXXXXXXXXXXXX
X . X
XX-o-XXXXX-o-XXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXX X
X . . . X
X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXX-o-XXXX
X . X X X X
XXXXX X X XXX XXXXX X XXXXXXXXXXX XXXXX X XXX XX-o-XX XXXXX XXXXX X X
X X X X X X X . X X X X X X X
XXXXX$X XXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXX XXXX-o-XXXX X X
X X X b X X X X
X XXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXXXXXXXXX-o-X XXXXXXXXXXXXXXXXXXXXX
X@ . . X . . b X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Collected treasure = 0 Bombs = 3
</pre>
Corresponding closing screen after a rare victory!
<pre>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X . X b . X X X X
XXXXX X X XXX XXXXX X XXXXX XXXXX X-o-X X X X XXXXXXX X-o-X XXXXX X X
X X X X X X X X X X X X X X X X
X XXXXX X X XXXbXXXXX X XXXXXXXXXXX XXXXX X XXX XXXXXXX XXXXX XXXXX X
X X X X X X X X X X X * * X X
XXXXX XXXXXXX XXX-o-XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX X X
X X X X . X . X X X X
X XXXXX X X XXX XXXXX X XXXXX XXXXX XXXXX X X X XXXXX X.XXXXX XXXXX X
X X X X X X X . X X X X X X X X X X
XXXXX X X XXX XXXXX XXXXXXXXXXXXX X-o-X X XXX XX-o-XX XXXXX XXXXX X X
X X X X X X X X X X X X .X X X
X.XXX X @XXX XXXXX X XXXXX XXX X XXXXX X X X$XXXXX X XXXXX XXXXX X
X X X X X X X X X X X X X X X
X XXX X-o-XXXXX X-o-XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX XXXXXXXXXXX X
X X Xb X X . X X X X
X XXXXX X X XXX XXXXX X XXXXX XXXXX XXXXX X X X XXXXX X XXXXX XXXXX X
X X X X X X X X X X X X b X X
X XXXXXXXXX-o-XXXXXXXXXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXX-o-XXXXXXXXXXXXX
X - . X
XX o XXXXX-o-XXXXX-o-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXX X
X - . . . X
X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXX-o-XXXX
X X X X X
XXXXX X X XXX XXXXX X XXXXXXXXXXX XXXXX X XXX XX-o-XX XXXXX XXXXX X X
X X X X X X X . X X X X X X X
XXXXX X XXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXXX XXXX-o-XXXX X X
X X X b X X X X
X XXXXXXXXXXXXXXXXXXXXXXXXXXX-o-XXXXXXXXXXX-o-X XXXXXXXXXXXXXXXXXXXXX
X . . X . . b X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Collected treasure = 3 Bombs = 1
YOU WON! Congratulations!
</pre>
|