Files
functional-programming-snake/fsharp/src/Input.fs
T

11 lines
508 B
FSharp

/// m09 input: from keyboard keys to game actions.
module Snake.Input
open Snake.Model
/// Translate a keyboard key name (as in the browser's `KeyboardEvent.key`) into the action it triggers, if any.
/// m09: "ArrowUp"/"w"/"W" -> `Some (Turn Up)`, "ArrowDown"/"s"/"S" -> Down, "ArrowLeft"/"a"/"A" -> Left,
/// "ArrowRight"/"d"/"D" -> Right. Any other key -> `None`.
/// (m10) " " (Space) -> `Some TogglePause`, "r"/"R" -> `Some Restart`.
let keyToAction (key: string) : Action option = failwith "TODO m09"