aboutsummaryrefslogtreecommitdiff
path: root/src/View/Game.elm
blob: ad0e9ea932f867787b8142a8176a91211993f09a (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
module View.Game
  ( gameView
  ) where

import List

import Graphics.Collage (..)
import Graphics.Element (Element)
import Color (..)
import Text (..)
import Text
import Time (Time)

import Model.Vec2 (Vec2)
import Model.Player (..)
import Model.Game (Game)
import Model.Point (..)
import Model.Config (..)
import Model.Round (..)

import View.Round (roundView)

gameView : Game -> Element
gameView game =
  let pointsForm color =
        List.map (pointForm game.time (configColor color)) (game.cloud.points color)
          |> group
      forms =
        [ boardForm game.boardSize
        , playerForm game.player
        , pointsForm White
        , pointsForm Black
        , scoreForm game.boardSize game.time game.rounds game.currentScore
        ]
  in  collage (truncate game.boardSize.x) (truncate game.boardSize.y) forms

boardForm : Vec2 -> Form
boardForm boardSize =
  filled boardColor (rect boardSize.x boardSize.y)

boardColor : Color
boardColor = rgb 103 123 244

playerForm : Player -> Form
playerForm player =
  let playerColor = configColor player.config
  in  circleForm player.pos playerSize playerColor

playerColor : Color
playerColor = rgb 224 224 224

pointForm : Float -> Color -> Point -> Form
pointForm time color point =
  let pos = pointMove point time
  in  circleForm pos pointSize color

configColor : Config -> Color
configColor config =
  case config of
    White -> rgb 240 240 240
    Black -> rgb 14 17 33

circleForm : Vec2 -> Float -> Color -> Form
circleForm pos size color =
  let outline = circle size
        |> filled outlineColor
      inside = circle (size - 1)
        |> filled color
  in  group [outline, inside]
        |> move (pos.x, pos.y)

outlineColor : Color
outlineColor = rgb 34 34 34

scoreForm : Vec2 -> Time -> List Round -> Int -> Form
scoreForm boardSize currentRoundTime rounds score =
  let scorePos =
        { x = 0.0
        , y = boardSize.y / 2 - 35
        }
  in  if currentRoundTime < 5000 && (not (List.isEmpty rounds))
        then
          List.head rounds
            |> roundView
            |> textForm scorePos
        else
          textForm scorePos (toString score)

textForm : Vec2 -> String -> Form
textForm pos content =
  let textElement = fromString content
        |> Text.height 24
        |> typeface ["calibri", "arial"]
        |> Text.color textColor
        |> bold
        |> centered
  in  textElement
        |> toForm
        |> move (pos.x, pos.y)

textColor : Color
textColor = rgb 14 17 33