Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pushing is hard #1

Open
dgodd opened this issue Aug 15, 2016 · 0 comments
Open

Pushing is hard #1

dgodd opened this issue Aug 15, 2016 · 0 comments

Comments

@dgodd
Copy link

dgodd commented Aug 15, 2016

\diff --git a/the-game-of-set/Card.elm b/the-game-of-set/Card.elm
index 3cbbd5d..f0d7076 100644
--- a/the-game-of-set/Card.elm
+++ b/the-game-of-set/Card.elm
@@ -5,10 +5,14 @@ import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import String exposing (repeat)
+import Random

-init: Model
-init =

  • { shape = Diamond, number = 3, color = Red, selected = False }
    +init: Random.Seed -> (Model, Random.Seed)
    +init seed0 =

  • let

  •  (number, seed1) = Random.step (Random.int 0 3) seed0
    
  • in

  •  ({ shape = Diamond, number = number, color = Red, selected = False }, seed1)
    

    type alias Model = {
    shape: Shape,
    @@ -31,25 +35,29 @@ asciiArt shape =

    -- UPDATE

-type Msg = SelectCard
+type Msg = SelectCard | DeselectCard

update : Msg -> Model -> Model
update msg model =

  • { model | selected = True }

  • case msg of

  •  SelectCard ->
    
  •    { model | selected = True }
    
  •  DeselectCard ->
    
  •    { model | selected = False }
    

    -- VIEW

    view : Model -> Html Msg
    view card =
    div [

  •        onClick SelectCard,
    
  •        onClick (if card.selected then DeselectCard else SelectCard),
         style
                 [   ("color", toString card.color)
                   , ("width", "150px")
                   , ("height", "100px")
                   , ("line-height", "100px")
                   , ("font-size", "50px")
    
  •                  , ("border", "1px solid black")
    
  •                  , ("border", (if card.selected then "5px solid red" else "5px solid black"))
                   , ("display", "inline-block")
                 ]
    
  •    ] [ text ((repeat card.number (asciiArt card.shape)) ++ toString card.selected) ]
    
  •    ] [ text ((repeat card.number (asciiArt card.shape))) ]
    

    diff --git a/the-game-of-set/the-game.elm b/the-game-of-set/the-game.elm
    index ad528fb..de1787e 100644
    --- a/the-game-of-set/the-game.elm
    +++ b/the-game-of-set/the-game.elm
    @@ -4,6 +4,8 @@ import Html.Attributes exposing (..)
    import Html.Events exposing (onClick)
    import String exposing (repeat)
    import Card
    +import Random
    +import List exposing (scanl repeat)

    main =
    Html.beginnerProgram
    @@ -20,9 +22,12 @@ type alias Model =

    init : Model
    init =

  • Model [

  • Card.init, Card.init, Card.init

  • ]

  • let

  • seeds = scanl (\b -> ZZ) (Random.initialSeed 323947) (repeat 4 0)

  • in

  • Model [

  •  Card.init seed0, Card.init seed0, Card.init seed0
    
  • ]

-- UPDATE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant