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>
|
|
|
|
|
#
|
|
|
|
|
# Arc
|
2023-03-04 19:33:22 +01:00
|
|
|
|
# The level is a 2d matrix of lists (tiles)
|
2023-03-05 14:42:33 +01:00
|
|
|
|
# Each list contains the objects of the game represented as numbers
|
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-04 18:38:17 +01:00
|
|
|
|
e←ansi.e
|
|
|
|
|
•term.RawMode 1 # set terminal to raw mode
|
|
|
|
|
•Out e∾"[?25l"∾e∾"[2J"∾e∾"[H" # Cursor to origin, hide it and clear screen
|
|
|
|
|
clear←""
|
2023-03-05 16:14:24 +01:00
|
|
|
|
|
|
|
|
|
g←Game "levels"‿" λ$⊕⭍#/\-|+<>^v"‿⟨ansi.defaultB,ansi.yellow,ansi.cyan,ansi.red⟩
|
2023-03-04 18:38:17 +01:00
|
|
|
|
{𝕤 # Loop until the user wins
|
2023-03-05 14:42:33 +01:00
|
|
|
|
•Out clear∾e∾"[H" # Cursor to origin
|
|
|
|
|
clear↩""
|
2023-03-05 15:58:49 +01:00
|
|
|
|
•Out "Level: "∾•Repr 1+g.currentLevel
|
2023-03-04 18:38:17 +01:00
|
|
|
|
•Out ansi.yellow∾"⭍"∾ansi.defaultB∾" Power the machines (⊕) by moving the mirrors ("∾ansi.cyan∾"\/"∾ansi.defaultB∾") "
|
|
|
|
|
•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 @
|
|
|
|
|
clear↩e∾"[2J"
|
2023-03-05 15:58:49 +01:00
|
|
|
|
g.NextLevel @
|
2023-03-05 14:42:33 +01:00
|
|
|
|
{𝕤⋄•Out e∾"[?12l"∾e∾"[?25h"⋄•Exit 0}⍟(key='q')@
|
|
|
|
|
;
|
|
|
|
|
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")@
|
|
|
|
|
{𝕤⋄g.Undo @}⍟(key='u')@
|
2023-03-05 14:42:33 +01:00
|
|
|
|
{𝕤⋄•Out e∾"[?12l"∾e∾"[?25h"⋄•Exit 0}⍟(key='q')@
|
2023-03-05 15:58:49 +01:00
|
|
|
|
{𝕤⋄clear↩e∾"[2J"⋄g.Reset @}⍟(key='r')@
|
|
|
|
|
{𝕤⋄clear↩e∾"[2J"}⍟(((1⊸+>○(⌊1+10⋆⁼1⌈⊢)⊢)¯1+≠g.moves)∧key='u')@
|
|
|
|
|
}•_While_{𝕤⋄g.Over @}@
|
2023-03-04 18:38:17 +01:00
|
|
|
|
•Out "Well played, you win!"
|
|
|
|
|
•Out e∾"[?12l"∾e∾"[?25h"
|