From 0257f5c5f3992fff30d36b09d9ebdb7864e854de Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Mon, 10 Jan 2022 12:56:00 +0100 Subject: [PATCH] [Mosaic] Display Mosaic game grid with table borders (fixes #15) --- .../game/wordle/mosaic/component/alphabet.kt | 4 +++ .../game/wordle/mosaic/component/wordle.kt | 34 ++++++++++++------- .../opatry/game/wordle/mosaic/gameScreen.kt | 2 ++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/alphabet.kt b/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/alphabet.kt index 200b166..dab43a1 100644 --- a/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/alphabet.kt +++ b/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/alphabet.kt @@ -25,6 +25,7 @@ package net.opatry.game.wordle.mosaic.component import androidx.compose.runtime.Composable import com.jakewharton.mosaic.ui.Column import com.jakewharton.mosaic.ui.Row +import com.jakewharton.mosaic.ui.Text import net.opatry.game.wordle.AnswerFlag @Composable @@ -33,9 +34,12 @@ fun Alphabet(alphabet: Map) { alphabet.keys.chunked(9).forEach { row -> Row { row.forEach { letter -> + Text(" ") WordleCharCell(letter, alphabet[letter]!!) + Text(" ") } } + Text(" ") } } } diff --git a/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/wordle.kt b/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/wordle.kt index b8793a5..42710fe 100644 --- a/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/wordle.kt +++ b/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/component/wordle.kt @@ -35,18 +35,29 @@ import net.opatry.game.wordle.AnswerFlag @Composable fun WordleGrid(grid: List) { 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("╰─────┴─────┴─────┴─────┴─────╯") } } @@ -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("") } } diff --git a/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/gameScreen.kt b/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/gameScreen.kt index 1bcf158..0b66023 100644 --- a/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/gameScreen.kt +++ b/wordle-compose-mosaic/src/main/java/net/opatry/game/wordle/mosaic/gameScreen.kt @@ -44,6 +44,8 @@ fun GameScreen(viewModel: WordleViewModel) { Alphabet(viewModel.alphabet) } + Text("") + when (val state = viewModel.state) { is State.Won -> { Text("Wordle ${state.answers.size}/${state.maxTries}")