-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGame.elm
66 lines (53 loc) · 1.61 KB
/
Game.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- TODO
-- Restrict the actions of players (for some of the rules)
-- Design note:
-- Referencing specific card is done using array index.
-- This is vulnarable if multiple simultaneous actions occur.
-- TODO reference cards by their identity.
-- Design note:
-- Code (actions, etc) could be split hierarchically so that code consists of components:
-- a component itself would be similar to a small Elm program with update, view and model functions
module Game exposing (..)
import Array exposing (empty)
import Browser
import Domain exposing (Model, startGameWithPlayers)
import Html
import Random exposing (initialSeed)
import Time
import UI as Msg exposing (Msg)
import Update exposing (update)
import View as GameView
initialModel : Model
initialModel =
let
( deck, players ) =
startGameWithPlayers shuffledDeck [ "Pasi", "Anssi", "Henkka" ]
( shuffledDeck, seed ) =
initDeck
in
{ startTime = Nothing
, currentTime = Time.millisToPosix 0
, players = players
, deck = deck
, discard = Array.empty
}
initDeck =
let
seedValue =
1525
-- TODO get seed from mousemovements&time
shuffledDeckGenerator =
Domain.shuffleDeck Domain.allCards
in
Random.step shuffledDeckGenerator (initialSeed seedValue)
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every 1000 Msg.GetTime
main : Program () Model Msg
main =
Browser.document
{ init = \_ -> ( initialModel, Cmd.none )
, view = GameView.view
, update = Update.update
, subscriptions = subscriptions
}