-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathController.fs
29 lines (26 loc) · 963 Bytes
/
Controller.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Controller
open Model
open GameCore
open Microsoft.Xna.Framework.Input
let keyMap =
function
| Keys.Left -> Some Command.Left
| Keys.Right -> Some Command.Right
| Keys.Up -> Some Command.Rotate
| _ -> None
let initModel elapsed =
Some { startModel with lastDropTime = elapsed; lastCommandTime = elapsed }
let advanceGame (runState: RunState) gameModel =
match gameModel with
| None ->
initModel runState.elapsed
| Some _ when runState.WasJustPressed Keys.Escape ->
None
| Some m when m.isGameOver && runState.WasJustPressed Keys.R ->
initModel runState.elapsed
| Some m when m.isGameOver ->
Some { m with events = [] }
| Some m ->
let command = List.map keyMap runState.keyboard.pressed |> List.tryPick id
let isDropPressed = List.contains Keys.Down runState.keyboard.pressed
Model.advanceGame runState.elapsed command isDropPressed m |> Some