Last active
May 19, 2016 21:28
-
-
Save vitaly-pushkar/7de8c42df37abbd8a6c04a364858fa40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (..) | |
import Html.App as Html | |
import Html.Events exposing (..) | |
import Html.Attributes exposing (src) | |
import Random | |
main = | |
Html.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
-- MODEL | |
type alias Model = | |
{ dieFace1 : Int | |
, dieFace2 : Int | |
} | |
init : (Model, Cmd Msg) | |
init = | |
(Model 1 1, Cmd.none) | |
-- UPDATE | |
type Msg | |
= Roll | |
| NewFace (Int, Int) | |
update : Msg -> Model -> (Model, Cmd Msg) | |
update msg model = | |
case msg of | |
Roll -> | |
(model, Random.generate NewFace (Random.pair (Random.int 1 6) (Random.int 1 6))) | |
NewFace (newFace1, newFace2) -> | |
(Model newFace1 newFace2, Cmd.none) | |
-- SUBSCRIPTIONS | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ img [src ((toString model.dieFace1) ++ ".png")] [], | |
img [src ((toString model.dieFace2) ++ ".png")] [] | |
, button [ onClick Roll ] [ text "Roll" ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment