-
Notifications
You must be signed in to change notification settings - Fork 6
/
TicTacToe.elm
44 lines (24 loc) · 1012 Bytes
/
TicTacToe.elm
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module TicTacToe where
import Graphics.Element exposing (Element)
import Mouse
import Signal exposing ((<~), Signal, foldp, mergeMany, sampleOn)
import TicTacToeModel exposing (..)
import TicTacToeView exposing (..)
clickSignal : Signal (Int,Int)
clickSignal = sampleOn Mouse.clicks Mouse.position
newGameButtonSignal : Signal ()
newGameButtonSignal = newGameMailbox.signal
undoButtonSignal : Signal ()
undoButtonSignal = undoMailbox.signal
newGameSignal : Signal (GameState -> GameState)
newGameSignal = always (always initialState) <~ newGameButtonSignal
undoSignal : Signal (GameState -> GameState)
undoSignal = always undoMoves <~ undoButtonSignal
moveSignal : Signal (GameState -> GameState)
moveSignal = processClick <~ clickSignal
inputSignal : Signal (GameState -> GameState)
inputSignal = mergeMany [ moveSignal, newGameSignal, undoSignal ]
gameStateSignal : Signal GameState
gameStateSignal = foldp (<|) initialState inputSignal
main : Signal Element
main = view <~ gameStateSignal