Getting Started
Useful Commands:
pushd src && elm test && popd
elm reactor
Useful Commands:
pushd src && elm test && popd
elm reactor
\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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.