diff --git a/arc.bqn b/arc.bqn index ca8b193..1537297 100755 --- a/arc.bqn +++ b/arc.bqn @@ -7,15 +7,16 @@ opts←{ a←•args - •Show a chars ⇐{0=≠𝕩?" λ$⊕⭍#/\-|+<>^v";⊑𝕩}(»(<"--chars")⊸⍷)⊸/a fchars⇐{0=≠𝕩?" λ$⊕⭍#/\-|+<>^v";⊑𝕩}(»(<"--fchars")⊸⍷)⊸/a - levels⇐{0=≠𝕩?"levels";⊑𝕩}(»(<"--levels")⊸⍷)⊸/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 } +g←Game⎊{𝕊: •Out •CurrentError @ ⋄ •Exit 1} opts.n‿opts.levels‿opts.chars‿opts.fchars‿⟨ansi.defaultB,ansi.yellow,ansi.cyan,ansi.red⟩ ansi.InitTerm @ clear←"" -g←Game opts.levels‿opts.chars‿opts.fchars‿⟨ansi.defaultB,ansi.yellow,ansi.cyan,ansi.red⟩ {𝕤 # Loop until the user wins •Out clear∾ansi.cursor.origin clear↩"" diff --git a/logic.bqn b/logic.bqn index 98573e7..fca1fab 100644 --- a/logic.bqn +++ b/logic.bqn @@ -5,7 +5,8 @@ ⟨FindIdx,SplitOnEmpty⟩←•Import "utils.bqn" Game⇐{ # The Game function creates a game object - 𝕊 levelPath‿dchars‿chars‿colors: # from parameters: + 𝕊 n‿levelPath‿dchars‿chars‿colors: # from parameters: + # n: starting level # levelPath: the path of the file containing the levels # dchars: the characters to use for drawing # chars: the characters that are used in the level representation @@ -125,8 +126,14 @@ Game⇐{ # The Game function creates a game object # ------------------------------------------------------------------------------- moves⇐⟨0‿0⟩ # list of moves, each move is a direction, we start without moving - currentLevel⇐0 + currentLevel⇐n-1 + "Invalid number of fchars" ! 15=≠chars + "Invalid number of chars" ! 15=≠dchars + "The level file contains illegal characters" ! ∧´chars∊˜∾´•Flines levelPath levels←Ascii2Matrix¨>¨SplitOnEmpty•FLines levelPath # Load file containing levels + "Some levels don't contain any player" ! ¬∨´0=≠¨{player FindIdx ⊑¨𝕩}¨levels + "Some levels don't contain any machine" ! ¬∨´0=≠¨{machine FindIdx ⊑¨𝕩}¨levels + "The starting level is higher than the number of levels" ! currentLevel<≠levels Next⇐{moves↩moves∾<𝕩} Undo⇐{𝕊:moves↩(-1<≠)⊸↓moves} Draw⇐{𝕊:•Out¨ (currentLevel⊑levels) DrawLevel moves}