Skip to content

Commit

Permalink
[Mosaic] Display Mosaic game grid with table borders (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
opatry committed Jan 13, 2022
1 parent 53c10a6 commit 54efa18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package net.opatry.game.wordle.mosaic.component
import androidx.compose.runtime.Composable
import com.jakewharton.mosaic.Column
import com.jakewharton.mosaic.Row
import com.jakewharton.mosaic.Text
import net.opatry.game.wordle.AnswerFlag

@Composable
Expand All @@ -33,9 +34,12 @@ fun Alphabet(alphabet: Map<Char, AnswerFlag>) {
alphabet.keys.chunked(9).forEach { row ->
Row {
row.forEach { letter ->
Text(" ")
WordleCharCell(letter, alphabet[letter]!!)
Text(" ")
}
}
Text(" ")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,29 @@ import net.opatry.game.wordle.AnswerFlag
@Composable
fun WordleGrid(grid: List<Answer>) {
Column {
grid.forEach { row ->
WordleWordRow(row)
}
}
}
// Box drawing: https://en.wikipedia.org/wiki/Box-drawing_character#Box_Drawing
// FIXME dividers length depends on max of row.letters
// good enough for now given that we know it's a 5x6 grid
Text("╭─────┬─────┬─────┬─────┬─────╮")
grid.forEachIndexed { rowIndex, row ->
if (rowIndex > 0) {
Text("├─────┼─────┼─────┼─────┼─────┤")
}
Row {
row.letters.forEachIndexed { cellIndex, char ->
if (cellIndex == 0)
Text("")
else
Text("")

@Composable
fun WordleWordRow(row: Answer) {
Row {
row.letters.forEachIndexed { index, char ->
WordleCharCell(char, row.flags[index])
WordleCharCell(char, row.flags[cellIndex])

if (cellIndex == row.letters.size - 1)
Text("")
}
}
}
Text("╰─────┴─────┴─────┴─────┴─────╯")
}
}

Expand All @@ -68,15 +79,12 @@ fun WordleCharCell(char: Char, flag: AnswerFlag) {
// TODO AnnotatedString " $char " https://github.com/JakeWharton/mosaic/issues/9
Column {
Row {
Text(" ")
Text(
" $char ",
color = foregroundColor,
background = backgroundColor,
style = TextStyle.Bold
)
Text(" ")
}
Text("")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ fun GameScreen(viewModel: WordleViewModel) {
Alphabet(viewModel.alphabet)
}

Text("")

when (val state = viewModel.state) {
is State.Won -> {
Text("Wordle ${state.wordleId} ${state.answers.size}/${state.maxTries}")
Expand Down

0 comments on commit 54efa18

Please sign in to comment.