-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.elm
47 lines (36 loc) · 1.37 KB
/
View.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
module View where
import Model exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import List
import Css.Transform2 exposing (..)
import Css.Position exposing (..)
view : Game -> Html
view {moles, score} = div [] <|
h1 [] [ text <| "Score: " ++ toString score ] :: renderMoles moles
grid : Int
grid = 300
scaleGrid : Float -> Int
scaleGrid x = round <| toFloat grid * x
renderMole : Hole -> Mole -> Html
renderMole hole mole = let
wackableUrl = "http://www.fcps.edu/islandcreekes/ecology/Mammals/Eastern%20Mole/eastern1.jpg"
unWackableUrl = "http://cloud.graphicleftovers.com/20677/464110/mole-hole-in-brown-dirt-closeup.-shallow-dof.jpg"
moleSize = round <| toFloat grid / 1.618
img' url = img[ src url, onClick messages.address (Wack hole), width moleSize, height moleSize ] []
in img' <|
if mole.wackable
then wackableUrl
else unWackableUrl
styleHole : Hole -> Attribute
styleHole h =
(\(x, y) -> style << position Absolute <| transform2 [translate2 x y] [])
<| case h of
UL -> (0, 0)
UM -> (grid, 0)
UR -> (grid * 2, 0)
LL -> (scaleGrid 0.5, grid)
LR -> (scaleGrid 1.5, grid)
renderMoles : List (Hole, Mole) -> List Html
renderMoles hms = List.map (\(h, m) -> Html.div [styleHole h] [renderMole h m]) hms