Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit c6d0665

Browse files
committed
Allow a player to restart the game after they've finished
https://trello.com/c/aQ7qkMRa/20-play-again-button
1 parent 3a4b30e commit c6d0665

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/elm/I18n.elm

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Translation
4444
| WithdrawCashButton
4545
| ReturnToGameButton
4646
| SeePriceRangesButton
47+
| RestartGameButton
4748

4849

4950
translate : Language -> Translation -> String
@@ -208,6 +209,9 @@ translate language trans =
208209

209210
ReturnToGameButton ->
210211
TranslationSet "Return to game" "Return to game"
212+
213+
RestartGameButton ->
214+
TranslationSet "Play again?" "Play again?"
211215
in
212216
case language of
213217
DrugWars ->

src/elm/Main.elm

+8-3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type Msg
111111
| BorrowMax
112112
| SeePrices
113113
| ReturnToGame
114+
| RestartGame
114115

115116

116117
update : Msg -> Model -> ( Model, Cmd Msg )
@@ -152,6 +153,9 @@ update msg model =
152153
ReturnToGame ->
153154
( { model | gameState = Running }, Cmd.none )
154155

156+
RestartGame ->
157+
initialModelAndEffects
158+
155159

156160
applyPricesAndEvents : Prices -> Event -> Model -> Model
157161
applyPricesAndEvents prices event model =
@@ -439,10 +443,11 @@ displayLenderOptions location =
439443
div [] []
440444

441445

442-
displayScore : Model -> Html a
446+
displayScore : Model -> Html Msg
443447
displayScore model =
444-
div []
445-
[ text <| "Your score: " ++ (toString <| calculateScore model)
448+
div [ class "score" ]
449+
[ p [] [ text <| "Your score: " ++ (toString <| calculateScore model) ]
450+
, button [ onClick RestartGame ] [ text <| translate gameStyle RestartGameButton ]
446451
]
447452

448453

src/static/styles/main.scss

+4
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@ body {
7575
max-width: 45em;
7676
margin: 0 auto;
7777
}
78+
79+
.score {
80+
text-align: center;
81+
}
7882
}

0 commit comments

Comments
 (0)