nonogram: draw mistake-revealed blanks apart from player Xs (#ux-audit)
- Commit
c74c1a21cbf1a90dd14b231d102aa7963fdf4df6- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:15 UTC (23 days ago)
- Parents
1dbc16b
Symptom: after a wrong guess cost a heart, the revealed blank cell was drawn exactly like the player's own cross-out note, so a player could not tell their working from the cells their mistakes paid for (or which cells are locked and which can still be cleared). Root cause: NonogramGameState.markAt() folded revealedBlanks into CellMark.CROSSED, so the board and TalkBack had no way to tell them apart. Fix: - New CellMark.REVEALED; markAt() returns it for revealed blanks. - The board paints REVEALED cells with an errorContainer background and a heavier onErrorContainer X (2.5dp vs the note's 1.5dp grey X), so it differs in fill and stroke weight, not only hue. - TalkBack reads "Empty, revealed by a mistake" (new cd_revealed). User-visible effect: mistakes show as tinted cells with a bold X; your own notes stay light grey Xs you can clear. Verification: NonogramGameStateTest asserts REVEALED vs CROSSED and that revealed cells stay locked; Compose test that the board describes a note and a revealed blank differently.
Diff
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.ktindex d5ba571c3b..27f5509e9b 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt@@ -12,12 +12,14 @@ import kotlinx.serialization.Serializable enum class GameMode { CASUAL, DAILY } /**- * What the player has put in a cell.+ * What a cell shows. *- * [CROSSED] is the "definitely blank" mark. It is bookkeeping only — the win check looks at [FILLED]- * alone — but it is how a nonogram is actually solved, so it has to persist alongside the fills.+ * [CROSSED] is the player's own "definitely blank" note. It is bookkeeping only — the win check looks+ * at [FILLED] alone — but it is how a nonogram is actually solved, so it has to persist alongside the+ * fills. [REVEALED] is a blank the game exposed after a wrong guess; it is drawn differently from a+ * note so the player can tell their own working from the cells their mistakes paid for. */-enum class CellMark { BLANK, FILLED, CROSSED }+enum class CellMark { BLANK, FILLED, CROSSED, REVEALED } /** * Which mark a plain tap places.@@ -39,8 +41,8 @@ const val STARTING_HEARTS = 3 * - [crossed] is the player's own note that a cell looks empty. Free to place and to take back, and * never checked against the solution — being wrong in a note is not a guess worth punishing. * - [revealedBlanks] is a cell the game has *told* the player is empty, after a wrong guess cost a- * heart. It draws the same as a cross but cannot be cleared, which is what stops the same cell- * being charged for twice.+ * heart. It draws as a distinct error-coloured cross and cannot be cleared, which is what stops+ * the same cell being charged for twice. * * Storing them as sets rather than per-cell lists keeps the DataStore write small — only the cells * actually touched are persisted.@@ -59,7 +61,8 @@ data class NonogramGameState( fun markAt(index: Int): CellMark = when { index in filled -> CellMark.FILLED- index in crossed || index in revealedBlanks -> CellMark.CROSSED+ index in revealedBlanks -> CellMark.REVEALED+ index in crossed -> CellMark.CROSSED else -> CellMark.BLANK }
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.ktindex 7eb3123820..d1632bd524 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt@@ -198,13 +198,20 @@ private fun NonogramCell( val haptics = LocalHapticFeedback.current val mark = game.markAt(index) - // No mistake colour: a fill only ever lands on a cell that belongs to the picture, because a wrong- // guess is turned into a cross instead.- val background = if (mark == CellMark.FILLED) scheme.onSurface else Color.Transparent+ // A fill only ever lands on a cell that belongs to the picture, because a wrong guess is turned+ // into a revealed blank instead. That revealed blank gets a tinted cell and an error-coloured X so+ // it reads as "the game told you" rather than the player's own grey note: colour plus a filled+ // background, so it does not rely on hue alone.+ val background = when (mark) {+ CellMark.FILLED -> scheme.onSurface+ CellMark.REVEALED -> scheme.errorContainer+ else -> Color.Transparent+ } val stateWord = when (mark) { CellMark.FILLED -> stringResource(R.string.cd_filled) CellMark.CROSSED -> stringResource(R.string.cd_crossed)+ CellMark.REVEALED -> stringResource(R.string.cd_revealed) CellMark.BLANK -> stringResource(R.string.cd_blank) } val description = stringResource(@@ -229,12 +236,16 @@ private fun NonogramCell( .clearAndSetSemantics { contentDescription = description }, contentAlignment = Alignment.Center, ) {- if (mark == CellMark.CROSSED) {+ if (mark == CellMark.CROSSED || mark == CellMark.REVEALED) {+ val revealed = mark == CellMark.REVEALED Box( Modifier .fillMaxSize() .padding(CrossInset)- .drawCross(scheme.onSurfaceVariant)+ .drawCross(+ color = if (revealed) scheme.onErrorContainer else scheme.onSurfaceVariant,+ width = if (revealed) RevealedCrossWidth else NoteCrossWidth,+ ) ) } }@@ -243,8 +254,14 @@ private fun NonogramCell( /** Keeps the X clear of the cell borders so it reads as a mark rather than a filled square. */ private val CrossInset = 3.dp -private fun Modifier.drawCross(color: Color) = drawBehind {- val stroke = 1.5.dp.toPx()+/** The player's own note: a light grey X. */+private val NoteCrossWidth = 1.5.dp++/** A blank a mistake revealed: heavier, so it differs in weight as well as colour. */+private val RevealedCrossWidth = 2.5.dp++private fun Modifier.drawCross(color: Color, width: Dp) = drawBehind {+ val stroke = width.toPx() drawLine(color, Offset(0f, 0f), Offset(size.width, size.height), stroke) drawLine(color, Offset(size.width, 0f), Offset(0f, size.height), stroke) }
games/nonogram/src/main/res/values/strings.xml
diff --git a/games/nonogram/src/main/res/values/strings.xml b/games/nonogram/src/main/res/values/strings.xmlindex fc033fbb43..5ab2d4d0d4 100644--- a/games/nonogram/src/main/res/values/strings.xml+++ b/games/nonogram/src/main/res/values/strings.xml@@ -39,6 +39,8 @@ <string name="cd_filled">Filled</string> <!-- NonogramBoard: Cell state, ruled out by the player. Verb past participle --> <string name="cd_crossed">Crossed out</string>+ <!-- NonogramBoard: Cell state, shown empty by the game after a wrong guess cost a heart. Adjective phrase -->+ <string name="cd_revealed">Empty, revealed by a mistake</string> <!-- NonogramBoard: Cell state, untouched. Adjective --> <string name="cd_blank">Blank</string> </resources>
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/data/NonogramGameStateTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/data/NonogramGameStateTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/data/NonogramGameStateTest.ktindex 0c450e3898..77a45b144d 100644--- a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/data/NonogramGameStateTest.kt+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/data/NonogramGameStateTest.kt@@ -87,9 +87,9 @@ class NonogramGameStateTest { } @Test- fun aRevealedBlankDrawsAsACrossButIsLocked() {+ fun aRevealedBlankIsDistinctFromANoteAndLocked() { val s = state(revealedBlanks = setOf(blankCell))- assertEquals(CellMark.CROSSED, s.markAt(blankCell))+ assertEquals(CellMark.REVEALED, s.markAt(blankCell), "a mistake must not look like the player's own X") assertTrue(s.isLocked(blankCell), "a cell the game revealed cannot be charged for twice") }
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.ktindex a8adb6abac..d9f9dffa5e 100644--- a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt@@ -137,6 +137,12 @@ class NonogramScreensTest { assertEquals(listOf(2), taps) } + @Test fun boardTellsARevealedBlankApartFromANote() {+ rule.setContent { NonogramBoard(game = game(crossed = setOf(0), revealed = setOf(2)), onTap = {}, onLongPress = {}) }+ rule.onNodeWithContentDescription(str(R.string.cd_cell, 1, 1, str(R.string.cd_crossed))).assertExists()+ rule.onNodeWithContentDescription(str(R.string.cd_cell, 1, 3, str(R.string.cd_revealed))).assertExists()+ }+ @Test fun boardLongPressFiresCross() { val crosses = mutableListOf<Int>() rule.setContent { NonogramBoard(game = game(), onTap = {}, onLongPress = { crosses += it }) }