0.108.30: Blast Off and Skydoku, two cast games

Paul, 5 November 2026: our own versions of a block puzzle and a sudoku,
with the cast.

Blast Off: three shapes wait in the tray; move one over the 8x8 board and
place it, and full rows and columns clear. Ten a line, more for several at
once, and Zip zooms past on a combo. When nothing left fits, it's over.
Down off the board picks another shape. Blocks in the cast's colours.

Skydoku: a 6x6 sudoku with the six cast faces (Ollie, Blaze, Zip, Drift,
Luna, Bumble) instead of numbers; each row, column and 2x3 box holds each
once. Made fresh each time with exactly one answer: Easy keeps 20 faces,
Harder as few as it can. OK opens a row of faces to choose from (1 to 6 and
0 work too); clashes are ringed, never flashed; Zip and Blaze cheer a
solve. Both on the Arcade page, with bests kept.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-05 21:41:35 +00:00
co-authored by Claude Opus 5.5
parent a2d6a14ec7
commit af86cf25b5
8 changed files with 571 additions and 8 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 189
versionName = "0.108.29-cast-bumpers"
versionCode = 190
versionName = "0.108.30-blast-skydoku"
}
buildFeatures { compose = true }
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
@@ -0,0 +1,248 @@
package tv.orbit.classic
import android.view.KeyEvent
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.material3.Text
/**
* Blast Off (Paul, 5 November 2026): Orbit's own block puzzle with the cast. Three shapes wait in the tray; fit them anywhere on
* the 8×8 board, and every full row or column clears. Clearing more than one at once is a combo, and Zip zooms past. When none of
* the shapes left can fit, the game is over. The game has no screen in it, so it can be tested.
*/
internal const val BLAST_SIZE = 8
internal data class BlastShape(val cells: List<Pair<Int, Int>>) {
val width get() = cells.maxOf { it.first } + 1
val height get() = cells.maxOf { it.second } + 1
}
private fun shape(vararg rows: String) = BlastShape(rows.flatMapIndexed { y, row -> row.mapIndexedNotNull { x, c -> if (c == '#') x to y else null } })
/** Orbit's set of shapes, from a single square up to the big 3×3. */
internal val BlastShapes = listOf(
shape("#"), shape("##"), shape("#", "#"), shape("###"), shape("#", "#", "#"), shape("####"), shape("#", "#", "#", "#"), shape("#####"), shape("#", "#", "#", "#", "#"),
shape("##", "##"), shape("###", "###", "###"), shape("###", "###"), shape("##", "##", "##"),
shape("#.", "##"), shape(".#", "##"), shape("##", "#."), shape("##", ".#"),
shape("#.", "#.", "##"), shape(".#", ".#", "##"), shape("###", "#.."), shape("###", "..#"),
shape("###", ".#."), shape(".#.", "###"), shape("#.", "##", "#."), shape(".#", "##", ".#"),
shape("##.", ".##"), shape(".##", "##."))
/** The cast's colours, for the blocks: Ollie, Zip, Drift, Luna, Bumble and a mint green. */
internal val BlastColours = listOf(Color(0xFFF7A928), Color(0xFFFF4FA3), Color(0xFF35D6F2), Color(0xFFA77BFF), Color(0xFFFFD84A), Color(0xFF6EDCAA))
internal data class BlastPiece(val shape: BlastShape, val colour: Int)
internal class BlastGame(
/** Row by row: 0 empty, otherwise a colour + 1. */
val board: List<List<Int>>,
val tray: List<BlastPiece?>,
val selected: Int,
/** Where the chosen shape's top left would go. */
val x: Int, val y: Int,
/** Choosing from the tray rather than moving on the board. */
val inTray: Boolean = false,
val score: Int = 0,
val alive: Boolean = true,
/** Rows and columns cleared by the last placing, for the cheer. */
val lastCleared: Int = 0) {
val piece get() = tray.getOrNull(selected)
fun fits(p: BlastPiece, px: Int, py: Int) = p.shape.cells.all { (cx, cy) ->
val bx = px + cx; val by = py + cy
bx in 0 until BLAST_SIZE && by in 0 until BLAST_SIZE && board[by][bx] == 0
}
fun fitsAnywhere(p: BlastPiece) = (0..BLAST_SIZE - p.shape.height).any { py -> (0..BLAST_SIZE - p.shape.width).any { px -> fits(p, px, py) } }
private fun copy(board: List<List<Int>> = this.board, tray: List<BlastPiece?> = this.tray, selected: Int = this.selected, x: Int = this.x, y: Int = this.y,
inTray: Boolean = this.inTray, score: Int = this.score, alive: Boolean = this.alive, lastCleared: Int = this.lastCleared) =
BlastGame(board, tray, selected, x, y, inTray, score, alive, lastCleared)
/** Moving the shape keeps it all on the board; down from the bottom goes to the tray. */
fun move(dx: Int, dy: Int): BlastGame {
val p = piece ?: return this
if (inTray) {
if (dy < 0) return copy(inTray = false)
if (dx == 0) return this
val slots = tray.indices.filter { tray[it] != null }
val next = slots.getOrNull((slots.indexOf(selected) + dx).coerceIn(0, slots.lastIndex)) ?: selected
return copy(selected = next).clamped()
}
if (dy > 0 && y + p.shape.height >= BLAST_SIZE) return copy(inTray = true)
return copy(x = (x + dx).coerceIn(0, BLAST_SIZE - p.shape.width), y = (y + dy).coerceIn(0, BLAST_SIZE - p.shape.height))
}
private fun clamped(): BlastGame {
val p = piece ?: return this
return copy(x = x.coerceIn(0, BLAST_SIZE - p.shape.width), y = y.coerceIn(0, BLAST_SIZE - p.shape.height))
}
/** OK: in the tray it picks the shape up; on the board it places it, if it fits. */
fun press(random: java.util.Random): BlastGame {
if (!alive) return this
if (inTray) return copy(inTray = false)
val p = piece ?: return this
if (!fits(p, x, y)) return this
val placed = board.map { it.toMutableList() }
p.shape.cells.forEach { (cx, cy) -> placed[y + cy][x + cx] = p.colour + 1 }
val rows = (0 until BLAST_SIZE).filter { r -> placed[r].all { it != 0 } }
val cols = (0 until BLAST_SIZE).filter { c -> placed.all { it[c] != 0 } }
rows.forEach { r -> for (c in 0 until BLAST_SIZE) placed[r][c] = 0 }
cols.forEach { c -> for (r in 0 until BLAST_SIZE) placed[r][c] = 0 }
val lines = rows.size + cols.size
// A square for each block placed, ten for each line, and more for clearing several at once.
val gained = p.shape.cells.size + 10 * lines * lines
var tray = tray.toMutableList<BlastPiece?>().also { it[selected] = null }.toList()
if (tray.all { it == null }) tray = deal(random)
val next = BlastGame(placed, tray, tray.indexOfFirst { it != null }, x, y, false, score + gained, true, lines)
return next.copy(alive = next.tray.filterNotNull().any(next::fitsAnywhere)).clamped()
}
companion object {
fun deal(random: java.util.Random) = List(3) { BlastPiece(BlastShapes[random.nextInt(BlastShapes.size)], random.nextInt(BlastColours.size)) }
fun start(random: java.util.Random) = BlastGame(List(BLAST_SIZE) { List(BLAST_SIZE) { 0 } }, deal(random), 0, 3, 3)
}
}
private val Marquee = FontFamily(Font(R.font.anton_regular))
private val Honey = Color(0xFFFFD84A)
private fun DrawScope.blastBlock(at: Offset, cell: Float, colour: Color, alpha: Float = 1f) {
val pad = cell * .06f
drawRoundRect(colour.copy(alpha = alpha), at + Offset(pad, pad), Size(cell - 2 * pad, cell - 2 * pad), CornerRadius(cell * .18f))
drawRoundRect(Color.White.copy(alpha = .28f * alpha), at + Offset(pad * 2.2f, pad * 2.2f), Size(cell * .5f, cell * .18f), CornerRadius(cell * .09f))
}
/** The board, with the chosen shape shown where it would land: bright where it fits, faint and ringed red where it doesn't. */
internal fun DrawScope.drawBlastBoard(game: BlastGame, showPiece: Boolean = true) {
val cell = size.minDimension / BLAST_SIZE
val origin = Offset((size.width - cell * BLAST_SIZE) / 2, (size.height - cell * BLAST_SIZE) / 2)
drawRoundRect(Color(0xFF0A1850), origin - Offset(6f, 6f), Size(cell * BLAST_SIZE + 12f, cell * BLAST_SIZE + 12f), CornerRadius(cell * .2f))
for (r in 0 until BLAST_SIZE) for (c in 0 until BLAST_SIZE) {
val at = origin + Offset(c * cell, r * cell)
val v = game.board[r][c]
if (v == 0) drawRoundRect(Color.White.copy(alpha = .05f), at + Offset(cell * .06f, cell * .06f), Size(cell * .88f, cell * .88f), CornerRadius(cell * .16f))
else blastBlock(at, cell, BlastColours[v - 1])
}
val p = game.piece ?: return
if (!showPiece || game.inTray || !game.alive) return
val fits = game.fits(p, game.x, game.y)
p.shape.cells.forEach { (cx, cy) ->
val at = origin + Offset((game.x + cx) * cell, (game.y + cy) * cell)
blastBlock(at, cell, BlastColours[p.colour], if (fits) .85f else .35f)
if (!fits) drawRoundRect(Color(0xFFFF6B6B), at + Offset(cell * .08f, cell * .08f), Size(cell * .84f, cell * .84f), CornerRadius(cell * .16f), style = Stroke(cell * .06f))
}
}
private fun DrawScope.drawTrayPiece(p: BlastPiece, cell: Float) {
val origin = Offset((size.width - p.shape.width * cell) / 2, (size.height - p.shape.height * cell) / 2)
p.shape.cells.forEach { (cx, cy) -> blastBlock(origin + Offset(cx * cell, cy * cell), cell, BlastColours[p.colour]) }
}
@Composable
internal fun BlastOffScreen(best: Int, onBest: (Int) -> Unit, onLeave: () -> Unit) {
val calm = LocalContext.current.let { context -> remember { OrbitSettings(context).reduceMotion } }
val random = remember { java.util.Random() }
var game by remember { mutableStateOf(BlastGame.start(random)) }
var paused by remember { mutableStateOf(false) }
val focus = remember { FocusRequester() }
val menuFocus = remember { FocusRequester() }
val windowFocused = LocalWindowInfo.current.isWindowFocused
LaunchedEffect(windowFocused) { if (!windowFocused && game.alive) paused = true }
LaunchedEffect(paused, game.alive) { if (paused || !game.alive) menuFocus.requestFocus() else focus.requestFocus() }
LaunchedEffect(game.alive) { if (!game.alive && game.score > best) onBest(game.score) }
// Zip zooms past on a combo.
var zipAt by remember { mutableLongStateOf(-1L) }
var now by remember { mutableLongStateOf(0L) }
LaunchedEffect(zipAt) { if (zipAt >= 0 && !calm) { val start = withFrameMillis { it }; while (true) { val t = withFrameMillis { it } - start; now = t; if (t > 1_200) { zipAt = -1; break } } } }
// The best as it stood while this game was played, so the new best still shows once it's been saved; Zip and Blaze cheer it.
val bestBefore = remember(game.alive) { best }
val newBest = game.score > bestBefore && game.score > 0
BackHandler { if (game.alive) paused = !paused else onLeave() }
Row(Modifier.fillMaxSize().background(Navy).padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
val native = event.nativeKeyEvent
if (native.action != KeyEvent.ACTION_DOWN || paused || !game.alive) return@onPreviewKeyEvent false
val next = when (native.keyCode) {
KeyEvent.KEYCODE_DPAD_LEFT -> game.move(-1, 0)
KeyEvent.KEYCODE_DPAD_RIGHT -> game.move(1, 0)
KeyEvent.KEYCODE_DPAD_UP -> game.move(0, -1)
KeyEvent.KEYCODE_DPAD_DOWN -> game.move(0, 1)
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> game.press(random).also { if (it.score > game.score && it.lastCleared >= 2) zipAt = System.currentTimeMillis() }
else -> null
}
if (next != null) game = next
next != null
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
Column(Modifier.width(180.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Text("BLAST OFF", color = Honey, fontFamily = Marquee, fontSize = 32.sp)
Spacer(Modifier.height(10.dp))
Text("SCORE", color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
Text(game.score.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
Text("BEST", color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
Text(maxOf(best, game.score).toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
Spacer(Modifier.weight(1f))
Text("◄►▲▼ Move the shape", color = Muted, fontSize = 13.sp)
Text("OK Place it", color = Muted, fontSize = 13.sp)
Text("▼ off the board: choose another", color = Muted, fontSize = 13.sp)
Text("Back Pause", color = Muted, fontSize = 13.sp)
}
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp)) {
Canvas(Modifier.weight(1f).aspectRatio(1f)) { drawBlastBoard(game) }
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
game.tray.forEachIndexed { i, p ->
val chosen = i == game.selected
val corner = RoundedCornerShape(8.dp)
Box(Modifier.size(96.dp, 80.dp).background(if (chosen && game.inTray) Navy else Panel, corner)
.border(if (chosen) 3.dp else 0.dp, if (chosen && game.inTray) Yellow else if (chosen) Muted else Color.Transparent, corner)) {
if (p != null) Canvas(Modifier.fillMaxSize().padding(8.dp)) { drawTrayPiece(p, minOf(size.width / 5, size.height / 5)) }
}
}
}
}
if (zipAt >= 0 && !calm) Canvas(Modifier.fillMaxSize()) {
val f = (now / 1_200f).coerceIn(0f, 1f)
val at = Offset(size.width * (1.1f - 1.3f * f), size.height * .3f)
val r = size.minDimension * .06f
for (k in 1..6) drawCircle(Color(0xFFFFE066).copy(alpha = .8f - k * .12f), r * .16f, at + Offset(k * r * .5f, 0f))
drawOrbChaser(at, r, OrbCharacter.Zip, OrbDir.Left, false, false, false, 0f)
}
if (paused || !game.alive) Column(Modifier.background(Navy, RoundedCornerShape(6.dp)).border(2.dp, Honey, RoundedCornerShape(6.dp)).padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(if (game.alive) "PAUSED" else "NO ROOM LEFT", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
if (!game.alive && newBest) CastCheer()
if (!game.alive) Text(if (newBest) "New best: ${game.score}" else "Score: ${game.score}", color = Color.White, fontSize = 16.sp)
OrbitButton(if (game.alive) "Carry on" else "Play again", Modifier.width(200.dp).focusRequester(menuFocus), onClick = {
if (!game.alive) game = BlastGame.start(random)
paused = false
})
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = onLeave)
}
}
}
}
@@ -0,0 +1,214 @@
package tv.orbit.classic
import android.view.KeyEvent
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.material3.Text
/**
* Skydoku (Paul, 5 November 2026): a 6×6 sudoku with the six cast faces instead of numbers. Every row, every column and every
* 2×3 box holds each of Ollie, Blaze, Zip, Drift, Luna and Bumble once. Each puzzle is made fresh and has exactly one answer.
* Easy leaves plenty of faces in place; Harder takes away as many as it can. Clashes are ringed, never flashed.
*/
internal const val SKY_SIZE = 6
private const val SKY_BOX_ROWS = 2
private const val SKY_BOX_COLUMNS = 3
internal fun skyPeers(i: Int): Set<Int> {
val r = i / SKY_SIZE; val c = i % SKY_SIZE
val br = r / SKY_BOX_ROWS * SKY_BOX_ROWS; val bc = c / SKY_BOX_COLUMNS * SKY_BOX_COLUMNS
return ((0 until SKY_SIZE).map { r * SKY_SIZE + it } + (0 until SKY_SIZE).map { it * SKY_SIZE + c } +
(0 until SKY_BOX_ROWS).flatMap { dr -> (0 until SKY_BOX_COLUMNS).map { dc -> (br + dr) * SKY_SIZE + bc + dc } }).toSet() - i
}
/** How many answers [cells] has, counting no further than [limit]. */
internal fun skySolutions(cells: IntArray, limit: Int = 2): Int {
val i = cells.indexOfFirst { it == 0 }
if (i < 0) return 1
var found = 0
for (v in 1..SKY_SIZE) {
if (skyPeers(i).any { cells[it] == v }) continue
cells[i] = v
found += skySolutions(cells, limit - found)
cells[i] = 0
if (found >= limit) break
}
return found
}
private fun skyFill(cells: IntArray, random: java.util.Random): Boolean {
val i = cells.indexOfFirst { it == 0 }
if (i < 0) return true
for (v in (1..SKY_SIZE).shuffled(random)) {
if (skyPeers(i).any { cells[it] == v }) continue
cells[i] = v
if (skyFill(cells, random)) return true
cells[i] = 0
}
return false
}
internal enum class SkyLevel(val label: String, val keep: Int) { Easy("Easy", 20), Harder("Harder", 0) }
internal class SkyGame(val solution: IntArray, val givens: Set<Int>, val cells: IntArray, val cursor: Int = 0, val level: SkyLevel = SkyLevel.Easy) {
val done get() = cells.contentEquals(solution)
/** Squares whose face appears again in their row, column or box. */
val clashes get() = cells.indices.filter { i -> cells[i] != 0 && skyPeers(i).any { cells[it] == cells[i] } }.toSet()
fun move(dx: Int, dy: Int) = SkyGame(solution, givens, cells, ((cursor / SKY_SIZE + dy).coerceIn(0, SKY_SIZE - 1)) * SKY_SIZE + (cursor % SKY_SIZE + dx).coerceIn(0, SKY_SIZE - 1), level)
/** Puts a face (1 to 6) in the cursor's square, or clears it (0). The faces you were given stay put. */
fun put(v: Int): SkyGame {
if (cursor in givens || done) return this
return SkyGame(solution, givens, cells.copyOf().also { it[cursor] = v }, cursor, level)
}
companion object {
fun make(random: java.util.Random, level: SkyLevel): SkyGame {
val solution = IntArray(SKY_SIZE * SKY_SIZE)
skyFill(solution, random)
val puzzle = solution.copyOf()
// Take faces away one at a time, keeping only those removals that leave a single answer.
for (i in puzzle.indices.shuffled(random)) {
if (puzzle.count { it != 0 } <= level.keep) break
val v = puzzle[i]; puzzle[i] = 0
if (skySolutions(puzzle.copyOf()) != 1) puzzle[i] = v
}
val givens = puzzle.indices.filter { puzzle[it] != 0 }.toSet()
return SkyGame(solution, givens, puzzle, puzzle.indexOfFirst { it == 0 }.coerceAtLeast(0), level)
}
}
}
private val Marquee = FontFamily(Font(R.font.anton_regular))
private val Honey = Color(0xFFFFD84A)
/** One of the six faces, 1 to 6, drawn to the cast's model sheet. */
internal fun DrawScope.drawSkyFace(v: Int, centre: Offset, r: Float) = when (v) {
1 -> drawOrbMascot(centre, r * .75f)
2 -> drawOrbChaser(centre, r * .85f, OrbCharacter.Blaze, OrbDir.Down, false, false, false, 0f)
3 -> drawOrbChaser(centre, r * .82f, OrbCharacter.Zip, OrbDir.Down, false, false, false, 0f)
4 -> drawOrbChaser(centre, r * .85f, OrbCharacter.Drift, OrbDir.Down, false, false, false, 0f)
5 -> drawOrbChaser(centre, r * .85f, OrbCharacter.Luna, OrbDir.Down, false, false, false, 0f)
6 -> drawOrbBee(centre + Offset(0f, r * .15f), r * .62f)
else -> {}
}
internal val SkyNames = listOf("Ollie", "Blaze", "Zip", "Drift", "Luna", "Bumble")
@Composable
internal fun SkydokuScreen(solved: Int, onSolved: () -> Unit, onLeave: () -> Unit) {
val random = remember { java.util.Random() }
var level by remember { mutableStateOf(SkyLevel.Easy) }
var game by remember { mutableStateOf(SkyGame.make(random, level)) }
var picking by remember { mutableStateOf<Int?>(null) }
var paused by remember { mutableStateOf(false) }
val focus = remember { FocusRequester() }
val menuFocus = remember { FocusRequester() }
LaunchedEffect(game.done) { if (game.done) onSolved() }
LaunchedEffect(paused, game.done) { if (paused || game.done) menuFocus.requestFocus() else focus.requestFocus() }
BackHandler { if (picking != null) picking = null else if (!game.done) paused = !paused else onLeave() }
Row(Modifier.fillMaxSize().background(Navy).padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
val native = event.nativeKeyEvent
if (native.action != KeyEvent.ACTION_DOWN || paused || game.done) return@onPreviewKeyEvent false
val typed = if (native.keyCode in KeyEvent.KEYCODE_0..KeyEvent.KEYCODE_6) native.keyCode - KeyEvent.KEYCODE_0 else null
if (typed != null) { game = game.put(typed); picking = null; return@onPreviewKeyEvent true }
// Choosing a face: a row of the six and a blank, under the board.
picking?.let { choice ->
when (native.keyCode) {
KeyEvent.KEYCODE_DPAD_LEFT -> picking = (choice - 1).coerceAtLeast(0)
KeyEvent.KEYCODE_DPAD_RIGHT -> picking = (choice + 1).coerceAtMost(SKY_SIZE)
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> { game = game.put(if (choice == SKY_SIZE) 0 else choice + 1); picking = null }
KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN -> picking = null
else -> return@onPreviewKeyEvent false
}
return@onPreviewKeyEvent true
}
when (native.keyCode) {
KeyEvent.KEYCODE_DPAD_LEFT -> game = game.move(-1, 0)
KeyEvent.KEYCODE_DPAD_RIGHT -> game = game.move(1, 0)
KeyEvent.KEYCODE_DPAD_UP -> game = game.move(0, -1)
KeyEvent.KEYCODE_DPAD_DOWN -> game = game.move(0, 1)
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> if (game.cursor !in game.givens) picking = (game.cells[game.cursor] - 1).let { if (it < 0) 0 else it }
else -> return@onPreviewKeyEvent false
}
true
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
Column(Modifier.width(190.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Text("SKYDOKU", color = Honey, fontFamily = Marquee, fontSize = 32.sp)
Text(game.level.label.uppercase(), color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
Spacer(Modifier.height(8.dp))
Text("Every row, column and box has each face once.", color = Color.White, fontSize = 14.sp)
Text("SOLVED", color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp, modifier = Modifier.padding(top = 8.dp))
Text(solved.toString(), color = Color.White, fontFamily = Marquee, fontSize = 30.sp)
Spacer(Modifier.weight(1f))
Text("◄►▲▼ Move", color = Muted, fontSize = 13.sp)
Text("OK Choose a face", color = Muted, fontSize = 13.sp)
Text("1 to 6 also work, 0 clears", color = Muted, fontSize = 13.sp)
Text("Back Pause", color = Muted, fontSize = 13.sp)
}
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp)) {
val clashes = game.clashes
Canvas(Modifier.weight(1f).aspectRatio(1f)) {
val cell = size.minDimension / SKY_SIZE
for (i in 0 until SKY_SIZE * SKY_SIZE) {
val at = Offset(i % SKY_SIZE * cell, i / SKY_SIZE * cell)
val given = i in game.givens
drawRoundRect(if (given) Color(0xFF0E2560) else Color(0xFF16357A), at + Offset(cell * .04f, cell * .04f), Size(cell * .92f, cell * .92f), CornerRadius(cell * .14f))
if (game.cells[i] != 0) drawSkyFace(game.cells[i], at + Offset(cell / 2, cell / 2), cell * .36f)
if (i in clashes && !given) drawRoundRect(Color(0xFFFF6B6B), at + Offset(cell * .07f, cell * .07f), Size(cell * .86f, cell * .86f), CornerRadius(cell * .12f), style = Stroke(cell * .05f))
}
// The 2×3 boxes.
for (k in 0..SKY_SIZE / SKY_BOX_COLUMNS) drawLine(Muted.copy(alpha = .6f), Offset(k * SKY_BOX_COLUMNS * cell, 0f), Offset(k * SKY_BOX_COLUMNS * cell, size.height), cell * .04f)
for (k in 0..SKY_SIZE / SKY_BOX_ROWS) drawLine(Muted.copy(alpha = .6f), Offset(0f, k * SKY_BOX_ROWS * cell), Offset(size.width, k * SKY_BOX_ROWS * cell), cell * .04f)
if (!game.done) {
val at = Offset(game.cursor % SKY_SIZE * cell, game.cursor / SKY_SIZE * cell)
drawRoundRect(Yellow, at + Offset(cell * .03f, cell * .03f), Size(cell * .94f, cell * .94f), CornerRadius(cell * .14f), style = Stroke(cell * .07f))
}
}
// The faces to choose from, with a blank to clear.
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
for (k in 0..SKY_SIZE) {
val on = picking == k
val corner = RoundedCornerShape(8.dp)
Column(Modifier.size(64.dp, 72.dp).background(if (on) Navy else Panel, corner).border(if (on) 3.dp else 0.dp, if (on) Yellow else Color.Transparent, corner),
horizontalAlignment = Alignment.CenterHorizontally) {
Canvas(Modifier.size(48.dp)) { if (k < SKY_SIZE) drawSkyFace(k + 1, center, size.minDimension * .36f) else drawCircle(Muted.copy(alpha = .5f), size.minDimension * .3f, center, style = Stroke(3f)) }
Text(if (k < SKY_SIZE) SkyNames[k] else "Clear", color = if (picking == null) Muted.copy(alpha = .6f) else Color.White, fontSize = 10.sp)
}
}
}
}
if (paused || game.done) Column(Modifier.background(Navy, RoundedCornerShape(6.dp)).border(2.dp, Honey, RoundedCornerShape(6.dp)).padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(if (game.done) "SOLVED!" else "PAUSED", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
if (game.done) CastCheer()
if (!game.done) OrbitButton("Carry on", Modifier.width(220.dp).focusRequester(menuFocus), onClick = { paused = false })
for (choice in SkyLevel.entries) OrbitButton("New puzzle: ${choice.label}", Modifier.width(220.dp).then(if (game.done && choice == level) Modifier.focusRequester(menuFocus) else Modifier), onClick = {
level = choice; game = SkyGame.make(random, choice); picking = null; paused = false
})
OrbitButton("Leave the game", Modifier.width(220.dp), onClick = onLeave)
}
}
}
}
@@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
connection.connectTimeout = 10_000
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.29\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.30\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -308,6 +308,8 @@ private fun OrbitHiveScreen(onLeave: () -> Unit) {
private enum class ArcadeGame(val title: String, val tagline: String, val blurb: String) {
// Paul, 5 November 2026: the Tots mascot is Ollie, so the game is renamed around the mascot, and OrbitHive becomes BumbleHive after its bee.
OrbMan("Star Chase", "Maze chase starring Ollie", "Help Ollie clear the stars, and dodge Blaze, Zip, Drift and Luna."),
Blast("Blast Off", "Fit the shapes, clear the lines", "Fit three shapes at a time on the board; full rows and columns clear. No room left and it's over."),
Sky("Skydoku", "The cast's own sudoku", "Every row, column and box holds each of the six cast once. Easy or Harder, always one answer."),
Hive("BumbleHive", "Link, match, clear the hive", "Help Bumble fire flowers into the honeycomb, and clear the hive before it reaches you."),
Snake("Snake", "Grow, turn, beat your best", "Eat, grow, and don't hit the walls or yourself."),
Blocks("Block Drop", "Stack the blocks, keep it tidy", "Turn and drop the falling blocks, and clear full rows before the stack reaches the top."),
@@ -325,6 +327,11 @@ private fun androidx.compose.ui.graphics.drawscope.DrawScope.gameIcon(game: Arca
when (game) {
ArcadeGame.OrbMan -> drawOrbMascot(c, s * .28f)
ArcadeGame.Hive -> drawOrbBee(c + Offset(0f, s * .12f), s * .26f)
ArcadeGame.Blast -> { val b = s * .2f
listOf(Triple(-1f, -1f, 0), Triple(0f, -1f, 0), Triple(-1f, 0f, 0), Triple(0f, 0f, 1), Triple(1f, 0f, 1), Triple(0f, 1f, 2), Triple(1f, 1f, 3))
.forEach { (x, y, k) -> drawRoundRect(BlastColours[k], c + Offset(x * b - b / 2 + 1, y * b - b / 2 + 1), Size(b - 2, b - 2), androidx.compose.ui.geometry.CornerRadius(b * .2f)) } }
ArcadeGame.Sky -> { val b = s * .3f
for (i in 0..3) { val at = c + Offset((i % 2 - .5f) * b * 1.1f, (i / 2 - .5f) * b * 1.1f); drawRoundRect(Color(0xFF16357A), at - Offset(b / 2, b / 2), Size(b, b), androidx.compose.ui.geometry.CornerRadius(b * .15f)); drawSkyFace(listOf(1, 3, 5, 6)[i], at, b * .34f) } }
ArcadeGame.Snake -> {
listOf(-.32f, -.16f, 0f).forEachIndexed { i, x -> drawCircle(Color(0xFF3DDC97), s * .1f, c + Offset(x * s, (if (i % 2 == 0) .12f else .04f) * s)) }
val head = c + Offset(.2f * s, -.06f * s)
@@ -363,11 +370,11 @@ private fun GameCard(game: ArcadeGame, modifier: Modifier, focus: FocusRequester
.onFocusChanged { focused = it.isFocused; if (it.isFocused) onFocus() }
.background(if (focused) Navy else Panel, corner).border(if (focused) 3.dp else 1.dp, if (focused) Yellow else Blue, corner)
.clickable(onClick = onPlay).padding(horizontal = 10.dp, vertical = 6.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Canvas(Modifier.size(42.dp)) { gameIcon(game) }
Canvas(Modifier.size(34.dp)) { gameIcon(game) }
Box(Modifier.width(1.dp).fillMaxHeight(.7f).background(Muted.copy(alpha = .4f)))
Column(verticalArrangement = Arrangement.spacedBy(1.dp)) {
Text(game.title.uppercase().takeIf { game == ArcadeGame.OrbMan } ?: game.title, color = Color.White, fontFamily = Marquee, fontSize = 18.sp, maxLines = 1)
Text(game.tagline, color = Muted, fontSize = 11.sp, maxLines = 2, lineHeight = 13.sp)
Text(game.tagline, color = Muted, fontSize = 11.sp, maxLines = 1)
}
}
}
@@ -383,6 +390,8 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
var pairsBest by remember { mutableIntStateOf(settings.pairsBest) }
var patienceWins by remember { mutableIntStateOf(settings.patienceWins) }
var orbBest by remember { mutableIntStateOf(settings.orbManBest) }
var blastBest by remember { mutableIntStateOf(settings.blastBest) }
var skySolved by remember { mutableIntStateOf(settings.skydokuSolved) }
var recent by remember { mutableStateOf(settings.recentGames.mapNotNull { name -> ArcadeGame.entries.firstOrNull { it.name == name } }) }
var playing by remember { mutableStateOf<ArcadeGame?>(null) }
var chosen by remember { mutableStateOf(ArcadeGame.OrbMan) }
@@ -396,6 +405,8 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
ArcadeGame.OrbMan -> { OrbManScreen(orbBest, onBest = { orbBest = it; settings.orbManBest = it }, onLeave = { playing = null }); return }
ArcadeGame.Snake -> { SnakeScreen(best, onBest = { best = it; settings.snakeBest = it }, onLeave = { playing = null }); return }
ArcadeGame.Hive -> { OrbitHiveScreen(onLeave = { playing = null }); return }
ArcadeGame.Blast -> { BlastOffScreen(blastBest, onBest = { blastBest = it; settings.blastBest = it }, onLeave = { playing = null }); return }
ArcadeGame.Sky -> { SkydokuScreen(skySolved, onSolved = { skySolved += 1; settings.skydokuSolved = skySolved }, onLeave = { playing = null }); return }
ArcadeGame.Pairs -> { PairsScreen(pairsBest, onBest = { pairsBest = it; settings.pairsBest = it }, onLeave = { playing = null }); return }
ArcadeGame.Patience -> { PatienceScreen(patienceWins, onWin = { patienceWins += 1; settings.patienceWins = patienceWins }, onLeave = { playing = null }); return }
ArcadeGame.Bricks -> { BrickBreakScreen(brickBest, onBest = { brickBest = it; settings.brickBreakBest = it }, onLeave = { playing = null }); return }
@@ -410,6 +421,8 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
ArcadeGame.Pairs -> pairsBest.takeIf { it > 0 }?.let { "$it moves" }
ArcadeGame.Patience -> patienceWins.takeIf { it > 0 }?.let { "$it won" }
ArcadeGame.Hive -> null
ArcadeGame.Blast -> blastBest.takeIf { it > 0 }?.let { "%,d".format(it) }
ArcadeGame.Sky -> skySolved.takeIf { it > 0 }?.let { "$it solved" }
}
val first = remember { FocusRequester() }
LaunchedEffect(Unit) { first.requestFocus() }
@@ -425,6 +438,11 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
val chasers = g.chasers.mapIndexed { i, c -> val p = listOf(OrbPos(5, 1), OrbPos(17, 3), OrbPos(14, 11), OrbPos(3, 8))[i]; c.copy(mover = OrbMover(p, p, OrbDir.Left), out = true) }
g.copy(player = OrbMover(OrbPos(9, 8), OrbPos(9, 8), OrbDir.Right), chasers = chasers, stars = g.stars.filter { it.y != 3 || it.x > 9 }.toSet(), readyLeft = 0)
}
val blastPreview = remember {
val rows = listOf("..##....", "..##....", ".....###", "#....###", "##..####", "###.####", "####.###", "#######.")
BlastGame(rows.mapIndexed { y, row -> row.mapIndexed { x, ch -> if (ch == '#') 1 + (x * 2 + y * 3) % BlastColours.size else 0 } }, BlastGame.deal(java.util.Random(3)), 0, 0, 0)
}
val skyPreview = remember { SkyGame.make(java.util.Random(8), SkyLevel.Easy) }
var clock by remember { mutableLongStateOf(0L) }
LaunchedEffect(chosen) { if (chosen == ArcadeGame.OrbMan) while (true) { withFrameNanos { clock = it / 1_000_000 } } }
Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
@@ -456,6 +474,15 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
drawRoundRect(if (down) Blue else BlockColours[i % BlockColours.size], at, Size(w, h), androidx.compose.ui.geometry.CornerRadius(w * .1f), style = Stroke(w * .05f))
}
}
ArcadeGame.Blast -> Canvas(Modifier.fillMaxSize().padding(6.dp)) { drawBlastBoard(blastPreview, showPiece = false) }
ArcadeGame.Sky -> Canvas(Modifier.fillMaxSize().padding(10.dp)) {
val cell = size.minDimension / SKY_SIZE; val left = (size.width - cell * SKY_SIZE) / 2
for (i in 0 until SKY_SIZE * SKY_SIZE) {
val at = Offset(left + i % SKY_SIZE * cell, i / SKY_SIZE * cell)
drawRoundRect(Color(0xFF16357A), at + Offset(cell * .05f, cell * .05f), Size(cell * .9f, cell * .9f), androidx.compose.ui.geometry.CornerRadius(cell * .14f))
if (skyPreview.cells[i] != 0) drawSkyFace(skyPreview.cells[i], at + Offset(cell / 2, cell / 2), cell * .34f)
}
}
ArcadeGame.Hive -> Canvas(Modifier.fillMaxSize()) {
val colours = listOf(Color(0xFFE53935), Color(0xFF1E66D0), Color(0xFF2E9D3A), Color(0xFFF4F4F4), Color(0xFFF5A623), Color(0xFF8E44AD))
val r = size.height / 9
@@ -475,9 +502,9 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
}
}
// Every game, two to a row, then what you played last.
Column(Modifier.weight(1f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(7.dp)) {
Column(Modifier.weight(1f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
ArcadeGame.entries.chunked(2).forEachIndexed { row, pair ->
Row(Modifier.fillMaxWidth().height(56.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Row(Modifier.fillMaxWidth().height(48.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
pair.forEachIndexed { i, game ->
GameCard(game, Modifier.weight(1f).fillMaxHeight(), if (row == 0 && i == 0) first else null, if (row == 0) nav else null, { chosen = game }, { play(game) })
}
@@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.108.29")
next.setRequestProperty("User-Agent", "OrbitTV/0.108.30")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
@@ -60,6 +60,12 @@ internal class OrbitSettings(context: Context) {
var orbManBest: Int
get() = saved.getInt("orb_man_best", 0)
set(value) { saved.edit().putInt("orb_man_best", value).apply() }
var blastBest: Int
get() = saved.getInt("blast_best", 0)
set(value) { saved.edit().putInt("blast_best", value).apply() }
var skydokuSolved: Int
get() = saved.getInt("skydoku_solved", 0)
set(value) { saved.edit().putInt("skydoku_solved", value).apply() }
var orbManSound: Boolean
get() = saved.getBoolean("orb_man_sound", true)
set(value) { saved.edit().putBoolean("orb_man_sound", value).apply() }
@@ -0,0 +1,68 @@
package tv.orbit.classic
import org.junit.Assert.*
import org.junit.Test
class CastGamesTest {
private val random = java.util.Random(4)
private val one = BlastPiece(BlastShapes.first { it.cells.size == 1 }, 0)
private val big = BlastPiece(BlastShapes.first { it.cells.size == 9 }, 1)
private fun board(filled: (Int, Int) -> Boolean) = List(BLAST_SIZE) { r -> List(BLAST_SIZE) { c -> if (filled(r, c)) 1 else 0 } }
@Test fun blastOffPlacesClearsAndScores() {
// Row 0 full but one square: a single square in the gap clears it.
val after = BlastGame(board { r, c -> r == 0 && c != 5 }, listOf(one, one, one), 0, 5, 0).press(random)
assertTrue(after.board[0].all { it == 0 })
assertEquals(1, after.lastCleared); assertEquals(1 + 10, after.score)
assertNull(after.tray[0]); assertEquals(1, after.selected)
// A row and a column at once is a combo: ten for each, times two.
assertEquals(1 + 40, BlastGame(board { r, c -> (r == 2) != (c == 2) }, listOf(one, one, one), 0, 2, 2).press(random).score)
// A shape that doesn't fit isn't placed.
val blocked = BlastGame(board { r, c -> r == 3 && c == 3 }, listOf(one, one, one), 0, 3, 3)
assertSame(blocked, blocked.press(random))
}
@Test fun blastOffEndsWhenNothingFits() {
// Scattered single holes, one in every row and column: the single fills one without completing a line, and the big squares
// have nowhere to go.
val holey = board { r, c -> !((r % 2 == 1 && c % 2 == 1) || (r % 2 == 0 && r == c)) }
val after = BlastGame(holey, listOf(one, big, big), 0, 1, 1).press(random)
assertEquals(0, after.lastCleared)
assertFalse(after.alive)
assertTrue(BlastGame.start(random).alive)
}
@Test fun blastOffMovesStayOnTheBoardAndReachTheTray() {
var g = BlastGame.start(random)
repeat(20) { g = g.move(1, 0) }
assertEquals(BLAST_SIZE - g.piece!!.shape.width, g.x)
repeat(20) { g = g.move(0, 1) }
assertTrue(g.inTray)
g = g.move(1, 0); assertEquals(1, g.selected)
g = g.move(0, -1); assertFalse(g.inTray)
}
@Test fun skydokuPuzzlesHaveOneAnswerAndCanBeSolved() {
for (level in SkyLevel.entries) {
val g = SkyGame.make(random, level)
assertEquals(1, skySolutions(g.cells.copyOf()))
assertTrue(g.solution.indices.all { i -> skyPeers(i).none { g.solution[it] == g.solution[i] } })
assertTrue(g.givens.all { g.cells[it] == g.solution[it] })
if (level == SkyLevel.Easy) assertTrue(g.givens.size >= 20) else assertTrue(g.givens.size < 20)
var x = g
for (i in g.cells.indices) if (i !in g.givens) x = SkyGame(x.solution, x.givens, x.cells, i, level).put(x.solution[i])
assertTrue(x.done)
// The faces you were given stay put.
val given = SkyGame(g.solution, g.givens, g.cells, g.givens.first())
assertSame(given, given.put(0))
}
}
@Test fun skydokuRingsClashes() {
val g = SkyGame.make(random, SkyLevel.Easy)
val free = g.cells.indices.first { it !in g.givens }
val peerFace = skyPeers(free).map { g.cells[it] }.first { it != 0 }
assertTrue(free in SkyGame(g.solution, g.givens, g.cells, free).put(peerFace).clashes)
assertTrue(SkyGame(g.solution, g.givens, g.cells, free).put(g.solution[free]).clashes.isEmpty())
}
}