Files

16 lines
521 B
FSharp

/// m09 input: from keyboard keys to game actions.
module Snake.Input
open Snake.Model
// A match on string literals is the lookup table; `|` lists the alternatives.
let keyToAction (key: string) : Action option =
match key with
| "ArrowUp" | "w" | "W" -> Some(Turn Up)
| "ArrowDown" | "s" | "S" -> Some(Turn Down)
| "ArrowLeft" | "a" | "A" -> Some(Turn Left)
| "ArrowRight" | "d" | "D" -> Some(Turn Right)
| " " -> Some TogglePause // m10
| "r" | "R" -> Some Restart // m10
| _ -> None