Skip to content

Commit

Permalink
refactor model and new word and test data
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroppeter committed Nov 26, 2023
1 parent 84e7eac commit 3257980
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 21 deletions.
7 changes: 6 additions & 1 deletion notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ color-words
- [x] colors (grid)
- [x] background colors
- [x] border
- [x] font color (and size)
- [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
82 changes: 62 additions & 20 deletions src/Main.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Main exposing (main)

import Array exposing (Array)
import Browser
import Element exposing (..)
import Element.Background as Background
Expand All @@ -14,18 +15,20 @@ main =


type alias Model =
{ guesses : List (List Char)
{ guesses : List Word
, current : Word
, solution : List Char
}


init : Model
init =
{ guesses =
[ [ 'A', 'B', 'C', 'D', 'E' ]
, [ 'A', 'B', 'C' ]
[ testGuess1
, testGuess2
]
, solution = []
, current = testCurrent
, solution = testSolution
}


Expand Down Expand Up @@ -87,18 +90,22 @@ type Match
= No --grey
| Exact --green
| Almost --yellow
| Unmatched
| Unmatched --white


type alias MatchedTile =
type alias Letter =
{ char : Char
, match : Match
}


type Tile
= EmptyTile
| FilledTile MatchedTile
| FilledTile Letter


type alias Word =
List Tile


viewGridArea model =
Expand All @@ -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 }
Expand All @@ -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)
)


Expand Down

0 comments on commit 3257980

Please sign in to comment.