2023-03-04 18:38:17 +01:00
|
|
|
|
#!/usr/bin/env BQN
|
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
# SPDX-FileCopyrightText: 2023 Rampoina <rampoina@protonmail.com>
|
2023-03-05 17:54:59 +01:00
|
|
|
|
|
2023-03-05 03:10:27 +01:00
|
|
|
|
⟨ansi⟩←•Import "ansi.bqn"
|
2023-03-05 15:58:49 +01:00
|
|
|
|
⟨Game⟩←•Import "logic.bqn"
|
2023-03-04 19:33:22 +01:00
|
|
|
|
|
2023-03-05 20:03:03 +01:00
|
|
|
|
opts←{
|
|
|
|
|
a←•args
|
2023-03-05 23:35:15 +01:00
|
|
|
|
_optl_←{≠◶⟨𝔾,𝔽⊑⟩ (»a∊𝕩)/a}
|
|
|
|
|
_opt_←{ 𝔽_optl_𝔾 ⋈𝕩}
|
2023-03-05 21:43:12 +01:00
|
|
|
|
{𝕤
|
|
|
|
|
•Out "Usage: "∾•name∾" [OPTION]...
|
2023-03-06 01:12:22 +01:00
|
|
|
|
-h,--help
|
|
|
|
|
Displays a help message
|
|
|
|
|
|
|
|
|
|
-l,--levels FILE
|
|
|
|
|
Load levels from FILE. (default: a file called “levels”).
|
|
|
|
|
|
|
|
|
|
-c,--chars string
|
|
|
|
|
Characters to display for each game object, needs to have length 15. (default: ” λ$⊕⭍#/-|+<>^v”).
|
|
|
|
|
|
|
|
|
|
-f,--fchars string
|
|
|
|
|
Characters to represent each game object in the levels file, needs to have length 15. (default: ” @$o⭍#/-|+<>^v”).
|
|
|
|
|
|
|
|
|
|
-s,--start N
|
|
|
|
|
Start directly at level number N. (default: 1)."
|
2023-03-05 21:43:12 +01:00
|
|
|
|
•Exit 0
|
2023-03-05 23:35:15 +01:00
|
|
|
|
}⍟∨´"-h"‿"--help"∊a
|
2023-03-05 21:43:12 +01:00
|
|
|
|
|
2023-03-05 23:35:15 +01:00
|
|
|
|
chars ⇐ ⊢_optl_" λ$⊕⭍#/\-|+<>^v" "-c"‿"--chars"
|
2023-03-06 00:42:48 +01:00
|
|
|
|
fchars⇐ ⊢_optl_" @$o⭍#/\-|+<>^v" "-f"‿"--fchars"
|
2023-03-05 23:35:15 +01:00
|
|
|
|
levels⇐ ⊢_optl_"levels" "-l"‿"--levels"
|
|
|
|
|
n⇐{1⌈•BQN⎊{𝕊: •Out "Invalid starting level number" ⋄ •Exit 1} 𝕩}_optl_ 1 "-s"‿"--start"
|
2023-03-05 20:03:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 21:15:08 +01:00
|
|
|
|
g←Game⎊{𝕊: •Out •CurrentError @ ⋄ •Exit 1} opts.n‿opts.levels‿opts.chars‿opts.fchars‿⟨ansi.defaultB,ansi.yellow,ansi.cyan,ansi.red⟩
|
2023-03-05 19:11:54 +01:00
|
|
|
|
ansi.InitTerm @
|
2023-03-04 18:38:17 +01:00
|
|
|
|
clear←""
|
|
|
|
|
{𝕤 # Loop until the user wins
|
2023-03-05 19:11:54 +01:00
|
|
|
|
•Out clear∾ansi.cursor.origin
|
2023-03-05 14:42:33 +01:00
|
|
|
|
clear↩""
|
2023-03-05 15:58:49 +01:00
|
|
|
|
•Out "Level: "∾•Repr 1+g.currentLevel
|
2023-03-05 22:49:04 +01:00
|
|
|
|
•Out (g.Color g.pmachine)∾ansi.defaultB∾" Power the machines ("∾(g.Color g.machine)∾") by moving the mirrors ("∾(∾g.Color¨ g.mirrors)∾ansi.defaultB∾")"
|
2023-03-04 18:38:17 +01:00
|
|
|
|
•Out "Controls: (hjkl or wasd) to move, u to undo, r to reset level, q to quit"
|
2023-03-05 15:58:49 +01:00
|
|
|
|
g.Draw @
|
|
|
|
|
•Out "Moves: "∾•Repr ¯1+≠g.moves
|
|
|
|
|
g.WinLevel @ ?
|
2023-03-04 19:13:53 +01:00
|
|
|
|
•Out "Good job!, press any key to continue to the next level"
|
2023-03-05 14:42:33 +01:00
|
|
|
|
key←•term.CharB @
|
2023-03-05 19:11:54 +01:00
|
|
|
|
clear↩ansi.clear.screen
|
2023-03-05 15:58:49 +01:00
|
|
|
|
g.NextLevel @
|
2023-03-05 19:11:54 +01:00
|
|
|
|
{𝕤⋄ansi.RestoreTerm @⋄•Exit 0}⍟(key='q')@
|
2023-03-05 14:42:33 +01:00
|
|
|
|
;
|
|
|
|
|
key←•term.CharB @
|
2023-03-05 15:58:49 +01:00
|
|
|
|
{𝕤⋄g.Next ⊑("hjklaswd"=key)/∾˜⟨0‿¯1,1‿0,¯1‿0,0‿1⟩}⍟(⊑key∊"hjklaswd")@
|
2023-03-05 20:03:03 +01:00
|
|
|
|
{𝕤⋄clear↩""‿ansi.clear.screen⊑˜((1⊸+>○(≠•Repr)⊢)¯1+≠g.moves)⋄g.Undo @}⍟(key='u')@
|
2023-03-05 19:11:54 +01:00
|
|
|
|
{𝕤⋄ansi.RestoreTerm @⋄•Exit 0}⍟(key='q')@
|
|
|
|
|
{𝕤⋄clear↩ansi.clear.screen⋄g.Reset @}⍟(key='r')@
|
2023-03-05 15:58:49 +01:00
|
|
|
|
}•_While_{𝕤⋄g.Over @}@
|
2023-03-04 18:38:17 +01:00
|
|
|
|
•Out "Well played, you win!"
|
2023-03-05 19:11:54 +01:00
|
|
|
|
ansi.RestoreTerm @
|