Skip to content

Commit

Permalink
feat: basic game termination (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
akiross authored Apr 20, 2024
1 parent 8a362d8 commit ec179bb
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,48 @@ decodeKey str =
--- VIEW


isGameEnded model =
-- All guesses or a guess is all green
isGameWon model || (List.length model.guesses == 6)


isGuessCorrect : List MatchedChar -> Bool
isGuessCorrect guess =
let
isMatchExact m =
case m of
Exact _ ->
True

_ ->
False
in
List.all isMatchExact guess


isGameWon model =
-- One guess is all green
List.any isGuessCorrect model.guesses


view : Model -> Html Msg
view model =
layout [ width fill, height fill ]
(column [ width (fill |> maximum 500), height fill, centerX, bgCyan ]
[ viewHeader
, viewGridArea model
, viewKeyboardArea model
]
)
if isGameEnded model then
layout [ width fill, height fill ]
(column [ width (fill |> maximum 500), height fill, centerX, bgCyan ]
[ viewHeader
, viewEndGame model
]
)

else
layout [ width fill, height fill ]
(column [ width (fill |> maximum 500), height fill, centerX, bgCyan ]
[ viewHeader
, viewGridArea model
, viewKeyboardArea model
]
)


viewHeader =
Expand Down Expand Up @@ -520,6 +553,19 @@ viewKeyboardRow model keys =



-- Show pop-up


viewEndGame : Model -> Element Msg
viewEndGame model =
if isGameWon model then
el [ centerX, centerY ] (text "You won!")

else
el [ centerX, centerY ] (text "You lose!")



--- COLORS


Expand Down

0 comments on commit ec179bb

Please sign in to comment.