From 84e7eac292b18d320f445fb7d6af43b4b1afaffe Mon Sep 17 00:00:00 2001 From: Pietro Peterlongo Date: Sun, 26 Nov 2023 22:20:12 +0100 Subject: [PATCH 1/2] ineffective "fix" of width issue --- src/Main.elm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Main.elm b/src/Main.elm index 11bcecf..2999fa7 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -1,4 +1,4 @@ -module Main exposing (..) +module Main exposing (main) import Browser import Element exposing (..) @@ -47,7 +47,7 @@ update msg model = view : Model -> Html Msg view model = layout [ width fill, height fill ] - (column [ width (px 500), height fill, centerX, bgCyan ] + (column [ width (fill |> maximum 500), height fill, centerX, bgCyan ] [ viewHeader , viewGridArea model , viewKeyboardArea @@ -215,7 +215,14 @@ viewTileChar tile = el [ centerX, centerY ] (text (String.fromChar ' ')) FilledTile ftile -> - el [ centerX, centerY, Font.color (tileFontColor ftile.match), Font.size 32, Font.bold ] (text (String.fromChar ftile.char)) + el + [ centerX + , centerY + , Font.color (tileFontColor ftile.match) + , Font.size 32 + , Font.bold + ] + (text (String.fromChar ftile.char)) From 3257980075ef5fe2d174322d7161d6270e07338a Mon Sep 17 00:00:00 2001 From: Pietro Peterlongo Date: Sun, 26 Nov 2023 22:51:55 +0100 Subject: [PATCH 2/2] refactor model and new word and test data --- notes.md | 7 ++++- src/Main.elm | 82 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/notes.md b/notes.md index 3954b98..b5a8ab0 100644 --- a/notes.md +++ b/notes.md @@ -6,4 +6,9 @@ color-words - [x] colors (grid) - [x] background colors - [x] border - - [x] font color (and size) \ No newline at end of file + - [x] font color (and size) + +refactor-word: goal is to refactor word to be able to show complete guess, current guess and empty words +- [x] new Word type +- [x] refactor model (add current) +- [x] new test data for init model \ No newline at end of file diff --git a/src/Main.elm b/src/Main.elm index 2999fa7..85e2772 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -1,5 +1,6 @@ module Main exposing (main) +import Array exposing (Array) import Browser import Element exposing (..) import Element.Background as Background @@ -14,7 +15,8 @@ main = type alias Model = - { guesses : List (List Char) + { guesses : List Word + , current : Word , solution : List Char } @@ -22,10 +24,11 @@ type alias Model = init : Model init = { guesses = - [ [ 'A', 'B', 'C', 'D', 'E' ] - , [ 'A', 'B', 'C' ] + [ testGuess1 + , testGuess2 ] - , solution = [] + , current = testCurrent + , solution = testSolution } @@ -87,10 +90,10 @@ type Match = No --grey | Exact --green | Almost --yellow - | Unmatched + | Unmatched --white -type alias MatchedTile = +type alias Letter = { char : Char , match : Match } @@ -98,7 +101,11 @@ type alias MatchedTile = type Tile = EmptyTile - | FilledTile MatchedTile + | FilledTile Letter + + +type alias Word = + List Tile viewGridArea model = @@ -109,8 +116,8 @@ emptyTile = EmptyTile -defaultWord : List Tile -defaultWord = +testWord : Word +testWord = [ FilledTile { char = 'A', match = No } , FilledTile { char = 'B', match = Exact } , FilledTile { char = 'C', match = Almost } @@ -119,24 +126,59 @@ defaultWord = ] +testGuess1 = + [ FilledTile { char = 'P', match = No } + , FilledTile { char = 'O', match = No } + , FilledTile { char = 'S', match = No } + , FilledTile { char = 'T', match = No } + , FilledTile { char = 'A', match = Exact } + ] + + +testGuess2 = + [ FilledTile { char = 'F', match = Almost } + , FilledTile { char = 'U', match = Exact } + , FilledTile { char = 'R', match = No } + , FilledTile { char = 'B', match = Almost } + , FilledTile { char = 'A', match = Exact } + ] + + +testCurrent = + [ FilledTile { char = 'B', match = Unmatched } + , FilledTile { char = 'U', match = Unmatched } + , FilledTile { char = 'F', match = Unmatched } + ] + + +testSolution = + [ 'B', 'U', 'F', 'F', 'A' ] + + +emptyWord = + List.repeat 5 emptyTile + + +padRightTake n padFill aList = + List.take n (aList ++ List.repeat n padFill) + + +getWords model = + padRightTake + 6 + emptyWord + (model.guesses ++ [ padRightTake 5 EmptyTile model.current ]) + + viewGrid model = column [ centerX, centerY, spacing 5 ] - (List.map viewTileRow - (List.repeat 6 defaultWord) - {-- - (List.take 6 - (model.guesses ++ List.repeat 6 []) - ) --} - ) + (List.map viewTileRow (getWords model)) viewTileRow word = row [ spacing 5 ] (List.map viewTile - (List.take 5 - (word ++ List.repeat 5 emptyTile) - ) + (padRightTake 5 emptyTile word) )