-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.elm
63 lines (45 loc) · 1.28 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
56
57
58
59
60
61
62
63
module Main exposing (..)
import Game
import Scoresheet exposing (Scoresheet)
import Task
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Random
import Platform.Sub
type State
= InProgress Game.GameState
| NewGameScreen
| GameOver Int Scoresheet
type Msg
= StartGame Int
| GameEvent Game.Action
| GetSeed
view state =
case state of
NewGameScreen ->
button [ onClick GetSeed ] [ text "Begin" ]
GameOver score scoresheet ->
button [ onClick GetSeed ] [ text "Begin" ]
InProgress gs ->
Html.map GameEvent (Game.view gs)
update msg st =
case msg of
StartGame value ->
( InProgress (Game.initialState value), Cmd.none )
GetSeed ->
( st, Random.generate StartGame (Random.int Random.minInt Random.maxInt) )
GameEvent action ->
case st of
InProgress gamestate ->
( InProgress (Game.update action gamestate), Cmd.none )
other ->
( other, Cmd.none )
subs model =
Sub.none
main =
Html.program
{ init = ( NewGameScreen, Cmd.none )
, view = view
, update = update
, subscriptions = subs
}