Arc/arc.bqn

52 lines
2.3 KiB
BQN
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env BQN
# SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-FileCopyrightText: 2023 Rampoina <rampoina@protonmail.com>
ansi•Import "ansi.bqn"
Game•Import "logic.bqn"
opts{
a•args
{𝕤
•Out "Usage: "•name" [OPTION]...
--help: Display this help message
--levels,-l FILE: load levels from FILE
--chars STRING: Characters to display for each game object, needs to have length 15
--fchars STRING: Characters to represent each game object in the levels file, needs to have length 15"
•Exit 0
}((´"-h"<a)(´"--help"<a)) @
chars{0=𝕩?" λ$⊕⭍#/\-|+<>^v";𝕩}(»(<"--chars"))/a
fchars{0=𝕩?" λ$⊕⭍#/\-|+<>^v";𝕩}(»(<"--fchars"))/a
l{0=𝕩?"levels";𝕩}(»(<"--levels"))/a
levels{0=𝕩?l;𝕩}(»(<"-l"))/a
n{0=𝕩?1;1𝕩}•BQN¨{𝕊: •Out "Invalid starting level number" •Exit 1}(»(<"-s"))/a
}
gGame{𝕊: •Out •CurrentError @ •Exit 1} opts.nopts.levelsopts.charsopts.fcharsansi.defaultB,ansi.yellow,ansi.cyan,ansi.red
ansi.InitTerm @
clear""
{𝕤 # Loop until the user wins
•Out clearansi.cursor.origin
clear""
•Out "Level: "•Repr 1+g.currentLevel
•Out (g.Color g.pmachine)ansi.defaultB" Power the machines ("(g.Color g.machine)") by moving the mirrors ("(g.Color¨ g.mirrors)ansi.defaultB")"
•Out "Controls: (hjkl or wasd) to move, u to undo, r to reset level, q to quit"
g.Draw @
•Out "Moves: "•Repr ¯1+g.moves
g.WinLevel @ ?
•Out "Good job!, press any key to continue to the next level"
key•term.CharB @
clearansi.clear.screen
g.NextLevel @
{𝕤ansi.RestoreTerm @•Exit 0}(key='q')@
;
key•term.CharB @
{𝕤g.Next ("hjklaswd"=key)/˜0¯1,10,¯10,01}(key"hjklaswd")@
{𝕤clear""ansi.clear.screen˜((1+>(•Repr))¯1+g.moves)g.Undo @}(key='u')@
{𝕤ansi.RestoreTerm @•Exit 0}(key='q')@
{𝕤clearansi.clear.screeng.Reset @}(key='r')@
}•_While_{𝕤g.Over @}@
•Out "Well played, you win!"
ansi.RestoreTerm @