diff --git a/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt b/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt index 5e1c57b2..22932b72 100644 --- a/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt +++ b/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt @@ -17,6 +17,7 @@ import tv.orbit.classic.arcade.classicPace import tv.orbit.classic.arcade.classicPanel import tv.orbit.classic.arcade.gameKeys import tv.orbit.classic.arcade.previousLine +import tv.orbit.classic.arcade.SpeechBubble import tv.orbit.classic.arcade.BLOCKS_SPRINT_SCORES import tv.orbit.classic.arcade.ArcadePlay @@ -57,6 +58,21 @@ import androidx.tv.material3.Text * none is starved; full rows clear for points that grow with the level, and the level rises every ten rows. Orbit's own look. */ internal const val BLOCK_COLUMNS = 10 +/** Broadcast's board values: a channel's block (plus 0 to 3), and interference's static. Classic uses 1 to 7, a shape each. */ +internal const val CHANNEL_BLOCK = 11 +internal const val STATIC_BLOCK = 20 +internal const val CHANNEL_BONUS = 250 +internal const val FREEZE_MS = 8_000L + +/** Broadcast's five power-ups, in the order they're earned. */ +internal enum class BlockPower(val title: String) { SignalBomb("Signal Bomb"), Rewind("Rewind"), Freeze("Freeze"), Tuner("Tuner"), ClearPicture("Clear Picture") } + +/** A board value's colour: a shape's, a channel's (Orbit 1, Riot, Tots, Terra), or static grey. */ +internal fun blockColour(v: Int): Color = when { + v >= STATIC_BLOCK -> Color(0xFF6A7390) + v >= CHANNEL_BLOCK -> OrbitSuits[v - CHANNEL_BLOCK].second + else -> BlockColours[v - 1] +} internal const val BLOCK_ROWS = 20 /** Each shape's cells in its own box, unturned; turning rotates them a quarter within that box. */ @@ -82,7 +98,17 @@ internal data class BlockPiece(val kind: Int, val turns: Int, val x: Int, val y: } /** The board as rows of colours (0 empty, otherwise the shape's kind + 1), the falling piece, the next, and the score. */ -internal data class BlockGame(val board: List, val piece: BlockPiece, val next: Int, val bag: List, val score: Int = 0, val lines: Int = 0, val alive: Boolean = true) { +internal data class BlockGame(val board: List, val piece: BlockPiece, val next: Int, val bag: List, val score: Int = 0, val lines: Int = 0, val alive: Boolean = true, + /** Broadcast (Phase 2): each piece is one channel's colour; this piece's and the next's. Classic leaves all of these alone. */ + val broadcast: Boolean = false, val chan: Int = 0, val nextChan: Int = 0, + /** Channel Bonuses towards the next power-up (three charge one), and how many power-ups so far. */ + val charge: Int = 0, val powers: Int = 0, + /** What the last piece did: its Channel Bonus rows and the power-up it set off, for the screen to show. */ + val lastBonus: Int = 0, val lastPower: BlockPower? = null, + /** Freeze's gravity hold, in ms, counted down by the screen. */ + val freezeMs: Long = 0, + /** Wind Down: no game over; a full stack fades and play goes on. */ + val windDown: Boolean = false, val fades: Int = 0) { val level get() = lines / 10 + 1 /** Gravity's pace, quickening with each level and never faster than 90 ms a row. */ val tickMs: Long get() = maxOf(90L, 800L - (level - 1) * 70L) @@ -120,18 +146,72 @@ internal data class BlockGame(val board: List, val piece: BlockPiece, private fun lock(random: java.util.Random): BlockGame { val rows = board.map { it.copyOf() } var above = false - piece.cells().forEach { (x, y) -> if (y < 0) above = true else rows[y][x] = piece.kind + 1 } + piece.cells().forEach { (x, y) -> if (y < 0) above = true else rows[y][x] = if (broadcast) CHANNEL_BLOCK + chan else piece.kind + 1 } + // Broadcast: a cleared row where four or more blocks share a channel is a Channel Bonus. + val full = rows.filter { row -> row.none { it == 0 } } + val fullAt = rows.indices.filter { y -> rows[y].none { it == 0 } } + val bonus = if (broadcast) full.count { row -> (0 until 4).any { c -> row.count { it == CHANNEL_BLOCK + c } >= 4 } } else 0 val kept = rows.filter { row -> row.any { it == 0 } } val cleared = BLOCK_ROWS - kept.size - val board2 = List(cleared) { IntArray(BLOCK_COLUMNS) } + kept - val points = listOf(0, 100, 300, 500, 800)[cleared] * level + var board2 = List(cleared) { IntArray(BLOCK_COLUMNS) } + kept + val points = listOf(0, 100, 300, 500, 800)[cleared.coerceAtMost(4)] * level + bonus * CHANNEL_BONUS * level val (nextKind, bag2) = draw(bag, random) val spawned = spawn(next) - val game = copy(board = board2, piece = spawned, next = nextKind, bag = bag2, score = score + points, lines = lines + cleared) - return if (above || !game.fits(spawned)) game.copy(alive = false) else game + var game = copy(board = board2, piece = spawned, next = nextKind, bag = bag2, score = score + points, lines = lines + cleared, + chan = nextChan, nextChan = if (broadcast) random.nextInt(4) else 0, lastBonus = bonus, lastPower = null) + // Three Channel Bonuses charge a power-up, which goes off at once (the remote has no spare button to hold it on). + if (broadcast && bonus > 0) { + var charge2 = charge + bonus; var powers2 = powers + while (charge2 >= 3) { charge2 -= 3; game = game.power(BlockPower.entries[powers2 % BlockPower.entries.size], piece, fullAt); powers2++ } + game = game.copy(charge = charge2, powers = powers2) + } + if (above || !game.fits(game.piece)) { + // Wind Down never ends: the stack fades away and play goes on. + return if (windDown) game.copy(board = List(BLOCK_ROWS) { IntArray(BLOCK_COLUMNS) }, fades = fades + 1) else game.copy(alive = false) + } + return game + } + + /** A power-up going off ([landed] is the piece that earned it). */ + internal fun power(p: BlockPower, landed: BlockPiece, clearedRows: List = emptyList()): BlockGame { + val rows = board.map { it.copyOf() } + return when (p) { + BlockPower.SignalBomb -> { + // Clears the 3 by 3 round where the piece landed. + val (cx, cy) = landed.cells().let { c -> c.sumOf { it.first } / c.size to c.sumOf { it.second } / c.size } + for (y in cy - 1..cy + 1) for (x in cx - 1..cx + 1) if (y in 0 until BLOCK_ROWS && x in 0 until BLOCK_COLUMNS) rows[y][x] = 0 + copy(board = rows, lastPower = p) + } + BlockPower.Rewind -> { + // Takes back what's left of the piece that just landed: each of its blocks not in a cleared row, moved down + // by the cleared rows below it. + landed.cells().forEach { (x, y) -> + if (y !in 0 until BLOCK_ROWS || y in clearedRows) return@forEach + val now = y + clearedRows.count { it > y } + if (now in 0 until BLOCK_ROWS && rows[now][x] >= CHANNEL_BLOCK) rows[now][x] = 0 + } + copy(board = rows, lastPower = p) + } + BlockPower.Freeze -> copy(freezeMs = FREEZE_MS, lastPower = p) + BlockPower.Tuner -> copy(next = 0, lastPower = p) + BlockPower.ClearPicture -> copy(board = listOf(IntArray(BLOCK_COLUMNS)) + board.dropLast(1), lastPower = p) + } + } + + /** Interference (Broadcast on Tricky): a row of static pushes up from the bottom, one gap in it. Off the top is game over. */ + fun interfere(random: java.util.Random): BlockGame { + if (!alive) return this + if (board.first().any { it != 0 }) return copy(alive = false) + val gap = random.nextInt(BLOCK_COLUMNS) + val raised = board.drop(1) + IntArray(BLOCK_COLUMNS) { if (it == gap) 0 else STATIC_BLOCK } + val g = copy(board = raised) + return if (!g.fits(piece)) g.copy(piece = piece.copy(y = piece.y - 1)).let { if (it.fits(it.piece)) it else g.copy(alive = false) } else g } companion object { + /** A Broadcast game: channel colours on, the first two pieces' channels drawn. */ + fun broadcastStart(random: java.util.Random) = start(random).copy(broadcast = true, chan = random.nextInt(4), nextChan = random.nextInt(4)) + fun windDownStart(random: java.util.Random) = start(random).copy(windDown = true) fun spawn(kind: Int) = BlockPiece(kind, 0, (BLOCK_COLUMNS - ShapeCells[kind].first) / 2, if (kind == 0) -1 else 0) /** The next shape from a shuffled bag of all seven, refilled when empty. */ fun draw(bag: List, random: java.util.Random): Pair> { @@ -161,26 +241,33 @@ internal fun BlockField(game: BlockGame, modifier: Modifier) = Canvas(modifier) drawRect(ArcadeColours.Night, origin, Size(size * BLOCK_COLUMNS, size * BLOCK_ROWS)) for (y in 0 until BLOCK_ROWS) for (x in 0 until BLOCK_COLUMNS) { val v = game.board[y][x] - if (v > 0) cell(x, y, size, origin, BlockColours[v - 1]) else drawRect(ArcadeColours.Panel, Offset(origin.x + x * size + size * .45f, origin.y + y * size + size * .45f), Size(size * .1f, size * .1f)) + if (v > 0) cell(x, y, size, origin, blockColour(v)) else drawRect(ArcadeColours.Panel, Offset(origin.x + x * size + size * .45f, origin.y + y * size + size * .45f), Size(size * .1f, size * .1f)) } if (game.alive) { - game.landing().cells().forEach { (x, y) -> if (y >= 0) cell(x, y, size, origin, BlockColours[game.piece.kind], .22f) } - game.piece.cells().forEach { (x, y) -> if (y >= 0) cell(x, y, size, origin, BlockColours[game.piece.kind]) } + val colour = if (game.broadcast) OrbitSuits[game.chan].second else BlockColours[game.piece.kind] + game.landing().cells().forEach { (x, y) -> if (y >= 0) cell(x, y, size, origin, colour, .22f) } + game.piece.cells().forEach { (x, y) -> if (y >= 0) cell(x, y, size, origin, colour) } } } @Composable -private fun NextPiece(kind: Int, modifier: Modifier) = Canvas(modifier) { +private fun NextPiece(kind: Int, modifier: Modifier, colour: Color? = null) = Canvas(modifier) { val size = this.size.minDimension / 4 val cells = shapeCells(kind, 0) val w = cells.maxOf { it.first } + 1; val h = cells.maxOf { it.second } + 1 val origin = Offset((this.size.width - w * size) / 2, (this.size.height - h * size) / 2) - cells.forEach { (x, y) -> cell(x, y, size, origin, BlockColours[kind]) } + cells.forEach { (x, y) -> cell(x, y, size, origin, colour ?: BlockColours[kind]) } } /** Block Drop's Challenge (Phase 2, 9 November 2026): 40 lines as fast as you can, in its own High Scores (fewest centiseconds). */ internal const val SPRINT_LINES = 40 +/** Block Drop's ways to play: each new one separate, with its own High Scores; Classic untouched. */ +internal enum class BlockMode(val title: String, val table: String?) { + Classic("Classic", null), Sprint("40-Line Sprint", tv.orbit.classic.arcade.BLOCKS_SPRINT_SCORES), + Broadcast("Broadcast", tv.orbit.classic.arcade.BLOCKS_BROADCAST_SCORES), WindDown("Wind Down", tv.orbit.classic.arcade.BLOCKS_WINDDOWN_SCORES) +} + /** A sprint time, as the High Scores and the HUD show it: 1:23.45. */ internal fun sprintText(centis: Int) = "%d:%02d.%02d".format(centis / 6_000, centis / 100 % 60, centis % 100) @@ -193,9 +280,10 @@ internal fun BlockDropScreen(play: ArcadePlay) { var stage by remember { mutableStateOf(ClassicStage.Title) } var paused by remember { mutableStateOf(false) } var howTo by remember { mutableStateOf(false) } - // Classic, or the 40-line Sprint: chosen on the title, remembered, each with its own High Scores. - var sprint by remember { mutableStateOf(play.level["mode"] == "Sprint") } - val table = if (sprint) BLOCKS_SPRINT_SCORES else gameDef.id + // Classic, the 40-line Sprint, Broadcast or Wind Down: chosen on the title, remembered, each with its own High Scores. + var mode by remember { mutableStateOf(BlockMode.entries.firstOrNull { it.name == play.level["mode"] } ?: BlockMode.Classic) } + val sprint = mode == BlockMode.Sprint + val table = mode.table ?: gameDef.id var bestBefore by remember { mutableIntStateOf(play.bestIn(table)) } var centis by remember { mutableIntStateOf(0) } val focus = remember { FocusRequester() } @@ -206,14 +294,27 @@ internal fun BlockDropScreen(play: ArcadePlay) { fun pause() { paused = true; guard.reset() } PauseWhenHidden(stage == ClassicStage.Play && !paused) { pause() } // Gravity only while playing; Difficulty sets its pace (Normal as it always was). - LaunchedEffect(stage, paused, game.alive) { - while (stage == ClassicStage.Play && !paused && game.alive) { kotlinx.coroutines.delay((game.tickMs / pace).toLong()); game = game.fall(random = random) } + // Wind Down has none; Broadcast's Freeze holds it for a while. + LaunchedEffect(stage, paused, game.alive, mode) { + while (mode != BlockMode.WindDown && stage == ClassicStage.Play && !paused && game.alive) { + val wait = (game.tickMs / pace).toLong() + kotlinx.coroutines.delay(wait) + game = if (game.freezeMs > 0) game.copy(freezeMs = (game.freezeMs - wait).coerceAtLeast(0)) else game.fall(random = random) + } } + // Interference: on Tricky, Broadcast pushes up a row of static every 25 seconds. + LaunchedEffect(stage, paused, mode, game.alive) { + if (mode != BlockMode.Broadcast || play.difficulty != tv.orbit.classic.arcade.Difficulty.Tricky) return@LaunchedEffect + while (stage == ClassicStage.Play && !paused && game.alive) { kotlinx.coroutines.delay(25_000); game = game.interfere(random) } + } + // A power-up's name, for a moment after it goes off. + var powerNews by remember { mutableStateOf(null) } + LaunchedEffect(game.powers) { if (game.powers > 0 && game.lastPower != null) { powerNews = game.lastPower!!.title + "!"; kotlinx.coroutines.delay(2_000); powerNews = null } } // Classic saves its points; a Sprint saves its time, only when all 40 lines are cleared. - val run = rememberRun({ end -> if (sprint) latestPlay.onRunEndIn(BLOCKS_SPRINT_SCORES, end) else latestPlay.onRunEnd(end) }) { + val run = rememberRun({ end -> mode.table?.let { latestPlay.onRunEndIn(it, end) } ?: latestPlay.onRunEnd(end) }) { if (sprint) RunEnd(centis, finished = false, detail = "${game.lines} lines") else RunEnd(game.score, finished = false, detail = "Level ${game.level}") } - fun startRun() { bestBefore = latestPlay.bestIn(table); game = BlockGame.start(random); centis = 0; guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play } + fun startRun() { bestBefore = latestPlay.bestIn(table); game = when (mode) { BlockMode.Broadcast -> BlockGame.broadcastStart(random); BlockMode.WindDown -> BlockGame.windDownStart(random); else -> BlockGame.start(random) }; centis = 0; guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play } fun leave() { run.end(if (sprint) RunEnd(centis, finished = false, detail = "${game.lines} lines") else RunEnd(game.score, finished = !game.alive, detail = "Level ${game.level}")) latestPlay.onLeave() @@ -242,11 +343,16 @@ internal fun BlockDropScreen(play: ArcadePlay) { if (stage == ClassicStage.Title) { val best = play.bestIn(table) - ClassicTitle(gameDef, backdrop, OrbCharacter.Drift.colour, if (sprint) "Forty rows? I'm awake!" else "Stack them neatly… zzz", + ClassicTitle(gameDef, backdrop, OrbCharacter.Drift.colour, when (mode) { BlockMode.Sprint -> "Forty rows? I'm awake!"; BlockMode.Broadcast -> "On air in three, two…"; BlockMode.WindDown -> "Nice and slow… zzz"; else -> "Stack them neatly… zzz" }, listOf("Your best" to if (best <= 0) "Not played yet" else if (sprint) sprintText(best) else "%,d".format(best)), - timed = true, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, - mode = if (sprint) "40-Line Sprint" else "Classic", modes = 2, onMode = { sprint = !sprint; latestPlay.setLevel("mode", if (sprint) "Sprint" else "Classic") }, - note = if (sprint) "Clear 40 rows as fast as you can. The clock stops when you pause." else "Clear several rows at once for more; every ten rows the blocks fall faster.") + timed = mode != BlockMode.WindDown, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, + mode = mode.title, modes = BlockMode.entries.size, onMode = { mode = BlockMode.entries[(mode.ordinal + 1) % BlockMode.entries.size]; latestPlay.setLevel("mode", mode.name) }, + note = when (mode) { + BlockMode.Sprint -> "Clear 40 rows as fast as you can. The clock stops when you pause." + BlockMode.Broadcast -> "Every piece is one channel's colour. Clear a row with four or more of one channel for a Channel Bonus; three bonuses set off a power-up: Signal Bomb, Rewind, Freeze, Tuner and Clear Picture, in turn. On Tricky, static creeps up from below." + BlockMode.WindDown -> "No gravity and no game over: pieces fall only when you send them. If the stack reaches the top it fades away and you carry on." + else -> "Clear several rows at once for more; every ten rows the blocks fall faster." + }) if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false }) return } @@ -277,16 +383,25 @@ internal fun BlockDropScreen(play: ArcadePlay) { HudLabel("SCORE"); HudValue("%,d".format(game.score)) HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score))) Spacer(Modifier.height(6.dp)) - HudLabel("LEVEL"); HudValue("${game.level}") - HudLabel("ROWS ${game.lines}") + if (mode == BlockMode.WindDown) { HudLabel("ROWS ${game.lines}"); if (game.fades > 0) HudLabel("FADED ${game.fades}") } + else { HudLabel("LEVEL"); HudValue("${game.level}"); HudLabel("ROWS ${game.lines}") } + if (game.broadcast) { + Spacer(Modifier.height(6.dp)) + HudLabel("POWER-UP") + Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) { for (k in 0 until 3) Box(Modifier.size(22.dp, 10.dp).background(if (k < game.charge) ArcadeColours.Yellow else ArcadeColours.Panel, RoundedCornerShape(3.dp))) } + Text("Next: " + BlockPower.entries[game.powers % BlockPower.entries.size].title, color = ArcadeColours.Muted, fontSize = 14.sp) + if (game.freezeMs > 0) Text("Frozen ${(game.freezeMs + 999) / 1000} s", color = ArcadeColours.Cyan, fontSize = 14.sp, fontWeight = FontWeight.SemiBold) + } } + powerNews?.let { SpeechBubble(it) } Spacer(Modifier.weight(1f)) // Drift hosts (Paul, 6 November 2026), dozing beside the board. Canvas(Modifier.size(56.dp)) { drawOrbChaser(center, size.minDimension * .36f, OrbCharacter.Drift, OrbDir.Down, scared = false, returning = false, blink = false, wobble = 0f, eyesShut = true) } }, side = { HudLabel("NEXT") - NextPiece(game.next, Modifier.size(110.dp).classicPanel().padding(12.dp)) + NextPiece(game.next, Modifier.size(110.dp).classicPanel().padding(12.dp), if (game.broadcast) OrbitSuits[game.nextChan].second else null) + if (game.broadcast) Text(OrbitSuits[game.nextChan].first, color = OrbitSuits[game.nextChan].second, fontSize = 14.sp, fontWeight = FontWeight.SemiBold) }) { BlockField(game, Modifier.fillMaxHeight().aspectRatio(BLOCK_COLUMNS / BLOCK_ROWS.toFloat()).classicPanel().padding(6.dp)) } @@ -296,9 +411,9 @@ internal fun BlockDropScreen(play: ArcadePlay) { 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 = "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) + } else if (stage == ClassicStage.Result) ClassicResult(gameDef, if (mode == BlockMode.Broadcast) "BLOCK DROP · BROADCAST · LEVEL ${game.level}" else if (mode == BlockMode.WindDown) "BLOCK DROP · WIND DOWN" else "BLOCK DROP · LEVEL ${game.level} REACHED", "SCORE", "%,d".format(game.score), + newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, if (mode == BlockMode.Classic) gameDef.title else mode.title), + detail = "${game.lines} rows cleared" + if (game.broadcast) " · ${game.powers} power-ups" else "", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave) if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, if (sprint) "Sprint · ${game.lines} of $SPRINT_LINES · ${sprintText(centis)}" else "Block Drop · Level ${game.level} · ${"%,d".format(game.score)}", onResume = { guard.reset(); paused = false }, onRestart = { run.end(if (sprint) RunEnd(centis, finished = false) else RunEnd(game.score, finished = false, detail = "Level ${game.level}")); startRun() }, onExit = ::leave) diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt b/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt index 0c5702ae..2d64305a 100644 --- a/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt +++ b/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt @@ -102,6 +102,10 @@ internal const val SKY_CHALLENGE_SCORES = "SkyChallenge" /** Block Drop's 40-line Sprint: the time in hundredths, fewest first. */ internal const val BLOCKS_SPRINT_SCORES = "BlocksSprint" +/** Block Drop's Broadcast and Wind Down: points, each in its own table. */ +internal const val BLOCKS_BROADCAST_SCORES = "BlocksBroadcast" +internal const val BLOCKS_WINDDOWN_SCORES = "BlocksWindDown" + /** Patience's Daily Challenge, drawing one and drawing three: fewest moves then time, in one number ([tv.orbit.classic.dailyScore]). */ internal const val PATIENCE_DAILY_SCORES = "PatienceDaily" internal const val PATIENCE_DAILY3_SCORES = "PatienceDaily3" @@ -128,7 +132,8 @@ internal class ScoreTable(val id: String, val name: String, val kind: ScoreKind, internal val modeTables: Map> = mapOf( "Hive" to listOf(ScoreTable(HIVE_HARD_SCORES, "Hard", ScoreKind.Points)), "OrbMan" to listOf(ScoreTable(ORBMAN_SIGNAL_SCORES, "Signal Run", ScoreKind.Points)), - "Blocks" to listOf(ScoreTable(BLOCKS_SPRINT_SCORES, "40-Line Sprint", ScoreKind.FewestMoves) { tv.orbit.classic.sprintText(it) }), + "Blocks" to listOf(ScoreTable(BLOCKS_SPRINT_SCORES, "40-Line Sprint", ScoreKind.FewestMoves) { tv.orbit.classic.sprintText(it) }, + ScoreTable(BLOCKS_BROADCAST_SCORES, "Broadcast", ScoreKind.Points), ScoreTable(BLOCKS_WINDDOWN_SCORES, "Wind Down", ScoreKind.Points)), "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) }, ScoreTable(PATIENCE_ORBIT_SCORES, "Orbit Deck", ScoreKind.Wins)), diff --git a/android/app/src/test/java/tv/orbit/classic/BlockModesTest.kt b/android/app/src/test/java/tv/orbit/classic/BlockModesTest.kt new file mode 100644 index 00000000..0ad2d666 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/BlockModesTest.kt @@ -0,0 +1,63 @@ +package tv.orbit.classic + +import org.junit.Assert.* +import org.junit.Test + +/** Block Drop's Broadcast and Wind Down (Phase 2): Classic plays as before. */ +class BlockModesTest { + private val random = java.util.Random(5) + private fun board(vararg rows: Pair) = List(BLOCK_ROWS) { y -> rows.firstOrNull { it.first == y }?.second ?: IntArray(BLOCK_COLUMNS) } + + @Test fun classicHasNoneOfIt() { + val g = BlockGame.start(random) + assertFalse(g.broadcast); assertFalse(g.windDown) + assertTrue(g.board.all { r -> r.all { it == 0 } }) + } + + @Test fun aRowOfOneChannelIsAChannelBonusAndThreeSetOffAPowerUp() { + // The bottom row: nine of Riot's blocks and a gap at the right, filled by a Riot bar dropped upright. + val row = IntArray(BLOCK_COLUMNS) { if (it < 9) CHANNEL_BLOCK + 1 else 0 } + var g = BlockGame.broadcastStart(random).copy(board = board(BLOCK_ROWS - 1 to row), piece = BlockPiece(0, 1, 7, 0), chan = 1, charge = 2) + g = g.drop(random) + assertEquals(1, g.lines); assertEquals(1, g.lastBonus) + // The bonus made the third charge: the first power-up, Signal Bomb, went off, and the meter starts again. + assertEquals(1, g.powers); assertEquals(0, g.charge); assertEquals(BlockPower.SignalBomb, g.lastPower) + assertTrue(g.score >= 100 + CHANNEL_BONUS) + } + + @Test fun mixedChannelsAreNoBonus() { + // Three of each channel at most (Orbit 1 at 0, 4, 8; Riot at 1, 5 and the dropped bar): no bonus. + val row = IntArray(BLOCK_COLUMNS) { if (it < 9) CHANNEL_BLOCK + it % 4 else 0 } + val g = BlockGame.broadcastStart(random).copy(board = board(BLOCK_ROWS - 1 to row), piece = BlockPiece(0, 1, 7, 0), chan = 1).drop(random) + assertEquals(1, g.lines); assertEquals(0, g.lastBonus) + } + + @Test fun thePowerUpsDoWhatTheySay() { + val full = BlockGame.broadcastStart(random).copy(board = List(BLOCK_ROWS) { y -> IntArray(BLOCK_COLUMNS) { if (y > 10) CHANNEL_BLOCK else 0 } }) + val landed = BlockPiece(1, 0, 4, 12) + val bomb = full.power(BlockPower.SignalBomb, landed) + assertEquals(9, (11..14).sumOf { y -> (3..6).count { x -> full.board[y][x] != 0 && bomb.board[y][x] == 0 } }) + assertEquals(FREEZE_MS, full.power(BlockPower.Freeze, landed).freezeMs) + assertEquals(0, full.power(BlockPower.Tuner, landed).next) + val clear = full.power(BlockPower.ClearPicture, landed) + assertTrue(clear.board.first().all { it == 0 }); assertEquals(full.board.count { r -> r.any { it != 0 } } - 1, clear.board.count { r -> r.any { it != 0 } } + 0) + val rewound = full.power(BlockPower.Rewind, landed) + assertTrue(landed.cells().all { (x, y) -> rewound.board[y][x] == 0 }) + } + + @Test fun interferencePushesStaticUpAndOffTheTopEndsIt() { + val g = BlockGame.broadcastStart(random).interfere(random) + assertEquals(BLOCK_COLUMNS - 1, g.board.last().count { it == STATIC_BLOCK }) + val topped = g.copy(board = board(0 to IntArray(BLOCK_COLUMNS) { 1 })).interfere(random) + assertFalse(topped.alive) + } + + @Test fun windDownNeverEndsTheStackFadesAway() { + val stacked = List(BLOCK_ROWS) { y -> IntArray(BLOCK_COLUMNS) { x -> if (y >= 1 && x != y % BLOCK_COLUMNS) 1 else 0 } } + var g = BlockGame.windDownStart(random).copy(board = stacked) + g = g.drop(random) + assertTrue(g.alive); assertEquals(1, g.fades) + // The same in Classic is game over. + assertFalse(BlockGame.start(random).copy(board = stacked).drop(random).alive) + } +}