feat(scala): m09 input/app/runtime and m10 extensions with tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas Winther
2026-10-29 00:13:52 +01:00
co-authored by Claude Opus 5.5
parent bd0c9fcc0c
commit c6ecb7c013
13 changed files with 448 additions and 6 deletions
+14
View File
@@ -0,0 +1,14 @@
package snake
/** m09 input: from keyboard keys to game actions. */
object Input:
// A pattern match on string literals is the lookup table; `|` lists the alternatives.
def keyToAction(key: String): Option[Action] = key match
case "ArrowUp" | "w" | "W" => Some(Action.Turn(Direction.Up))
case "ArrowDown" | "s" | "S" => Some(Action.Turn(Direction.Down))
case "ArrowLeft" | "a" | "A" => Some(Action.Turn(Direction.Left))
case "ArrowRight" | "d" | "D" => Some(Action.Turn(Direction.Right))
case " " => Some(Action.TogglePause) // m10
case "r" | "R" => Some(Action.Restart) // m10
case _ => None