Commit 97e494a7 authored by Joris Guyonvarch's avatar Joris Guyonvarch

Save round durations

parent 6c1f5e10
......@@ -10,6 +10,7 @@ import Model.Player (..)
import Model.Cloud (..)
import Model.Vec2 (Vec2)
import Model.Config (..)
import Model.Round (Round)
type alias Game =
{ time : Float
......@@ -17,7 +18,7 @@ type alias Game =
, currentScore : Int
, player : Player
, cloud : Cloud
, scores : List Int
, rounds : List Round
, seed : Seed
}
......@@ -28,6 +29,6 @@ initialGame seed =
, currentScore = 0
, player = initPlayer
, cloud = initCloud
, scores = []
, rounds = []
, seed = seed
}
module Model.Round
( Round
, roundOrder
) where
import Time (Time)
type alias Round =
{ duration : Time
, score : Int
}
roundOrder : Round -> Round -> Order
roundOrder round1 round2 =
if round1.score == round2.score
then
compare round2.duration round1.duration
else
compare round1.score round2.score
......@@ -13,6 +13,7 @@ import Model.Vec2 (..)
import Model.Config (otherConfig)
import Model.Cloud (..)
import Model.Game (..)
import Model.Round (Round)
import Utils.Geometry (..)
import Utils.Physics (getNewPosAndSpeed)
......@@ -30,7 +31,7 @@ update input game =
| time <- 0
, currentScore <- 0
, cloud <- initCloud
, scores <- game.currentScore :: game.scores
, rounds <- (Round game.time game.currentScore) :: game.rounds
}
else
let newTime = game.time + input.delta
......
......@@ -10,8 +10,10 @@ import Html.Attributes as A
import Json.Encode (string)
import Model.Game (Game)
import Model.Round (roundOrder)
import View.Game (gameView)
import View.Time (timeView)
pageView : Game -> Html
pageView game =
......@@ -27,14 +29,17 @@ pageView game =
, p
[]
[ text "Use the arrow keys to move and 'e' to change your color." ]
, ( if List.isEmpty game.scores
then
div [ class "bestScore" ] []
else
let bestScore = List.maximum game.scores
in p
[ class "bestScore isDefined" ]
[ text <| "Best score: " ++ (toString bestScore) ]
, ( 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) ]
)
, a
[ href "https://github.com/guyonvarch/catchvoid" ]
......
module View.Time
( timeView
) where
import Time (Time)
timeView : Time -> String
timeView time =
let s = truncate (time / 1000)
in (toString s) ++ " seconds"
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