Commit 87386e8b authored by Joris Guyonvarch's avatar Joris Guyonvarch

Showing the score at the end of each round

parent 97e494a7
module Model.Round
( Round
, roundOrder
, maybeBestRound
) where
import List
import Time (Time)
type alias Round =
......@@ -10,6 +11,16 @@ type alias Round =
, score : Int
}
maybeBestRound : List Round -> Maybe Round
maybeBestRound rounds =
let orderedRounds =
rounds
|> List.sortWith roundOrder
|> List.reverse
in case orderedRounds of
[] -> Nothing
best :: _ -> Just best
roundOrder : Round -> Round -> Order
roundOrder round1 round2 =
if round1.score == round2.score
......
......@@ -31,7 +31,7 @@ update input game =
| time <- 0
, currentScore <- 0
, cloud <- initCloud
, rounds <- (Round game.time game.currentScore) :: game.rounds
, rounds <- game.rounds `List.append` [Round game.time game.currentScore]
}
else
let newTime = game.time + input.delta
......
......@@ -69,7 +69,7 @@ outlineColor = rgb 34 34 34
scoreForms : Int -> List Form
scoreForms score =
let text = (toString score)
scorePos = { x = 0.0, y = boardSize.y / 2 - 30 }
scorePos = { x = 0.0, y = boardSize.y / 2 - 35 }
in [textForm text scorePos centered]
textForm : String -> Vec2 -> (Text -> Element) -> Form
......
......@@ -3,6 +3,7 @@ module View.Page
) where
import List
import String (append)
import Html (..)
import Html.Attributes (..)
......@@ -10,7 +11,7 @@ import Html.Attributes as A
import Json.Encode (string)
import Model.Game (Game)
import Model.Round (roundOrder)
import Model.Round (..)
import View.Game (gameView)
import View.Time (timeView)
......@@ -29,18 +30,23 @@ pageView game =
, p
[]
[ text "Use the arrow keys to move and 'e' to change your color." ]
, ( let orderedRounds =
game.rounds
|> List.sortWith roundOrder
|> List.reverse
in case orderedRounds of
[] ->
div [ class "bestScore" ] []
bestRound :: _ ->
p
[ class "bestScore isDefined" ]
[ text <| "Best score: " ++ (toString bestRound.score) ++ " hits within " ++ (timeView bestRound.duration) ]
, ( case maybeBestRound game.rounds of
Nothing ->
div [ class "bestScore" ] []
Just bestRound ->
p
[ class "bestScore isDefined" ]
[ roundView bestRound
|> append "Best score: "
|> text
]
)
, ul
[ class "rounds" ]
( List.map
(\round -> li [] [ text (roundView round) ])
game.rounds
)
, a
[ href "https://github.com/guyonvarch/catchvoid" ]
[ img
......@@ -58,3 +64,9 @@ pageView game =
]
]
roundView : Round -> String
roundView round =
let score = toString round.score
hits = "hit" ++ (if round.score > 1 then "s" else "")
duration = timeView round.duration
in score ++ " " ++ hits ++ " within " ++ duration
......@@ -67,3 +67,54 @@ p {
color: white;
}
}
ul.rounds {
padding-left: 0;
color: white;
list-style-type: none;
position: absolute;
width: 300px;
left: 50%;
margin-left: -150px;
top: 110px;
}
ul.rounds > li {
background-color: #333333;
text-align: center;
border-radius: 2px;
animation: hide 5s ease;
opacity: 0;
height: 0px;
line-height: 0px;
margin-bottom: 0px;
}
@keyframes hide {
0% {
opacity: 1;
height: 40px;
line-height: 40px;
margin-bottom: 10px;
}
90% {
opacity: 1;
height: 40px;
line-height: 40px;
margin-bottom: 10px;
}
95% {
opacity: 0;
height: 40px;
line-height: 40px;
margin-bottom: 10px;
}
100% {
opacity: 0;
height: 0px;
line-height: 0px;
margin-bottom: 0px;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment