diff options
Diffstat (limited to 'main.fnl')
-rw-r--r-- | main.fnl | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/main.fnl b/main.fnl index c205454..8144b11 100644 --- a/main.fnl +++ b/main.fnl @@ -34,17 +34,23 @@ ;; game loop (while (not (= game.stage const.stages.complete)) (with-board game.moves) - ;; validation loop (var is-valid false) (var move "") + ;; validation loop (while (not is-valid) (set move (get-move)) - (set is-valid (game.validate-move move)) - (if (not is-valid) - (print "Try again.") - (do - (print (string.format "Turn %d: You chose %s" game.turns move)) - (game:update move))))) + (case (pcall game.validate-move move) + (false msg) + (do + (let [(i j) (string.find msg ": ") + key (string.sub msg (+ 1 j))] + (print (. const.errors key))) + (print "Try again.")) + ok + (do + (set is-valid true) + (print (string.format "Turn %d: You chose %s" game.turns move)) + (game:update move))))) ;; game is complete (print "Congratulations!") (print (string.format "Player %d is the winner!" game.player))) |