minesweeper: cross out wrong flags when the game is lost (#ux-audit)
- Commit
4a223055e179c097e6c0dc16046ae7edbfcbe9d2- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:22 UTC (23 days ago)
- Parents
8339163
Symptom: after stepping on a mine, the opened-up field showed every mine, but a flag the player had placed on a safe cell looked exactly like a correct flag. The player could not see which of their deductions had been wrong - the main thing a loss screen should teach. Root cause: MineCell drew any flag that was not on a shown mine with the same IconFlag in every outcome; nothing checked flag vs mine on a loss. TalkBack likewise said only "Flagged". Fix: on a LOST field, a flagged cell without a mine draws a dimmed flag with an "x" (library IconClear, no new icon needed) across it, the classic Minesweeper "false flag" marker, and is announced as "Wrong flag, no mine" (new string). During play and on a win nothing changes - wrong flags are never revealed before the game is over. User-visible effect: on the loss screen, incorrect flags are visibly crossed out (and announced); correctly flagged mines show as mines, as before. Verification: new MinesweeperBoardTest cases: on a lost 3x3 field the wrong corner flag is described as a wrong flag and the flagged mine as a mine; during play the same flag is still just "Flagged". :games:minesweeper:testDevUnitTest in the toolchain container.
Diff
games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.ktindex 11a405136a..2c91368231 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt@@ -35,6 +35,7 @@ import androidx.compose.ui.unit.sp import com.vayunmathur.games.minesweeper.R import com.vayunmathur.games.minesweeper.data.GameOutcome import com.vayunmathur.games.minesweeper.data.MinesweeperGameState+import com.vayunmathur.library.ui.IconClear import com.vayunmathur.library.ui.IconFlag import com.vayunmathur.library.ui.IconMine import com.vayunmathur.library.ui.MaterialTheme@@ -110,6 +111,9 @@ private fun MineCell( // up; on a win the mines are shown as the flags the player earned rather than as bare mines. val showMine = isMine && (revealed || lost) val showFlag = flagged && !showMine+ // On a loss the field is opened up, so a flag on a safe cell is now known to be wrong: crossed+ // out, as in classic Minesweeper, so the player can see which deductions failed.+ val wrongFlag = showFlag && lost && !isMine val background = when { index == game.explodedAt -> scheme.error@@ -124,6 +128,7 @@ private fun MineCell( ) val stateWord = when { showMine -> stringResource(R.string.cd_mine)+ wrongFlag -> stringResource(R.string.cd_wrong_flag) showFlag -> stringResource(R.string.cd_flagged) !revealed -> stringResource(R.string.cd_covered) count == 0 -> stringResource(R.string.cd_empty)@@ -165,6 +170,11 @@ private fun MineCell( tint = if (index == game.explodedAt) scheme.onError else scheme.onSurfaceVariant, ) + wrongFlag -> Box(Modifier.fillMaxSize(0.65f), contentAlignment = Alignment.Center) {+ IconFlag(Modifier.fillMaxSize(), tint = scheme.error.copy(alpha = WRONG_FLAG_ALPHA))+ IconClear(Modifier.fillMaxSize(), tint = scheme.onSurface, contentDescription = null)+ }+ showFlag -> IconFlag(Modifier.fillMaxSize(0.65f), tint = scheme.error) revealed && count > 0 -> Text(@@ -183,6 +193,9 @@ private fun MineCell( /** Gap between cells, so the field reads as a grid without needing drawn lines. */ private val CellGap = 1.dp +/** A disproved flag is dimmed under its cross, so the cross reads first. */+private const val WRONG_FLAG_ALPHA = 0.45f+ /** Luminance below which the revealed-cell background counts as dark. */ private const val HALF = 0.5f
games/minesweeper/src/main/res/values/strings.xml
diff --git a/games/minesweeper/src/main/res/values/strings.xml b/games/minesweeper/src/main/res/values/strings.xmlindex 7fb29f4f44..1cdb223312 100644--- a/games/minesweeper/src/main/res/values/strings.xml+++ b/games/minesweeper/src/main/res/values/strings.xml@@ -54,6 +54,8 @@ <string name="cd_covered">Covered</string> <!-- GameBoardScreen: Content description of a flagged cell. Verb past participle --> <string name="cd_flagged">Flagged</string>+ <!-- GameBoardScreen: Content description, after a loss, of a flag the player put on a cell with no mine. Noun phrase -->+ <string name="cd_wrong_flag">Wrong flag, no mine</string> <!-- GameBoardScreen: Content description of a revealed mine. Noun --> <string name="cd_mine">Mine</string> <!-- GameBoardScreen: Content description of an open cell touching no mines. Adjective -->
games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt
diff --git a/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt b/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.ktindex 59ee8ce20a..b31b342121 100644--- a/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt+++ b/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt@@ -137,6 +137,31 @@ class MinesweeperBoardTest { assertTrue(digit.bottom - digit.top <= cell.bottom - cell.top, "count fits its cell: $digit in $cell") } + @Test+ fun lossMarksWrongFlagsButNotCorrectOnes() {+ // Flag on the centre mine (right) and on corner 0 (wrong), then the game is lost.+ val flagged = List(9) { it == 4 || it == 0 }+ composeRule.setContent {+ MineFieldGrid(+ field(flagged = flagged, outcome = GameOutcome.LOST),+ onTap = {},+ onLongPress = { false },+ )+ }+ composeRule.onNodeWithContentDescription("Row 1, column 1, ${str(R.string.cd_wrong_flag)}")+ .assertExists()+ composeRule.onNodeWithContentDescription("Row 2, column 2, ${str(R.string.cd_mine)}")+ .assertExists()+ }++ @Test+ fun wrongFlagsAreNotRevealedDuringPlay() {+ val flagged = List(9) { it == 0 }+ composeRule.setContent { MineFieldGrid(field(flagged = flagged), onTap = {}, onLongPress = { false }) }+ composeRule.onNodeWithContentDescription("Row 1, column 1, ${str(R.string.cd_flagged)}")+ .assertExists()+ }+ @Test fun gridRevealedNumberAndFlagDescriptions() { val revealed = List(9) { it == 0 }