Created
          March 7, 2016 08:01 
        
      - 
      
- 
        Save A-gambit/a30c27c4494ab0d5e83f to your computer and use it in GitHub Desktop. 
Revisions
- 
        A-gambit created this gist Mar 7, 2016 .There are no files selected for viewingThis file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ module Game where import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) import Signal exposing (Address) import StartApp.Simple as StartApp -- MODEL type alias Model = { row : List Int, cur : Int } initialModel : Model initialModel = { row = [ 0, 0, 0 ], cur = 1 } -- UPDATE type Action = NoOp | Move Int update : Action -> Model -> Model update action model = case action of NoOp -> model Move index -> let updateRow eIndex e = if eIndex == index then model.cur else e next = if model.cur == 1 then 2 else 1 in { model | row = List.indexedMap updateRow model.row, cur = next } -- VIEW view : Address Action -> Model -> Html view address model = div [ id "container" ] [ title, squareList address model.row ] title : Html title = h1 [] [ text "The Game!" ] squareList : Address Action -> List Int -> Html squareList address row = let items = List.indexedMap (item address) row in ul [ ] items item : Address Action -> Int -> Int -> Html item address index val = li [ onClick address (Move index) ] [ text ((toString val) ++ " " ++ (toString index)) ] -- MAIN main : Signal Html main = StartApp.start { model = initialModel, view = view, update = update }