Skydoku Challenge: a ladder of ten puzzles from 6x6 to 8x8, three shared hearts, a clock, its own High Scores
Puzzle maker takes a size (6x6 unchanged, so the daily puzzle is the same); a heart back every third puzzle; scored on puzzles solved then time; the next puzzle made in the background while this one is played. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import kotlinx.coroutines.launch
|
||||
import tv.orbit.classic.arcade.SKY_CHALLENGE_SCORES
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
@@ -57,20 +58,22 @@ import kotlin.math.abs
|
||||
internal const val SKY_SIZE = 6
|
||||
internal const val SKY_HEARTS = 3
|
||||
|
||||
/** The region of each square (0 to 5), and the one answer: the column of the cast member in each row. */
|
||||
internal class SkyPuzzle(val regions: IntArray, val answer: IntArray)
|
||||
/** The region of each square (0 to n - 1), and the one answer: the column of the cast member in each row. [size] is n. */
|
||||
internal class SkyPuzzle(val regions: IntArray, val answer: IntArray) {
|
||||
val size get() = answer.size
|
||||
}
|
||||
|
||||
/** Every placing of one per row and column, none touching, that puts one in each region. Counts no further than [limit]. */
|
||||
internal fun skyAnswers(regions: IntArray, limit: Int = 2): List<IntArray> {
|
||||
internal fun skyAnswers(regions: IntArray, limit: Int = 2, n: Int = SKY_SIZE): List<IntArray> {
|
||||
val found = mutableListOf<IntArray>()
|
||||
val cols = IntArray(SKY_SIZE)
|
||||
val cols = IntArray(n)
|
||||
fun place(row: Int, usedCols: Int, usedRegions: Int) {
|
||||
if (found.size >= limit) return
|
||||
if (row == SKY_SIZE) { found += cols.copyOf(); return }
|
||||
for (c in 0 until SKY_SIZE) {
|
||||
if (row == n) { found += cols.copyOf(); return }
|
||||
for (c in 0 until n) {
|
||||
if (usedCols and (1 shl c) != 0) continue
|
||||
if (row > 0 && abs(cols[row - 1] - c) <= 1) continue
|
||||
val region = regions[row * SKY_SIZE + c]
|
||||
val region = regions[row * n + c]
|
||||
if (usedRegions and (1 shl region) != 0) continue
|
||||
cols[row] = c
|
||||
place(row + 1, usedCols or (1 shl c), usedRegions or (1 shl region))
|
||||
@@ -80,36 +83,40 @@ internal fun skyAnswers(regions: IntArray, limit: Int = 2): List<IntArray> {
|
||||
return found
|
||||
}
|
||||
|
||||
internal fun skyMake(random: java.util.Random): SkyPuzzle {
|
||||
/**
|
||||
* A puzzle of [n] by [n] (6 for Classic and the daily; the Challenge ladder goes up to 8). The 6 by 6 puzzles come out
|
||||
* exactly as they always have from the same random numbers, so the daily puzzle is unchanged.
|
||||
*/
|
||||
internal fun skyMake(random: java.util.Random, n: Int = SKY_SIZE): SkyPuzzle {
|
||||
while (true) {
|
||||
// An answer first: one per row and column, never touching.
|
||||
val answer = skyPlacing(random) ?: continue
|
||||
// Then six regions grown out from it at random, one around each cast member, kept only if that answer is the only one.
|
||||
val answer = skyPlacing(random, n) ?: continue
|
||||
// Then n regions grown out from it at random, one around each cast member, kept only if that answer is the only one.
|
||||
repeat(60) {
|
||||
val regions = IntArray(SKY_SIZE * SKY_SIZE) { -1 }
|
||||
val regions = IntArray(n * n) { -1 }
|
||||
val frontier = mutableListOf<Int>()
|
||||
for (r in 0 until SKY_SIZE) { val i = r * SKY_SIZE + answer[r]; regions[i] = r; frontier += i }
|
||||
for (r in 0 until n) { val i = r * n + answer[r]; regions[i] = r; frontier += i }
|
||||
while (frontier.isNotEmpty()) {
|
||||
val i = frontier.removeAt(random.nextInt(frontier.size))
|
||||
val open = listOf(-SKY_SIZE, SKY_SIZE, -1, 1).map { i + it }.filter { n ->
|
||||
n in regions.indices && regions[n] == -1 && (abs(n % SKY_SIZE - i % SKY_SIZE) <= 1)
|
||||
val open = listOf(-n, n, -1, 1).map { i + it }.filter { m ->
|
||||
m in regions.indices && regions[m] == -1 && (abs(m % n - i % n) <= 1)
|
||||
}
|
||||
if (open.isEmpty()) continue
|
||||
val n = open[random.nextInt(open.size)]
|
||||
regions[n] = regions[i]
|
||||
frontier += i; frontier += n
|
||||
val m = open[random.nextInt(open.size)]
|
||||
regions[m] = regions[i]
|
||||
frontier += i; frontier += m
|
||||
}
|
||||
// Region numbers follow the cast order by the rows of their members, so colours vary.
|
||||
if (skyAnswers(regions).size == 1) return SkyPuzzle(regions, answer)
|
||||
if (skyAnswers(regions, n = n).size == 1) return SkyPuzzle(regions, answer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun skyPlacing(random: java.util.Random): IntArray? {
|
||||
val cols = IntArray(SKY_SIZE)
|
||||
private fun skyPlacing(random: java.util.Random, n: Int = SKY_SIZE): IntArray? {
|
||||
val cols = IntArray(n)
|
||||
fun go(row: Int, used: Int): Boolean {
|
||||
if (row == SKY_SIZE) return true
|
||||
for (c in (0 until SKY_SIZE).shuffled(random)) {
|
||||
if (row == n) return true
|
||||
for (c in (0 until n).shuffled(random)) {
|
||||
if (used and (1 shl c) != 0 || (row > 0 && abs(cols[row - 1] - c) <= 1)) continue
|
||||
cols[row] = c
|
||||
if (go(row + 1, used or (1 shl c))) return true
|
||||
@@ -120,10 +127,10 @@ private fun skyPlacing(random: java.util.Random): IntArray? {
|
||||
}
|
||||
|
||||
/** The squares a cast member at [i] rules out: their row, column and region, and the eight around them. */
|
||||
internal fun skyRuledOut(regions: IntArray, i: Int): Set<Int> {
|
||||
val r = i / SKY_SIZE; val c = i % SKY_SIZE
|
||||
internal fun skyRuledOut(regions: IntArray, i: Int, n: Int = SKY_SIZE): Set<Int> {
|
||||
val r = i / n; val c = i % n
|
||||
return regions.indices.filter { j ->
|
||||
j != i && (j / SKY_SIZE == r || j % SKY_SIZE == c || regions[j] == regions[i] || (abs(j / SKY_SIZE - r) <= 1 && abs(j % SKY_SIZE - c) <= 1))
|
||||
j != i && (j / n == r || j % n == c || regions[j] == regions[i] || (abs(j / n - r) <= 1 && abs(j % n - c) <= 1))
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
@@ -131,28 +138,45 @@ internal class SkyGame(val puzzle: SkyPuzzle, val placed: Set<Int> = emptySet(),
|
||||
val cursor: Int = 0,
|
||||
/** The square of the last wrong try, shown with a cross until the next move. */
|
||||
val wrong: Int? = null) {
|
||||
val done get() = placed.size == SKY_SIZE
|
||||
val n get() = puzzle.size
|
||||
val done get() = placed.size == n
|
||||
val out get() = hearts <= 0
|
||||
private fun copy(placed: Set<Int> = this.placed, crossed: Set<Int> = this.crossed, hearts: Int = this.hearts, cursor: Int = this.cursor, wrong: Int? = null) =
|
||||
SkyGame(puzzle, placed, crossed, hearts, cursor, wrong)
|
||||
fun move(dx: Int, dy: Int) = copy(cursor = ((cursor / SKY_SIZE + dy).coerceIn(0, SKY_SIZE - 1)) * SKY_SIZE + (cursor % SKY_SIZE + dx).coerceIn(0, SKY_SIZE - 1))
|
||||
fun move(dx: Int, dy: Int) = copy(cursor = ((cursor / n + dy).coerceIn(0, n - 1)) * n + (cursor % n + dx).coerceIn(0, n - 1))
|
||||
/** OK: put the region's cast member here. Right, and the squares they rule out are crossed off; wrong, and a heart goes. */
|
||||
fun place(): SkyGame {
|
||||
if (done || out || cursor in placed || cursor in crossed) return this
|
||||
val right = puzzle.answer[cursor / SKY_SIZE] == cursor % SKY_SIZE
|
||||
return if (right) copy(placed = placed + cursor, crossed = crossed + skyRuledOut(puzzle.regions, cursor))
|
||||
val right = puzzle.answer[cursor / n] == cursor % n
|
||||
return if (right) copy(placed = placed + cursor, crossed = crossed + skyRuledOut(puzzle.regions, cursor, n))
|
||||
else copy(hearts = hearts - 1, crossed = crossed + cursor, wrong = cursor)
|
||||
}
|
||||
fun again() = SkyGame(puzzle)
|
||||
}
|
||||
|
||||
/**
|
||||
* Skydoku's Challenge (Phase 2, 9 November 2026): a ladder of ten puzzles growing from 6 by 6 to 8 by 8, three hearts for
|
||||
* the whole climb and a clock. Every third puzzle solved wins a heart back (up to three). Scored on puzzles solved, then
|
||||
* time: [challengeScore] keeps both in one number, so more solved always ranks higher, and quicker breaks a tie.
|
||||
*/
|
||||
internal val SkyLadder = listOf(6, 6, 6, 7, 7, 7, 7, 8, 8, 8)
|
||||
|
||||
internal fun challengeScore(solved: Int, seconds: Int) = solved * 10_000 + (9_999 - seconds.coerceIn(0, 9_999))
|
||||
internal fun challengeSolved(score: Int) = score / 10_000
|
||||
internal fun challengeSeconds(score: Int) = 9_999 - score % 10_000
|
||||
internal fun clockText(seconds: Int) = "%d:%02d".format(seconds / 60, seconds % 60)
|
||||
internal fun challengeLine(score: Int) = "${challengeSolved(score)} of ${SkyLadder.size} · ${clockText(challengeSeconds(score))}"
|
||||
|
||||
/** After solving puzzle [solved] (1 is the first), the hearts carried to the next: one back every third, never above three. */
|
||||
internal fun ladderHearts(hearts: Int, solved: Int) = if (solved % 3 == 0) minOf(SKY_HEARTS, hearts + 1) else hearts
|
||||
|
||||
/** The puzzle of the day: the same all day for everyone with Orbit. */
|
||||
internal fun skyDaily(day: java.time.LocalDate) = skyMake(java.util.Random(day.toEpochDay() * 7_919 + 61))
|
||||
|
||||
|
||||
/** The cast in region order, each region in its member's colour. */
|
||||
internal val SkyCast = listOf("Ollie", "Blaze", "Zip", "Drift", "Luna", "Bumble")
|
||||
internal val SkyColours = listOf(Color(0xFFF7A928), OrbCharacter.Blaze.colour, OrbCharacter.Zip.colour, OrbCharacter.Drift.colour, OrbCharacter.Luna.colour, Color(0xFF8BD86A))
|
||||
internal val SkyCast = listOf("Ollie", "Blaze", "Zip", "Drift", "Luna", "Bumble", "Nite Owl", "a star")
|
||||
internal val SkyColours = listOf(Color(0xFFF7A928), OrbCharacter.Blaze.colour, OrbCharacter.Zip.colour, OrbCharacter.Drift.colour, OrbCharacter.Luna.colour, Color(0xFF8BD86A), Color(0xFF6C7BD9), Color(0xFFFFDE59))
|
||||
|
||||
/** One of the six, by region, drawn to the cast's model sheet. */
|
||||
internal fun DrawScope.drawSkyFace(region: Int, centre: Offset, r: Float) = when (region) {
|
||||
@@ -162,16 +186,19 @@ internal fun DrawScope.drawSkyFace(region: Int, centre: Offset, r: Float) = when
|
||||
3 -> drawOrbChaser(centre, r * .85f, OrbCharacter.Drift, OrbDir.Down, false, false, false, 0f)
|
||||
4 -> drawOrbChaser(centre, r * .85f, OrbCharacter.Luna, OrbDir.Down, false, false, false, 0f)
|
||||
5 -> drawOrbBee(centre + Offset(0f, r * .15f), r * .62f)
|
||||
else -> {}
|
||||
// The Challenge's bigger skies: Nite Owl, and a gold star (a stand-in until Paul picks the eighth).
|
||||
6 -> drawNiteOwl(centre, r * .8f)
|
||||
else -> drawPath(starPath(centre, r * .8f, r * .36f, 0f), Color(0xFFFFDE59))
|
||||
}
|
||||
|
||||
/** The board: regions tinted in their member's colour with bold edges between them, the cast where placed, crosses where ruled out. */
|
||||
internal fun DrawScope.drawSkyBoard(game: SkyGame, showCursor: Boolean = true) {
|
||||
val cell = size.minDimension / SKY_SIZE
|
||||
val origin = Offset((size.width - cell * SKY_SIZE) / 2, (size.height - cell * SKY_SIZE) / 2)
|
||||
val n = game.n
|
||||
val cell = size.minDimension / n
|
||||
val origin = Offset((size.width - cell * n) / 2, (size.height - cell * n) / 2)
|
||||
val regions = game.puzzle.regions
|
||||
for (i in regions.indices) {
|
||||
val at = origin + Offset(i % SKY_SIZE * cell, i / SKY_SIZE * cell)
|
||||
val at = origin + Offset(i % n * cell, i / n * cell)
|
||||
drawRect(ArcadeColours.Night, at, Size(cell, cell))
|
||||
drawRect(SkyColours[regions[i]].copy(alpha = .42f), at, Size(cell, cell))
|
||||
if (i in game.placed) drawSkyFace(regions[i], at + Offset(cell / 2, cell / 2), cell * .36f)
|
||||
@@ -184,14 +211,14 @@ internal fun DrawScope.drawSkyBoard(game: SkyGame, showCursor: Boolean = true) {
|
||||
}
|
||||
// Thin lines between squares, bold ones between regions.
|
||||
for (i in regions.indices) {
|
||||
val r = i / SKY_SIZE; val c = i % SKY_SIZE
|
||||
val r = i / n; val c = i % n
|
||||
val at = origin + Offset(c * cell, r * cell)
|
||||
if (c < SKY_SIZE - 1) drawLine(if (regions[i] != regions[i + 1]) Color.White else Color.White.copy(alpha = .15f), at + Offset(cell, 0f), at + Offset(cell, cell), if (regions[i] != regions[i + 1]) cell * .06f else cell * .015f)
|
||||
if (r < SKY_SIZE - 1) drawLine(if (regions[i] != regions[i + SKY_SIZE]) Color.White else Color.White.copy(alpha = .15f), at + Offset(0f, cell), at + Offset(cell, cell), if (regions[i] != regions[i + SKY_SIZE]) cell * .06f else cell * .015f)
|
||||
if (c < n - 1) drawLine(if (regions[i] != regions[i + 1]) Color.White else Color.White.copy(alpha = .15f), at + Offset(cell, 0f), at + Offset(cell, cell), if (regions[i] != regions[i + 1]) cell * .06f else cell * .015f)
|
||||
if (r < n - 1) drawLine(if (regions[i] != regions[i + n]) Color.White else Color.White.copy(alpha = .15f), at + Offset(0f, cell), at + Offset(cell, cell), if (regions[i] != regions[i + n]) cell * .06f else cell * .015f)
|
||||
}
|
||||
drawRoundRect(Color.White, origin, Size(cell * SKY_SIZE, cell * SKY_SIZE), CornerRadius(cell * .08f), style = Stroke(cell * .07f))
|
||||
drawRoundRect(Color.White, origin, Size(cell * n, cell * n), CornerRadius(cell * .08f), style = Stroke(cell * .07f))
|
||||
if (showCursor && !game.done && !game.out) {
|
||||
val at = origin + Offset(game.cursor % SKY_SIZE * cell, game.cursor / SKY_SIZE * cell)
|
||||
val at = origin + Offset(game.cursor % n * cell, game.cursor / n * cell)
|
||||
drawRoundRect(ArcadeColours.Yellow, at + Offset(cell * .05f, cell * .05f), Size(cell * .9f, cell * .9f), CornerRadius(cell * .12f), style = Stroke(cell * .08f))
|
||||
}
|
||||
}
|
||||
@@ -213,13 +240,16 @@ internal fun SkydokuScreen(play: ArcadePlay) {
|
||||
val today = remember { java.time.LocalDate.now() }
|
||||
var dailyDone by remember { mutableStateOf(play.level["daily"] == today.toString()) }
|
||||
var daily by remember { mutableStateOf(!dailyDone) }
|
||||
// Classic, or the Challenge ladder (Phase 2): chosen on the title and remembered; the Challenge has its own High Scores.
|
||||
var challenge by remember { mutableStateOf(play.level["mode"] == "Challenge") }
|
||||
// Puzzles are made off the main thread (making one and checking it has only one answer could stutter the screen):
|
||||
// the first is made while the title shows.
|
||||
var game by remember { mutableStateOf<SkyGame?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
suspend fun made(n: Int, todays: Boolean = false) = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Default) { if (todays) skyDaily(today) else skyMake(random, n) }
|
||||
fun make(todays: Boolean, then: () -> Unit = {}) {
|
||||
daily = todays; game = null
|
||||
scope.launch { val puzzle = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Default) { if (todays) skyDaily(today) else skyMake(random) }; game = SkyGame(puzzle); then() }
|
||||
scope.launch { game = SkyGame(made(SKY_SIZE, todays)); then() }
|
||||
}
|
||||
LaunchedEffect(Unit) { make(!dailyDone) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
@@ -230,25 +260,61 @@ internal fun SkydokuScreen(play: ArcadePlay) {
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
// A solved puzzle counts for this profile; today's puzzle is then done for today (per profile). Out of hearts counts nothing.
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game?.hearts ?: 0, finished = false) }
|
||||
// The Challenge: which rung of the ladder, the clock, the next puzzle made while this one is played.
|
||||
var rung by remember { mutableIntStateOf(0) }
|
||||
var seconds by remember { mutableIntStateOf(0) }
|
||||
var nextPuzzle by remember { mutableStateOf<SkyPuzzle?>(null) }
|
||||
var bestBefore by remember { mutableIntStateOf(play.bestIn(SKY_CHALLENGE_SCORES)) }
|
||||
val climb = rememberRun({ end -> latestPlay.onRunEndIn(SKY_CHALLENGE_SCORES, end) }) { RunEnd(challengeScore(rung, seconds), finished = false, detail = "Puzzle ${rung + 1}") }
|
||||
fun prepare(r: Int) { nextPuzzle = null; if (r < SkyLadder.size) scope.launch { nextPuzzle = made(SkyLadder[r]) } }
|
||||
fun begin() { run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun startChallenge() {
|
||||
bestBefore = latestPlay.bestIn(SKY_CHALLENGE_SCORES); rung = 0; seconds = 0; game = null; paused = false; stage = ClassicStage.Play
|
||||
climb.begin()
|
||||
scope.launch { game = SkyGame(made(SkyLadder[0])); prepare(1) }
|
||||
}
|
||||
LaunchedEffect(game, startWhenReady) { if (startWhenReady && game != null) { startWhenReady = false; begin() } }
|
||||
fun startNew() { make(false) { begin() } }
|
||||
val g = game
|
||||
LaunchedEffect(g?.done, g?.out) {
|
||||
if (g == null || stage != ClassicStage.Play) return@LaunchedEffect
|
||||
if (challenge) {
|
||||
if (g.done) {
|
||||
val solved = rung + 1
|
||||
if (solved == SkyLadder.size) { rung = solved; climb.end(RunEnd(challengeScore(solved, seconds), finished = true, detail = "All ${SkyLadder.size}")); stage = ClassicStage.Result; return@LaunchedEffect }
|
||||
val hearts = ladderHearts(g.hearts, solved)
|
||||
rung = solved
|
||||
val puzzle = nextPuzzle ?: made(SkyLadder[solved])
|
||||
game = SkyGame(puzzle, hearts = hearts)
|
||||
prepare(solved + 1)
|
||||
} else if (g.out) { climb.end(RunEnd(challengeScore(rung, seconds), finished = true, detail = "Puzzle ${rung + 1}")); stage = ClassicStage.Result }
|
||||
return@LaunchedEffect
|
||||
}
|
||||
if (g.done) {
|
||||
if (daily) { latestPlay.setLevel("daily", today.toString()); dailyDone = true }
|
||||
run.end(RunEnd(g.hearts, finished = true, detail = if (daily) "Today's puzzle" else null))
|
||||
stage = ClassicStage.Result
|
||||
} else if (g.out) stage = ClassicStage.Result
|
||||
}
|
||||
// The Challenge's clock runs only while playing (not paused, not while the next puzzle is being made).
|
||||
LaunchedEffect(stage, paused, challenge, g != null) {
|
||||
while (challenge && stage == ClassicStage.Play && !paused && game != null) { kotlinx.coroutines.delay(1_000); seconds++ }
|
||||
}
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { paused = true }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, OrbCharacter.Luna.colour, if (dailyDone) "Today's is done: fancy another?" else "Today's puzzle is ready!",
|
||||
val best = play.bestIn(SKY_CHALLENGE_SCORES)
|
||||
if (challenge) ClassicTitle(gameDef, backdrop, OrbCharacter.Luna.colour, "Ten skies, three hearts. Ready?",
|
||||
listOf("Your best" to if (best > 0) challengeLine(best) else "Not played yet"),
|
||||
timed = false, difficulty = play.difficulty, refocus = !howTo, playLabel = "Start the climb", mode = "Challenge", modes = 2,
|
||||
onMode = { challenge = false; latestPlay.setLevel("mode", "Classic") },
|
||||
onPlay = ::startChallenge, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "A ladder of ten puzzles, from 6 by 6 up to 8 by 8, against the clock. Three hearts for the whole climb; every third puzzle solved wins one back.")
|
||||
else ClassicTitle(gameDef, backdrop, OrbCharacter.Luna.colour, if (dailyDone) "Today's is done: fancy another?" else "Today's puzzle is ready!",
|
||||
listOf("Solved" to "${play.best}", "Today's puzzle" to if (dailyDone) "Done ★" else "Not yet"),
|
||||
timed = false, difficulty = play.difficulty, refocus = !howTo, playLabel = if (dailyDone) "New puzzle" else "Today's puzzle",
|
||||
timed = false, difficulty = play.difficulty, refocus = !howTo, playLabel = if (dailyDone) "New puzzle" else "Today's puzzle", mode = "Classic", modes = 2,
|
||||
onMode = { challenge = true; latestPlay.setLevel("mode", "Challenge") },
|
||||
onPlay = { if (game != null) begin() else startWhenReady = true }, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "One in every row and column, and no two touching, not even at the corners. Every puzzle can be solved by logic alone.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
@@ -270,34 +336,48 @@ internal fun SkydokuScreen(play: ArcadePlay) {
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶▲▼", "Move"), Control("OK", "Place"), Control("Back", "Pause")), hud = {
|
||||
HudLabel(if (daily) "TODAY'S PUZZLE" else "NEW PUZZLE")
|
||||
if (challenge) {
|
||||
HudLabel("CHALLENGE")
|
||||
HudLabel("PUZZLE ${minOf(rung + 1, SkyLadder.size)} OF ${SkyLadder.size}")
|
||||
HudValue(clockText(seconds))
|
||||
} else HudLabel(if (daily) "TODAY'S PUZZLE" else "NEW PUZZLE")
|
||||
Spacer(Modifier.height(4.dp))
|
||||
HudLabel("HEARTS")
|
||||
Canvas(Modifier.height(30.dp).fillMaxWidth()) { val r = size.height * .4f; repeat(SKY_HEARTS) { k -> drawHeart(Offset(r * 1.4f + k * r * 3.2f, size.height / 2), r, k < (g?.hearts ?: SKY_HEARTS)) } }
|
||||
if (challenge) Text("A heart back every third puzzle", color = ArcadeColours.Muted, fontSize = 13.sp)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("SOLVED"); HudValue("${play.best}")
|
||||
if (!challenge) { HudLabel("SOLVED"); HudValue("${play.best}") }
|
||||
}, side = {
|
||||
// Who goes in the region under the cursor.
|
||||
if (g != null) {
|
||||
val region = g.puzzle.regions[g.cursor]
|
||||
HudLabel("THIS COLOUR")
|
||||
Canvas(Modifier.size(72.dp)) { drawCircle(SkyColours[region].copy(alpha = .35f), size.minDimension / 2); drawSkyFace(region, center, size.minDimension * .4f) }
|
||||
Text(SkyCast[region], color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
|
||||
Text(SkyCast[region].replaceFirstChar { it.uppercase() }, color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
|
||||
Text("goes here?", color = ArcadeColours.Muted, fontSize = 14.sp)
|
||||
}
|
||||
}) {
|
||||
if (g != null) Canvas(Modifier.fillMaxHeight().aspectRatio(1f)) { drawSkyBoard(g) }
|
||||
else Text("Making a puzzle…", color = ArcadeColours.Muted, fontSize = 16.sp)
|
||||
}
|
||||
if (stage == ClassicStage.Result && g != null) {
|
||||
if (stage == ClassicStage.Result && challenge) {
|
||||
val score = challengeScore(rung, seconds)
|
||||
ClassicResult(gameDef, "SKYDOKU · CHALLENGE", "SOLVED", "$rung of ${SkyLadder.size}", newBest = rung > 0 && score > bestBefore,
|
||||
previous = (if (rung == SkyLadder.size) "The whole ladder in " else "In ") + clockText(seconds),
|
||||
detail = if (bestBefore > 0) "Previous best ${challengeLine(bestBefore)}" else "Your first Skydoku Challenge",
|
||||
heading = if (rung == SkyLadder.size) "TOP OF THE SKY!" else "OUT OF HEARTS", againLabel = "Climb again",
|
||||
cheer = if (rung == SkyLadder.size) Mascot.Bumble else Mascot.Drift, onAgain = ::startChallenge, onBack = { latestPlay.onLeave() })
|
||||
} else if (stage == ClassicStage.Result && g != null) {
|
||||
if (g.done) ClassicResult(gameDef, if (daily) "SKYDOKU · TODAY'S PUZZLE" else "SKYDOKU · NEW PUZZLE", "SOLVED", "${maxOf(play.best, 1)}", newBest = false,
|
||||
previous = "With ${g.hearts} of $SKY_HEARTS hearts left", detail = if (daily) "Today's puzzle is done. A new one tomorrow." else null, heading = "SOLVED!",
|
||||
againLabel = "New puzzle", cheer = Mascot.Bumble, onAgain = ::startNew, onBack = { latestPlay.onLeave() })
|
||||
else ClassicResult(gameDef, "SKYDOKU · OUT OF HEARTS", "PLACED", "${g.placed.size} of $SKY_SIZE", newBest = false,
|
||||
else ClassicResult(gameDef, "SKYDOKU · OUT OF HEARTS", "PLACED", "${g.placed.size} of ${g.n}", newBest = false,
|
||||
previous = "Every puzzle can be solved by logic alone.", detail = null, heading = "OUT OF HEARTS", againLabel = "Try it again",
|
||||
extra = "New puzzle" to ::startNew, cheer = Mascot.Drift, onAgain = { game = g.again(); paused = false; stage = ClassicStage.Play }, onBack = { latestPlay.onLeave() })
|
||||
}
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Skydoku · ${g?.placed?.size ?: 0} of $SKY_SIZE placed",
|
||||
onResume = { paused = false }, onRestart = { game = g?.again(); paused = false }, onExit = { latestPlay.onLeave() })
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, if (challenge) "Skydoku Challenge · puzzle ${rung + 1} of ${SkyLadder.size} · ${clockText(seconds)}" else "Skydoku · ${g?.placed?.size ?: 0} of ${g?.n ?: SKY_SIZE} placed",
|
||||
onResume = { paused = false },
|
||||
onRestart = { if (challenge) { climb.end(RunEnd(challengeScore(rung, seconds), finished = false, detail = "Puzzle ${rung + 1}")); startChallenge() } else { game = g?.again(); paused = false } },
|
||||
onExit = { latestPlay.onLeave() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,9 @@ internal const val HIVE_HARD_SCORES = "HiveHard"
|
||||
/** Star Chase's Signal Run (Phase 2, 9 November 2026): its own High Scores, apart from Classic's. */
|
||||
internal const val ORBMAN_SIGNAL_SCORES = "OrbManSignal"
|
||||
|
||||
/** Skydoku's Challenge ladder: puzzles solved, then time, in one number ([tv.orbit.classic.challengeScore]). */
|
||||
internal const val SKY_CHALLENGE_SCORES = "SkyChallenge"
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -106,6 +109,7 @@ internal class ScoreTable(val id: String, val name: String, val kind: ScoreKind,
|
||||
internal val modeTables: Map<String, List<ScoreTable>> = mapOf(
|
||||
"Hive" to listOf(ScoreTable(HIVE_HARD_SCORES, "Hard", ScoreKind.Points)),
|
||||
"OrbMan" to listOf(ScoreTable(ORBMAN_SIGNAL_SCORES, "Signal Run", ScoreKind.Points)),
|
||||
"Sky" to listOf(ScoreTable(SKY_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.challengeLine(it) }),
|
||||
)
|
||||
|
||||
/** Every table of a game, its own first (called Normal for BumbleHive, Classic for the rest). */
|
||||
|
||||
Reference in New Issue
Block a user