Created
October 19, 2016 00:35
-
-
Save JoseGonzalez321/b5bd36d22243d91d935cd95089a8f1dc 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 App | |
import Html.Events exposing (..) | |
-- MODEL | |
type alias Model = | |
{ xCoord: Int | |
, yCoord: Int | |
} | |
init : Model | |
init = | |
{ xCoord = 0 | |
, yCoord = 0 | |
} | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div[] | |
[ | |
div [] [ text ("X Coordinate: " ++ (toString model.xCoord)) ] | |
, div [] [ text ("Y Coordinate: " ++ (toString model.yCoord)) ] | |
, button [ onClick Up ] [ text "Up" ] | |
, button [ onClick Down ] [ text "Down" ] | |
, button [ onClick Left ] [ text "Left" ] | |
, button [ onClick Right ] [ text "Right" ] | |
] | |
-- UPDATE | |
type Msg | |
= Up | |
| Down | |
| Left | |
| Right | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Up -> | |
{ model | yCoord = model.yCoord + 1 } | |
Down -> | |
{ model | yCoord = model.yCoord - 1 } | |
Left -> | |
{ model | xCoord = model.xCoord - 1 } | |
Right -> | |
{ model | xCoord = model.xCoord + 1 } | |
main : Program Never | |
main = | |
App.beginnerProgram | |
{ model = init | |
, view = view | |
, update = update | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment