-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.elm
55 lines (45 loc) · 1.69 KB
/
Main.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
45
46
47
48
49
50
51
52
53
54
55
module Main exposing (..)
import Model exposing (Model, initialModel, GameState(..))
import View exposing (view)
import Msg exposing (Msg)
import Html
import Player exposing (..)
import Board exposing (Board)
init : ( Model, Cmd Msg )
init =
( initialModel, Cmd.none )
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case model.gameState of
Won player ->
( model, Cmd.none )
Playing ->
case msg of
Msg.Play column ->
case Board.move model.board column model.currentPlayer of
Board.OutOfBoardError ->
( model, Cmd.none )
Board.Ok newBoard lastPosition ->
case Board.winPlay newBoard ( lastPosition, model.currentPlayer ) of
True ->
( { model
| board = newBoard
, gameState = Won model.currentPlayer
}
, Cmd.none
)
False ->
( { model
| board = newBoard
, currentPlayer = Player.otherPlayer model.currentPlayer
}
, Cmd.none
)
main : Program Never Model Msg
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = (\_ -> Sub.none)
}