Classic Challenges (0.113.0, versionCode 303): Blast Off's twenty hand-made challenges; Skydoku, Block Drop, Patience and Pairs modes complete

- Blast Off: twenty numbered boards with line targets and shape limits, same shapes each try, all beaten by a test bot
- Mode button shows the whole mode name; title buttons 230 dp, Play Again 180 dp
- Every mode its own High Scores table; Classic tables, kinds and Household keys unchanged

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 09:50:02 +00:00
co-authored by Claude Opus 5.5
parent 85c5e08803
commit 9cd43b1e40
10 changed files with 256 additions and 25 deletions
@@ -15,6 +15,7 @@ import tv.orbit.classic.arcade.HudValue
import tv.orbit.classic.arcade.Mascot
import tv.orbit.classic.arcade.gameKeys
import tv.orbit.classic.arcade.previousLine
import tv.orbit.classic.arcade.BLAST_CHALLENGE_SCORES
import tv.orbit.classic.arcade.ArcadePlay
import tv.orbit.classic.arcade.PauseWhenHidden
@@ -199,6 +200,12 @@ internal fun BlastOffScreen(play: ArcadePlay) {
var paused by remember { mutableStateOf(false) }
var howTo by remember { mutableStateOf(false) }
var bestBefore by remember { mutableIntStateOf(play.best) }
// Classic, or the twenty numbered Challenges (Phase 2): chosen on the title and remembered.
var challenge by remember { mutableStateOf(play.level["mode"] == "Challenge") }
var cleared by remember { mutableIntStateOf(play.level["challenge.cleared"]?.toIntOrNull() ?: 0) }
var crun by remember { mutableStateOf<BlastRun?>(null) }
var crandom by remember { mutableStateOf(java.util.Random(1)) }
var picked by remember { mutableIntStateOf(1) }
val focus = remember { FocusRequester() }
val backdrop = ArcadeLook.forGame(gameDef.id)
// Holding OK places one shape, not one after another (audit finding 8).
@@ -206,9 +213,25 @@ internal fun BlastOffScreen(play: ArcadePlay) {
fun pause() { paused = true; guard.reset() }
PauseWhenHidden(stage == ClassicStage.Play && !paused) { pause() }
val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false) }
fun startRun() { bestBefore = latestPlay.best; game = BlastGame.start(random); guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play }
fun leave() { run.end(RunEnd(game.score, finished = !game.alive)); latestPlay.onLeave() }
LaunchedEffect(game.alive) { if (!game.alive && stage == ClassicStage.Play) { run.end(RunEnd(game.score, finished = true)); stage = ClassicStage.Result } }
fun startRun() { crun = null; bestBefore = latestPlay.best; game = BlastGame.start(random); guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play }
fun startChallenge(n: Int) {
val c = BlastChallenges[(n - 1).coerceIn(0, BlastChallenges.size - 1)]
val (r, rnd) = BlastRun.start(c)
picked = c.number; crun = r; crandom = rnd; game = r.game; guard.reset(); paused = false; stage = ClassicStage.Play
}
fun leave() { if (crun == null) run.end(RunEnd(game.score, finished = !game.alive)); latestPlay.onLeave() }
LaunchedEffect(game.alive) { if (crun == null && !game.alive && stage == ClassicStage.Play) { run.end(RunEnd(game.score, finished = true)); stage = ClassicStage.Result } }
// A challenge is over when its target is reached, or there are no shapes or no room left. Clearing one saves how far you've got.
LaunchedEffect(crun?.over) {
val r = crun ?: return@LaunchedEffect
if (!r.over || stage != ClassicStage.Play) return@LaunchedEffect
if (r.won && r.challenge.number > cleared) {
cleared = r.challenge.number
latestPlay.setLevel("challenge.cleared", cleared.toString())
latestPlay.onRunEndIn(BLAST_CHALLENGE_SCORES, RunEnd(cleared, finished = true, detail = r.challenge.name))
}
stage = ClassicStage.Result
}
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
// Zip zooms past on a combo; the flight stops while paused (it used to run on behind the pause menu).
var zipAt by remember { mutableLongStateOf(-1L) }
@@ -218,18 +241,26 @@ internal fun BlastOffScreen(play: ArcadePlay) {
val start = withFrameMillis { it } - now
while (true) { val t = withFrameMillis { it } - start; now = t; if (t > 1_200) { zipAt = -1; now = 0; break } }
}
BackHandler(stage == ClassicStage.Play && !paused) { if (game.inTray) game = game.move(0, -1) else pause() }
fun setGame(next: BlastGame) { game = next; crun = crun?.moved(next) }
BackHandler(stage == ClassicStage.Play && !paused) { if (game.inTray) setGame(game.move(0, -1)) else pause() }
if (stage == ClassicStage.Title) {
ClassicTitle(gameDef, backdrop, ArcadeColours.Pink, "Fit them in, light them up!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"),
val nextUp = minOf(cleared + 1, BlastChallenges.size)
if (challenge) ClassicTitle(gameDef, backdrop, ArcadeColours.Pink, "Twenty boards. Can you clear them all?",
listOf("Cleared" to "$cleared of ${BlastChallenges.size}"), timed = false, difficulty = play.difficulty, refocus = !howTo,
playLabel = "Challenge $nextUp", onPlay = { startChallenge(nextUp) }, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
mode = "Challenges", modes = 2, onMode = { challenge = false; latestPlay.setLevel("mode", "Classic") },
note = "Each board is made by hand, with a target: clear so many lines with so many shapes. The shapes come in the same order every try, so you can learn it. Next: ${BlastChallenges[nextUp - 1].name}, ${BlastChallenges[nextUp - 1].lines} lines in ${BlastChallenges[nextUp - 1].pieces} shapes.")
else ClassicTitle(gameDef, backdrop, ArcadeColours.Pink, "Fit them in, light them up!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"),
timed = false, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
mode = "Classic", modes = 2, onMode = { challenge = true; latestPlay.setLevel("mode", "Challenge") },
note = "Clear lines on placings in a row for a combo: it multiplies every clear.")
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
return
}
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused,
// Back by context: choosing in the tray, Back goes back to the board with the shape you had; on the board it pauses.
active = { game.inTray }, cancel = { game = game.move(0, -1) }, pause = ::pause) { key, native ->
active = { game.inTray }, cancel = { setGame(game.move(0, -1)) }, pause = ::pause) { key, native ->
// Releases are always noted, so the guard knows OK was let go even if the game paused meanwhile.
if (native.action == KeyEvent.ACTION_UP) { guard.accept(native); return@gameKeys false }
if (native.action != KeyEvent.ACTION_DOWN || !game.alive) return@gameKeys false
@@ -238,10 +269,14 @@ internal fun BlastOffScreen(play: ArcadePlay) {
ArcadeKey.Right -> game.move(1, 0)
ArcadeKey.Up -> game.move(0, -1)
ArcadeKey.Down -> game.move(0, 1)
ArcadeKey.Ok -> if (!guard.accept(native)) game else game.press(random).also { if (it.lastCleared >= 2 || it.streak >= 2) { now = 0; zipAt = System.currentTimeMillis() } }
ArcadeKey.Ok -> if (!guard.accept(native)) game else {
// A challenge counts its shapes and lines as they're placed; Classic plays on as before.
val r = crun
if (r != null) { val after = r.press(crandom); crun = after; after.game } else game.press(random)
}.also { if (it.lastCleared >= 2 || it.streak >= 2) { now = 0; zipAt = System.currentTimeMillis() } }
else -> null
}
if (next != null) game = next
if (next != null) { if (key == ArcadeKey.Ok) game = next else setGame(next) }
next != null
}
Box(Modifier.fillMaxSize()) {
@@ -249,6 +284,15 @@ internal fun BlastOffScreen(play: ArcadePlay) {
footer = if (game.inTray) listOf(Control("◀▶", "Choose a shape"), Control("OK", "Take it"), Control("▲", "Back to the board"), Control("Back", "Back to the board"))
else listOf(Control("◀▶▲▼", "Move the shape"), Control("OK", "Place it"), Control("▼", "Off the board: the tray"), Control("Back", "Pause")),
hud = {
val r = crun
if (r != null) {
HudLabel("CHALLENGE ${r.challenge.number}")
Text(r.challenge.name, color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
Spacer(Modifier.height(6.dp))
HudLabel("LINES"); HudValue("${r.lines} of ${r.challenge.lines}", if (r.won) ArcadeColours.Green else ArcadeColours.Ink)
HudLabel("SHAPES LEFT"); HudValue("${r.shapesLeft}", if (r.shapesLeft <= 3) ArcadeColours.Red else ArcadeColours.Ink)
return@ClassicPlayFrame
}
HudLabel("SCORE"); HudValue("%,d".format(game.score))
HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score)))
Spacer(Modifier.height(6.dp))
@@ -278,10 +322,20 @@ internal fun BlastOffScreen(play: ArcadePlay) {
drawOrbChaser(at, r, OrbCharacter.Zip, OrbDir.Left, false, false, false, 0f)
}
}
if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLAST OFF · NO ROOM LEFT", "SCORE", "%,d".format(game.score),
val cr = crun
if (stage == ClassicStage.Result && cr != null) {
val last = cr.challenge.number == BlastChallenges.size
if (cr.won) ClassicResult(gameDef, "BLAST OFF · CHALLENGE ${cr.challenge.number} · ${cr.challenge.name.uppercase()}", "LINES", "${cr.lines} of ${cr.challenge.lines}", newBest = false,
previous = "With ${cr.shapesLeft} shapes to spare", detail = if (last) "All ${BlastChallenges.size} cleared!" else "Next: ${BlastChallenges[cr.challenge.number].name}",
heading = "CLEARED!", againLabel = if (last) "Play it again" else "Next board", cheer = Mascot.Zip,
onAgain = { startChallenge(if (last) cr.challenge.number else cr.challenge.number + 1) }, extra = if (last) null else "Try again" to { startChallenge(cr.challenge.number) }, onBack = ::leave)
else ClassicResult(gameDef, "BLAST OFF · CHALLENGE ${cr.challenge.number} · ${cr.challenge.name.uppercase()}", "LINES", "${cr.lines} of ${cr.challenge.lines}", newBest = false,
previous = if (cr.game.alive) "Out of shapes" else "No room left", detail = "The shapes come in the same order: try another way.", heading = "NOT QUITE",
againLabel = "Try again", cheer = Mascot.Drift, onAgain = { startChallenge(cr.challenge.number) }, onBack = ::leave)
} else if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLAST OFF · NO ROOM LEFT", "SCORE", "%,d".format(game.score),
newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title), detail = null,
cheer = Mascot.Zip, onAgain = ::startRun, onBack = ::leave)
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Blast Off · ${"%,d".format(game.score)}",
onResume = { guard.reset(); paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false)); startRun() }, onExit = ::leave)
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, crun?.let { "Challenge ${it.challenge.number} · ${it.lines} of ${it.challenge.lines} lines" } ?: "Blast Off · ${"%,d".format(game.score)}",
onResume = { guard.reset(); paused = false }, onRestart = { val r = crun; if (r != null) startChallenge(r.challenge.number) else { run.end(RunEnd(game.score, finished = false)); startRun() } }, onExit = ::leave)
}
}
@@ -295,7 +295,7 @@ internal fun BlockDropScreen(play: ArcadePlay) {
ClassicResult(gameDef, "BLOCK DROP · 40-LINE SPRINT", if (done) "TIME" else "ROWS", if (done) sprintText(centis) else "${game.lines} of $SPRINT_LINES",
newBest = done && (bestBefore == 0 || centis < bestBefore), heading = if (done) "FORTY!" else "TOPPED OUT",
previous = if (bestBefore > 0) "Best ${sprintText(bestBefore)}" else "Your first Sprint", detail = if (done) null else "Only a finished Sprint goes in the High Scores",
againLabel = "Sprint again", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave)
againLabel = "Go again", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave)
} else if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLOCK DROP · LEVEL ${game.level} REACHED", "SCORE", "%,d".format(game.score),
newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title),
detail = "${game.lines} rows cleared", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave)
@@ -0,0 +1,66 @@
package tv.orbit.classic
/**
* Blast Off's Challenge (Phase 2, 9 November 2026): twenty numbered boards, made by hand, each with a target: clear so many
* lines with so many shapes. The shapes come in the same order every try (each challenge has its own seed), so a challenge
* is a puzzle you can learn, not luck. Free and optional, no streaks; the High Scores keep the furthest challenge cleared.
*/
internal class BlastChallenge(val number: Int, val name: String, val rows: List<String>, val lines: Int, val pieces: Int) {
val seed get() = 7_700L + number * 131L
/** The starting board: # is a block already there, in the cast's colours by where it sits. */
fun board(): List<List<Int>> = rows.mapIndexed { y, row -> row.mapIndexed { x, c -> if (c == '#') (x + 2 * y) % BlastColours.size + 1 else 0 } }
fun start(random: java.util.Random) = BlastGame(board(), BlastGame.deal(random), 0, 3, 3)
}
/** A challenge being played: the board, shapes used, lines cleared. Won on reaching the target; lost when out of shapes or room. */
internal class BlastRun(val challenge: BlastChallenge, val game: BlastGame, val placed: Int = 0, val lines: Int = 0) {
val won get() = lines >= challenge.lines
val lost get() = !won && (placed >= challenge.pieces || !game.alive)
val over get() = won || lost
val shapesLeft get() = (challenge.pieces - placed).coerceAtLeast(0)
/** The game moved (steering, the tray): nothing counted. */
fun moved(next: BlastGame) = BlastRun(challenge, next, placed, lines)
/** OK: a shape placed counts one, and the lines it clears count towards the target. */
fun press(random: java.util.Random): BlastRun {
if (over) return this
val next = game.press(random)
return if (next.score > game.score) BlastRun(challenge, next, placed + 1, lines + next.lastCleared) else BlastRun(challenge, next, placed, lines)
}
companion object {
fun start(c: BlastChallenge) = java.util.Random(c.seed).let { r -> BlastRun(c, c.start(r)) to r }
}
}
private fun b(vararg rows: String) = rows.toList()
/** The twenty, easiest first. */
internal val BlastChallenges: List<BlastChallenge> = listOf(
BlastChallenge(1, "Warm-up", b("........", "........", "........", "........", "........", "........", "###..###", "###..###"), 2, 8),
BlastChallenge(2, "Side door", b("........", "........", "........", "........", "##......", "##......", "##......", "##......"), 2, 10),
BlastChallenge(3, "Two gaps", b("........", "........", "........", "........", "........", "##.#####", "#####.##", "##.#####"), 3, 10),
BlastChallenge(4, "Pillars", b("........", "#......#", "#......#", "#......#", "#......#", "#......#", "#......#", "#......#"), 3, 12),
BlastChallenge(5, "Steps", b("........", "........", "........", "........", "#.......", "##......", "###.....", "####...."), 3, 12),
BlastChallenge(6, "The frame", b(".######.", "#......#", "#......#", "#......#", "#......#", "#......#", "#......#", ".######."), 3, 12),
BlastChallenge(7, "Chequers", b("........", "........", "........", "........", "#.#.#.#.", ".#.#.#.#", "#.#.#.#.", ".#.#.#.#"), 3, 14),
BlastChallenge(8, "Ollie's ring", b("........", "........", "..####..", ".##..##.", ".##..##.", "..####..", "........", "........"), 4, 14),
BlastChallenge(9, "Comb", b("#.#.#.#.", "#.#.#.#.", "#.#.#.#.", "........", "........", "........", "........", "........"), 4, 14),
BlastChallenge(10, "Half way", b("........", "........", "........", "........", "####....", "####....", "####....", "####...."), 4, 14),
BlastChallenge(11, "Corners", b("##....##", "##....##", "........", "........", "........", "........", "##....##", "##....##"), 4, 16),
BlastChallenge(12, "Cross", b("...#....", "...#....", "...#....", "###.####", "...#....", "...#....", "...#....", "...#...."), 4, 16),
BlastChallenge(13, "Staircase", b("#.......", "##......", "###.....", "####....", "#####...", "######..", "#######.", "........"), 5, 16),
BlastChallenge(14, "Gappy", b("###.####", "####.###", "#.######", "######.#", "........", "........", "........", "........"), 6, 16),
BlastChallenge(15, "Window", b("..####..", "##....##", "##....##", "##....##", "##....##", "##....##", "##....##", "..####.."), 6, 16),
BlastChallenge(16, "Zig-zag", b("##......", ".##.....", "..##....", "...##...", "....##..", ".....##.", "......##", "........"), 6, 18),
BlastChallenge(17, "Shelves", b("........", "######..", "........", "..######", "........", "######..", "........", "..######"), 7, 18),
BlastChallenge(18, "Sky high", b("##.##.##", "........", "##.##.##", "........", "........", "........", "........", "........"), 7, 20),
BlastChallenge(19, "Tight squeeze", b("###..###", "###..###", "###..###", "........", "........", "###..###", "###..###", "###..###"), 8, 20),
BlastChallenge(20, "Blast off!", b("........", "........", "........", "........", "#.######", "###.####", "#####.##", "#######."), 8, 20),
)
/** The furthest challenge cleared, as the High Scores write it. */
internal fun blastChallengeLine(score: Int) = if (score >= BlastChallenges.size) "All ${BlastChallenges.size} cleared" else "Challenge $score"
@@ -109,6 +109,9 @@ internal const val PATIENCE_DAILY3_SCORES = "PatienceDaily3"
/** Pairs' Challenge: boards cleared then pairs matched, in one number ([tv.orbit.classic.pairsScore]). */
internal const val PAIRS_CHALLENGE_SCORES = "PairsChallenge"
/** Blast Off's Challenges: the furthest of the twenty cleared. */
internal const val BLAST_CHALLENGE_SCORES = "BlastChallenge"
/**
* One of a game's High Scores tables: the game's own (its id, its score kind), or a mode's, kept under its own record id so
* the two never mix (Paul: "preserve existing scores and make new modes separate"). [format] writes a score for the page.
@@ -123,6 +126,7 @@ internal val modeTables: Map<String, List<ScoreTable>> = mapOf(
"Patience" to listOf(ScoreTable(PATIENCE_DAILY_SCORES, "Daily", ScoreKind.FewestMoves) { tv.orbit.classic.dailyLine(it) },
ScoreTable(PATIENCE_DAILY3_SCORES, "Daily Draw 3", ScoreKind.FewestMoves) { tv.orbit.classic.dailyLine(it) }),
"Pairs" to listOf(ScoreTable(PAIRS_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.pairsLine(it) }),
"Blast" to listOf(ScoreTable(BLAST_CHALLENGE_SCORES, "Challenges", ScoreKind.Points) { tv.orbit.classic.blastChallengeLine(it) }),
"Sky" to listOf(ScoreTable(SKY_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.challengeLine(it) }),
)
@@ -89,9 +89,10 @@ internal fun ClassicTitle(game: ArcadeGame, backdrop: ArcadeBackdrop, accent: Co
Canvas(Modifier.size(80.dp)) { drawMascot(game.mascot, center, size.minDimension * .36f) }
}
Spacer(Modifier.height(16.dp))
Column(Modifier.width(210.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Column(Modifier.width(230.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
ArcadeButton(playLabel, Modifier.fillMaxWidth().focusRequester(play), icon = "▶", primary = true, height = 34.dp, onClick = onPlay)
if (modes > 1) ArcadeButton("Mode", Modifier.fillMaxWidth(), icon = "◆", detail = mode, height = 34.dp, onClick = onMode)
// The mode spelled out in full on the button itself (OK steps to the next); the chip below says it too.
if (modes > 1) ArcadeButton(mode, Modifier.fillMaxWidth(), icon = "◆", height = 34.dp, onClick = onMode)
ArcadeButton("How to Play", Modifier.fillMaxWidth(), icon = "?", height = 34.dp, onClick = onHowTo)
ArcadeButton("Back to Arcade", Modifier.fillMaxWidth(), icon = "←", height = 34.dp, onClick = onBack)
}
@@ -171,7 +172,7 @@ internal fun ClassicResult(game: ArcadeGame, kicker: String, label: String, valu
if (detail != null) Text(detail, color = ArcadeColours.Muted, fontSize = 13.sp, textAlign = TextAlign.Center)
Spacer(Modifier.height(6.dp))
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
ArcadeButton(againLabel, Modifier.width(160.dp).focusRequester(first), icon = "▶", primary = true, height = 34.dp, onClick = onAgain)
ArcadeButton(againLabel, Modifier.width(180.dp).focusRequester(first), icon = "▶", primary = true, height = 34.dp, onClick = onAgain)
if (extra != null) ArcadeButton(extra.first, Modifier.width(160.dp), icon = "✦", height = 34.dp, onClick = extra.second)
ArcadeButton("Back to Arcade", Modifier.width(200.dp), icon = "←", height = 34.dp, onClick = onBack)
}