Pairs Showtime (five growing boards, streaks, Drift/Bumble/Zip special cards, the rare wizard; own High Scores) and Family Play for 2 to 4 players

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 09:55:57 +00:00
co-authored by Claude Opus 5.5
parent 24e4b54d07
commit d8e4cce96b
4 changed files with 225 additions and 55 deletions
@@ -16,6 +16,8 @@ import tv.orbit.classic.arcade.Mascot
import tv.orbit.classic.arcade.gameKeys
import tv.orbit.classic.arcade.classicPanel
import tv.orbit.classic.arcade.PAIRS_CHALLENGE_SCORES
import tv.orbit.classic.arcade.PAIRS_SHOWTIME_SCORES
import tv.orbit.classic.arcade.SpeechBubble
import tv.orbit.classic.arcade.ArcadePlay
import tv.orbit.classic.arcade.RunEnd
@@ -81,6 +83,12 @@ internal data class PairsGame(val cards: List<Int>, val matched: Set<Int> = empt
return if (cards[now[0]] == cards[now[1]]) copy(matched = matched + now, open = emptyList(), moves = moves + 1) else copy(open = now, moves = moves + 1)
}
/** Drift's mischief in Showtime: two face-down cards change places. */
fun swap(i: Int, j: Int): PairsGame = copy(cards = cards.toMutableList().also { val t = it[i]; it[i] = it[j]; it[j] = t })
/** Cards still face down and unmatched. */
val hidden get() = cards.indices.filter { it !in matched && it !in open }
/** Turns a mismatched pair back down. */
fun hide() = if (waiting) copy(open = emptyList()) else this
@@ -112,6 +120,35 @@ internal fun pairsLine(score: Int) = "${score / 1_000} boards · ${score % 1_000
/** The Challenge's faces: Classic's ten, then more of Orbit's family channels and Drift, enough for a 6 by 5. */
private val PairsChallengeFaces = PairsChannels + listOf(3, 102, 104, 203, 602, 605)
/** Showtime's special cards (faces below 0): Drift swaps two face-down cards, Bumble flashes a pair open, Zip shows a row; the wizard, rarely, is 999 points. */
internal const val PAIRS_DRIFT = -1
internal const val PAIRS_BUMBLE = -2
internal const val PAIRS_ZIP = -3
internal const val PAIRS_WIZARD = -4
/** One board in this many has the wizard instead of its special card. */
internal const val WIZARD_ONE_IN = 25
/** Showtime's points for a match: 100 times the streak (matches in a row, a miss starts again). */
internal fun showtimePoints(streak: Int) = 100 * streak.coerceAtLeast(1)
internal const val SHOWTIME_BOARD_BONUS = 500
/** The faces for a Showtime board: from the second board, one pair is a special card. */
internal fun showtimeFaces(board: Int, pairs: Int, random: java.util.Random): List<Int> {
val faces = PairsChallengeFaces.shuffled(random).take(pairs).toMutableList()
if (board >= 1) faces[faces.size - 1] = if (random.nextInt(WIZARD_ONE_IN) == 0) PAIRS_WIZARD else listOf(PAIRS_DRIFT, PAIRS_BUMBLE, PAIRS_ZIP)[(board - 1) % 3]
return faces
}
/** The ways to play Pairs: each new one separate, Classic untouched. Family Play is shared turns, so it keeps no High Scores. */
internal enum class PairsMode(val title: String, val players: Int = 1) {
Classic("Classic"), Challenge("Challenge"), Showtime("Showtime"),
Family2("Family Play for 2", 2), Family3("Family Play for 3", 3), Family4("Family Play for 4", 4);
val family get() = players > 1
}
/** Family Play's players: one of the cast's colours each. */
internal val FamilyColours = listOf(Color(0xFFF7A928), OrbCharacter.Zip.colour, OrbCharacter.Drift.colour, OrbCharacter.Luna.colour)
@Composable
@@ -121,7 +158,23 @@ private fun PairsCard(channel: Int, up: Boolean, matched: Boolean, selected: Boo
Box(modifier.graphicsLayer { rotationY = 180f * (1 - turn); cameraDistance = 12 * density }
.background(if (turn > .5f) ArcadeColours.PanelDeep else if (selected) ArcadeColours.FocusFill else ArcadeColours.Panel, RoundedCornerShape(8.dp))
.border(if (selected) 3.dp else 1.dp, if (selected) ArcadeColours.Yellow else if (matched) ArcadeColours.Green else ArcadeColours.Line, RoundedCornerShape(8.dp)), contentAlignment = Alignment.Center) {
if (turn > .5f && channel < 100) androidx.compose.foundation.Canvas(Modifier.fillMaxSize().padding(8.dp).alpha(if (matched) .7f else 1f)) {
// Showtime's special cards: a gold halo round the one who does something when matched.
if (turn > .5f && channel < 0) androidx.compose.foundation.Canvas(Modifier.fillMaxSize().padding(6.dp).alpha(if (matched) .7f else 1f)) {
val r = size.minDimension * .34f
drawCircle(ArcadeColours.Yellow.copy(alpha = .3f), r * 1.35f, center)
when (channel) {
PAIRS_DRIFT -> drawOrbChaser(center, r, OrbCharacter.Drift, OrbDir.Down, false, false, false, 0f)
PAIRS_BUMBLE -> drawOrbBee(center + androidx.compose.ui.geometry.Offset(0f, r * .15f), r * .75f)
PAIRS_ZIP -> drawOrbChaser(center, r, OrbCharacter.Zip, OrbDir.Down, false, false, false, 0f)
else -> {
// The wizard of page 999, very rarely: his hat and the page number.
drawPath(androidx.compose.ui.graphics.Path().apply { moveTo(center.x, center.y - r * 1.2f); lineTo(center.x + r * .8f, center.y + r * .5f); lineTo(center.x - r * .8f, center.y + r * .5f); close() }, Color(0xFF7B4DFF))
drawPath(starPath(center + androidx.compose.ui.geometry.Offset(r * .1f, -r * .2f), r * .25f, r * .1f, 0f), ArcadeColours.Yellow)
drawRect(Color(0xFF7B4DFF), center + androidx.compose.ui.geometry.Offset(-r, r * .45f), androidx.compose.ui.geometry.Size(r * 2f, r * .2f))
}
}
}
else if (turn > .5f && channel < 100) androidx.compose.foundation.Canvas(Modifier.fillMaxSize().padding(8.dp).alpha(if (matched) .7f else 1f)) {
val r = size.minDimension * .36f
if (channel == 0) drawOrbMascot(center, r * .8f)
else drawOrbChaser(center, r, OrbCharacter.entries[channel - 1], OrbDir.Down, scared = false, returning = false, blink = false, wobble = 0f)
@@ -146,43 +199,65 @@ internal fun PairsScreen(play: ArcadePlay) {
var stage by remember { mutableStateOf(ClassicStage.Title) }
var paused by remember { mutableStateOf(false) }
var howTo by remember { mutableStateOf(false) }
// Classic, or the Challenge (Phase 2): chosen on the title, remembered, each with its own High Scores.
var challenge by remember { mutableStateOf(play.level["mode"] == "Challenge") }
val table = if (challenge) PAIRS_CHALLENGE_SCORES else gameDef.id
// Classic, the Challenge, Showtime, or Family Play for 2 to 4: chosen on the title, remembered.
var mode by remember { mutableStateOf(PairsMode.entries.firstOrNull { it.name == play.level["mode"] } ?: PairsMode.Classic) }
val table = when (mode) { PairsMode.Challenge -> PAIRS_CHALLENGE_SCORES; PairsMode.Showtime -> PAIRS_SHOWTIME_SCORES; else -> gameDef.id }
var bestBefore by remember { mutableIntStateOf(play.bestIn(table)) }
// The Challenge's board, faces, clock and tally.
// The Challenge's and Showtime's board, faces, clock and tally.
var board by remember { mutableIntStateOf(0) }
var faces by remember { mutableStateOf(PairsChannels) }
var clock by remember { mutableIntStateOf(PAIRS_CLOCK_START) }
var boards by remember { mutableIntStateOf(0) }
var pairs by remember { mutableIntStateOf(0) }
var points by remember { mutableIntStateOf(0) }
var streak by remember { mutableIntStateOf(0) }
var peek by remember { mutableStateOf(emptySet<Int>()) }
var news by remember { mutableStateOf<String?>(null) }
// Family Play: whose turn, and everyone's pairs.
var turn by remember { mutableIntStateOf(0) }
var scores by remember { mutableStateOf(List(4) { 0 }) }
val focus = remember { FocusRequester() }
val backdrop = ArcadeLook.forGame(gameDef.id)
LaunchedEffect(game.waiting, paused) { if (game.waiting && !paused) { delay(900); game = game.hide() } }
// A cleared board is saved for this profile; leaving part-way saves nothing (fewest moves only counts when it's done).
// A Challenge counts however it ends: the boards and pairs it got.
val run = rememberRun({ end -> if (challenge) latestPlay.onRunEndIn(PAIRS_CHALLENGE_SCORES, end) else latestPlay.onRunEnd(end) }) {
if (challenge) RunEnd(pairsScore(boards, pairs), finished = false) else RunEnd(game.moves, finished = game.done)
}
// A miss turns back after a moment; in Family Play the turn then passes on.
LaunchedEffect(game.waiting, paused) { if (game.waiting && !paused) { delay(900); game = game.hide(); if (mode.family) turn = (turn + 1) % mode.players } }
LaunchedEffect(peek) { if (peek.isNotEmpty()) { delay(1_500); peek = emptySet() } }
LaunchedEffect(news) { if (news != null) { delay(2_200); news = null } }
fun runScore() = when (mode) { PairsMode.Challenge -> pairsScore(boards, pairs); PairsMode.Showtime -> points; else -> game.moves }
// Classic saves a cleared board's moves; the Challenge and Showtime count however they end; Family Play keeps no scores.
val run = rememberRun({ end -> when (mode) { PairsMode.Challenge -> latestPlay.onRunEndIn(PAIRS_CHALLENGE_SCORES, end); PairsMode.Showtime -> latestPlay.onRunEndIn(PAIRS_SHOWTIME_SCORES, end)
PairsMode.Classic -> latestPlay.onRunEnd(end); else -> {} } }) { RunEnd(runScore(), finished = mode == PairsMode.Classic && game.done) }
fun dealBoard(b: Int) {
val (cols, rows) = pairsBoard(b)
faces = PairsChallengeFaces.shuffled(random).take(cols * rows / 2)
faces = if (mode == PairsMode.Showtime) showtimeFaces(b, cols * rows / 2, random) else PairsChallengeFaces.shuffled(random).take(cols * rows / 2)
game = PairsGame.deal(random, cols * rows / 2, cols)
}
fun deal() {
bestBefore = latestPlay.bestIn(table)
if (challenge) { board = 0; boards = 0; pairs = 0; clock = PAIRS_CLOCK_START; dealBoard(0) } else { faces = PairsChannels; game = PairsGame.deal(random) }
bestBefore = latestPlay.bestIn(table); board = 0; boards = 0; pairs = 0; points = 0; streak = 0; peek = emptySet(); news = null; turn = 0; scores = List(4) { 0 }
when {
mode == PairsMode.Challenge -> { clock = PAIRS_CLOCK_START; dealBoard(0) }
mode == PairsMode.Showtime -> dealBoard(0)
mode.family -> { faces = PairsChallengeFaces.shuffled(random).take(12); game = PairsGame.deal(random, 12, 6) }
else -> { faces = PairsChannels; game = PairsGame.deal(random) }
}
run.begin(); paused = false; stage = ClassicStage.Play
}
fun leave() { run.end(if (challenge) RunEnd(pairsScore(boards, pairs), finished = false) else RunEnd(game.moves, finished = game.done)); latestPlay.onLeave() }
fun leave() { run.end(RunEnd(runScore(), finished = false)); latestPlay.onLeave() }
LaunchedEffect(game.done) {
if (!game.done || stage != ClassicStage.Play) return@LaunchedEffect
if (challenge) { boards++; clock += PAIRS_BOARD_BONUS; board++; dealBoard(board) }
else { run.end(RunEnd(game.moves, finished = true)); stage = ClassicStage.Result }
when {
mode == PairsMode.Challenge -> { boards++; clock += PAIRS_BOARD_BONUS; board++; dealBoard(board) }
mode == PairsMode.Showtime -> {
boards++; points += SHOWTIME_BOARD_BONUS
if (board + 1 >= PairsBoards.size) { run.end(RunEnd(points, finished = true, detail = "$boards boards")); stage = ClassicStage.Result }
else { board++; dealBoard(board) }
}
mode.family -> { run.end(RunEnd(0, finished = false)); stage = ClassicStage.Result }
else -> { run.end(RunEnd(game.moves, finished = true)); stage = ClassicStage.Result }
}
}
// The Challenge's clock: down a second at a time while playing; at nought, the run ends.
LaunchedEffect(stage, paused, challenge) {
while (challenge && stage == ClassicStage.Play && !paused) {
LaunchedEffect(stage, paused, mode) {
while (mode == PairsMode.Challenge && stage == ClassicStage.Play && !paused) {
delay(1_000); clock--
if (clock <= 0) { clock = 0; run.end(RunEnd(pairsScore(boards, pairs), finished = true)); stage = ClassicStage.Result }
}
@@ -193,18 +268,29 @@ internal fun PairsScreen(play: ArcadePlay) {
if (stage == ClassicStage.Title) {
val best = play.bestIn(table)
ClassicTitle(gameDef, backdrop, ArcadeColours.Cyan, if (challenge) "Quick! How many boards can you clear?" else "Remember where we are!",
listOf("Your best" to if (best <= 0) "Not played yet" else if (challenge) pairsLine(best) else "$best moves"),
timed = challenge, difficulty = play.difficulty, refocus = !howTo, onPlay = ::deal, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
mode = if (challenge) "Challenge" else "Classic", modes = 2, onMode = { challenge = !challenge; latestPlay.setLevel("mode", if (challenge) "Challenge" else "Classic") },
note = if (challenge) "Clear boards in a row before the clock runs out, each a little bigger, up to 6 by 5. Every match adds 2 seconds, every board 30."
else "Two cards are one move. The fewer moves, the better.")
ClassicTitle(gameDef, backdrop, ArcadeColours.Cyan, when (mode) {
PairsMode.Challenge -> "Quick! How many boards can you clear?"; PairsMode.Showtime -> "It's Showtime! Watch for my friends."
PairsMode.Classic -> "Remember where we are!"; else -> "Who's got the best memory?" },
when (mode) {
PairsMode.Classic -> listOf("Your best" to if (best <= 0) "Not played yet" else "$best moves")
PairsMode.Challenge -> listOf("Your best" to if (best <= 0) "Not played yet" else pairsLine(best))
PairsMode.Showtime -> listOf("Your best" to if (best <= 0) "Not played yet" else "%,d".format(best))
else -> listOf("Players" to "${mode.players}")
},
timed = mode == PairsMode.Challenge, difficulty = play.difficulty, refocus = !howTo, onPlay = ::deal, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
mode = mode.title, modes = PairsMode.entries.size, onMode = { mode = PairsMode.entries[(mode.ordinal + 1) % PairsMode.entries.size]; latestPlay.setLevel("mode", mode.name) },
note = when (mode) {
PairsMode.Challenge -> "Clear boards in a row before the clock runs out, each a little bigger, up to 6 by 5. Every match adds 2 seconds, every board 30."
PairsMode.Showtime -> "Five boards, 4 by 3 up to 6 by 5. Matches in a row build a streak: 100 points times the streak. Special cards: Drift swaps two cards, Bumble flashes a pair, Zip shows a row. And very rarely, someone from page 999…"
PairsMode.Classic -> "Two cards are one move. The fewer moves, the better."
else -> "${mode.players} players share the remote and take turns. Find a pair and go again; miss and it's the next player's turn. Most pairs wins."
})
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
return
}
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused, pause = { paused = true }) { key, native ->
if (native.action != KeyEvent.ACTION_DOWN || game.done) return@gameKeys key != ArcadeKey.Other
val next = when (key) {
var next = when (key) {
ArcadeKey.Left -> game.moveCursor(-1, 0)
ArcadeKey.Right -> game.moveCursor(1, 0)
ArcadeKey.Up -> game.moveCursor(0, -1)
@@ -212,24 +298,62 @@ internal fun PairsScreen(play: ArcadePlay) {
ArcadeKey.Ok -> if (native.repeatCount > 0) game else game.flip()
else -> null
}
// Each match in the Challenge: a pair counted and two seconds back, at the moment it's made.
if (next != null && challenge && next.matched.size > game.matched.size) { pairs++; clock += PAIRS_MATCH_BONUS }
if (next != null && key == ArcadeKey.Ok) {
val matchedNow = next.matched.size > game.matched.size
when {
matchedNow && mode == PairsMode.Challenge -> { pairs++; clock += PAIRS_MATCH_BONUS }
matchedNow && mode == PairsMode.Showtime -> {
streak++; pairs++; points += showtimePoints(streak)
// The special cards do their thing as soon as they're matched.
when (faces[next.cards[next.cursor]]) {
PAIRS_DRIFT -> { val h = next.hidden; if (h.size >= 2) { val a = h[random.nextInt(h.size)]; val b = h.filter { it != a }.let { it[random.nextInt(it.size)] }; next = next.swap(a, b) }; news = "Drift swapped two cards!" }
PAIRS_BUMBLE -> { val h = next.hidden; h.groupBy { next.cards[it] }.values.firstOrNull { it.size == 2 }?.let { peek = it.toSet() }; news = "Bumble shows you a pair!" }
PAIRS_ZIP -> { val row = (0 until next.rows).maxByOrNull { r -> next.hidden.count { it / next.cols == r } } ?: 0; peek = next.hidden.filter { it / next.cols == row }.toSet(); news = "Zip lights up a row!" }
PAIRS_WIZARD -> { points += 999; news = "The wizard of page 999! +999" }
}
}
matchedNow && mode.family -> scores = scores.toMutableList().also { it[turn]++ }
!matchedNow && next.waiting && mode == PairsMode.Showtime -> streak = 0
}
}
if (next != null) game = next
next != null
}
Box(Modifier.fillMaxSize()) {
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶▲▼", "Move"), Control("OK", "Turn a card"), Control("Back", "Pause")), hud = {
if (challenge) {
HudLabel("TIME LEFT"); HudValue("%d:%02d".format(clock / 60, clock % 60), if (clock <= 10) ArcadeColours.Red else ArcadeColours.Ink)
HudLabel("BOARDS"); HudValue("$boards")
Spacer(Modifier.height(6.dp))
HudLabel("PAIRS"); HudValue("$pairs")
Text("Board ${board + 1}: ${game.cols} by ${game.rows}", color = ArcadeColours.Muted, fontSize = 14.sp)
} else {
HudLabel("MOVES"); HudValue("${game.moves}")
HudLabel("BEST"); HudValue(if (bestBefore == 0) "—" else "$bestBefore")
Spacer(Modifier.height(6.dp))
HudLabel("PAIRS"); HudValue("${game.matched.size / 2} of ${game.cards.size / 2}")
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶▲▼", "Move"), Control("OK", "Turn a card"), Control("Back", "Pause")),
note = if (mode.family) "Player ${turn + 1}'s turn" else null, hud = {
when {
mode == PairsMode.Challenge -> {
HudLabel("TIME LEFT"); HudValue("%d:%02d".format(clock / 60, clock % 60), if (clock <= 10) ArcadeColours.Red else ArcadeColours.Ink)
HudLabel("BOARDS"); HudValue("$boards")
Spacer(Modifier.height(6.dp))
HudLabel("PAIRS"); HudValue("$pairs")
Text("Board ${board + 1}: ${game.cols} by ${game.rows}", color = ArcadeColours.Muted, fontSize = 14.sp)
}
mode == PairsMode.Showtime -> {
HudLabel("SCORE"); HudValue("%,d".format(points))
HudLabel("STREAK"); HudValue(if (streak > 0) "×$streak" else "—", if (streak >= 3) ArcadeColours.Pink else ArcadeColours.Ink)
Spacer(Modifier.height(6.dp))
HudLabel("BOARD ${board + 1} OF ${PairsBoards.size}")
Text("${game.cols} by ${game.rows} · ${game.moves} moves", color = ArcadeColours.Muted, fontSize = 14.sp)
Spacer(Modifier.weight(1f))
news?.let { SpeechBubble(it) }
}
mode.family -> {
HudLabel("WHOSE TURN")
for (p in 0 until mode.players) Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.then(if (p == turn) Modifier.border(2.dp, ArcadeColours.Yellow, RoundedCornerShape(8.dp)) else Modifier).padding(horizontal = 6.dp, vertical = 2.dp)) {
androidx.compose.foundation.Canvas(Modifier.size(14.dp)) { drawCircle(FamilyColours[p]) }
Text("Player ${p + 1}", color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = if (p == turn) FontWeight.Bold else FontWeight.Normal)
Text("${scores[p]}", color = FamilyColours[p], fontSize = 18.sp, fontWeight = FontWeight.Bold)
}
}
else -> {
HudLabel("MOVES"); HudValue("${game.moves}")
HudLabel("BEST"); HudValue(if (bestBefore == 0) "—" else "$bestBefore")
Spacer(Modifier.height(6.dp))
HudLabel("PAIRS"); HudValue("${game.matched.size / 2} of ${game.cards.size / 2}")
}
}
}) {
// Classic's cards are 120 by 80; bigger boards' shrink to fit (6 by 5 at 100 by 70).
@@ -239,23 +363,37 @@ internal fun PairsScreen(play: ArcadePlay) {
for (row in 0 until game.rows) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
for (col in 0 until game.cols) {
val i = row * game.cols + col
PairsCard(faces[game.cards[i]], i in game.matched || i in game.open, i in game.matched, i == game.cursor && !game.done, Modifier.width(cw.dp).height(ch.dp))
PairsCard(faces[game.cards[i]], i in game.matched || i in game.open || i in peek, i in game.matched, i == game.cursor && !game.done, Modifier.width(cw.dp).height(ch.dp))
}
}
}
}
if (stage == ClassicStage.Result && challenge) {
val score = pairsScore(boards, pairs)
ClassicResult(gameDef, "PAIRS · CHALLENGE", "BOARDS", "$boards", newBest = score > bestBefore && score > 0,
previous = "$pairs pairs matched", detail = if (bestBefore > 0) "Previous best ${pairsLine(bestBefore)}" else "Your first Pairs Challenge", heading = "TIME!",
againLabel = "Go again", cheer = Mascot.Blaze, onAgain = ::deal, onBack = ::leave)
} else if (stage == ClassicStage.Result) {
val newBest = bestBefore == 0 || game.moves < bestBefore
ClassicResult(gameDef, "PAIRS · ALL ${game.cards.size / 2} PAIRED", "MOVES", "${game.moves}", newBest = newBest,
previous = if (bestBefore > 0) "Previous best $bestBefore moves" else "Your first Pairs score", detail = null, heading = "ALL PAIRED",
cheer = Mascot.Luna, onAgain = ::deal, onBack = ::leave)
if (stage == ClassicStage.Result) when {
mode == PairsMode.Challenge -> {
val score = pairsScore(boards, pairs)
ClassicResult(gameDef, "PAIRS · CHALLENGE", "BOARDS", "$boards", newBest = score > bestBefore && score > 0,
previous = "$pairs pairs matched", detail = if (bestBefore > 0) "Previous best ${pairsLine(bestBefore)}" else "Your first Pairs Challenge", heading = "TIME!",
againLabel = "Go again", cheer = Mascot.Blaze, onAgain = ::deal, onBack = ::leave)
}
mode == PairsMode.Showtime -> ClassicResult(gameDef, "PAIRS · SHOWTIME · ALL ${PairsBoards.size} BOARDS", "SCORE", "%,d".format(points), newBest = points > bestBefore,
previous = if (bestBefore > 0) "Previous best ${"%,d".format(bestBefore)}" else "Your first Showtime", detail = "$pairs pairs", heading = "THAT'S SHOWTIME!",
againLabel = "Go again", cheer = Mascot.Bumble, onAgain = ::deal, onBack = ::leave)
mode.family -> {
val top = scores.take(mode.players).max()
val winners = (0 until mode.players).filter { scores[it] == top }
ClassicResult(gameDef, "PAIRS · FAMILY PLAY · ${mode.players} PLAYERS", "PAIRS", (0 until mode.players).joinToString(" ") { "P${it + 1}: ${scores[it]}" }, newBest = false,
previous = if (winners.size == 1) "Player ${winners[0] + 1} wins!" else "A draw between players ${winners.joinToString(" and ") { "${it + 1}" }}!",
detail = "Family Play keeps no High Scores: it's everyone's game", heading = "WELL PLAYED!", againLabel = "Play again", cheer = Mascot.Luna, onAgain = ::deal, onBack = ::leave)
}
else -> {
val newBest = bestBefore == 0 || game.moves < bestBefore
ClassicResult(gameDef, "PAIRS · ALL ${game.cards.size / 2} PAIRED", "MOVES", "${game.moves}", newBest = newBest,
previous = if (bestBefore > 0) "Previous best $bestBefore moves" else "Your first Pairs score", detail = null, heading = "ALL PAIRED",
cheer = Mascot.Luna, onAgain = ::deal, onBack = ::leave)
}
}
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, if (challenge) "Pairs Challenge · $boards boards · ${clock}s left" else "Pairs · ${game.moves} moves · ${game.matched.size / 2} of ${game.cards.size / 2} pairs",
onResume = { paused = false }, onRestart = { run.end(if (challenge) RunEnd(pairsScore(boards, pairs), finished = false) else RunEnd(game.moves, finished = false)); deal() }, onExit = ::leave)
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, when { mode == PairsMode.Challenge -> "Pairs Challenge · $boards boards · ${clock}s left"; mode == PairsMode.Showtime -> "Showtime · ${"%,d".format(points)}"
mode.family -> "Family Play · Player ${turn + 1}'s turn"; else -> "Pairs · ${game.moves} moves · ${game.matched.size / 2} of ${game.cards.size / 2} pairs" },
onResume = { paused = false }, onRestart = { run.end(RunEnd(runScore(), finished = false)); deal() }, onExit = ::leave)
}
}
@@ -112,6 +112,9 @@ internal const val PATIENCE_ORBIT_SCORES = "PatienceOrbit"
/** Pairs' Challenge: boards cleared then pairs matched, in one number ([tv.orbit.classic.pairsScore]). */
internal const val PAIRS_CHALLENGE_SCORES = "PairsChallenge"
/** Pairs' Showtime: points over its five boards. */
internal const val PAIRS_SHOWTIME_SCORES = "PairsShowtime"
/** Blast Off's Challenges: the furthest of the twenty cleared. */
internal const val BLAST_CHALLENGE_SCORES = "BlastChallenge"
@@ -129,7 +132,8 @@ internal val modeTables: Map<String, List<ScoreTable>> = mapOf(
"Patience" to listOf(ScoreTable(PATIENCE_DAILY_SCORES, "Daily", ScoreKind.FewestMoves) { tv.orbit.classic.dailyLine(it) },
ScoreTable(PATIENCE_DAILY3_SCORES, "Daily Draw 3", ScoreKind.FewestMoves) { tv.orbit.classic.dailyLine(it) },
ScoreTable(PATIENCE_ORBIT_SCORES, "Orbit Deck", ScoreKind.Wins)),
"Pairs" to listOf(ScoreTable(PAIRS_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.pairsLine(it) }),
"Pairs" to listOf(ScoreTable(PAIRS_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.pairsLine(it) },
ScoreTable(PAIRS_SHOWTIME_SCORES, "Showtime", ScoreKind.Points)),
"Blast" to listOf(ScoreTable(BLAST_CHALLENGE_SCORES, "Challenges", ScoreKind.Points) { tv.orbit.classic.blastChallengeLine(it) }),
"Sky" to listOf(ScoreTable(SKY_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.challengeLine(it) }),
)
@@ -155,4 +155,32 @@ class PairsPatienceTest {
val after = uncover.point(h.from).press().point(h.to).press()
assertEquals(2, after.piles[7].size); assertTrue(after.piles[6].single().up)
}
// ---------- Pairs Showtime and Family Play (Phase 2) ----------
@Test fun showtimeHasOneSpecialPairFromTheSecondBoard() {
val r = java.util.Random(8)
assertTrue(showtimeFaces(0, 6, r).none { it < 0 })
val second = showtimeFaces(1, 8, r)
assertEquals(8, second.size); assertEquals(1, second.count { it < 0 }); assertEquals(8, second.toSet().size)
// Over many boards the specials take turns, and the wizard turns up only rarely.
val specials = (1..400).map { b -> showtimeFaces(b, 10, java.util.Random(b.toLong())).first { it < 0 } }
assertTrue(specials.count { it == PAIRS_WIZARD } in 4..40)
assertTrue(listOf(PAIRS_DRIFT, PAIRS_BUMBLE, PAIRS_ZIP).all { it in specials })
}
@Test fun streaksMultiplyAndDriftsSwapKeepsThePairs() {
assertEquals(100, showtimePoints(1)); assertEquals(300, showtimePoints(3))
val g = PairsGame.deal(java.util.Random(3), 6, 4)
val swapped = g.swap(0, 5)
assertEquals(g.cards[0], swapped.cards[5]); assertEquals(g.cards[5], swapped.cards[0])
assertEquals(g.cards.sorted(), swapped.cards.sorted())
assertEquals(12, g.hidden.size)
}
@Test fun familyPlayIsTwoToFourPlayersAndKeepsNoTable() {
assertEquals(listOf(2, 3, 4), PairsMode.entries.filter { it.family }.map { it.players })
assertFalse(PairsMode.Classic.family)
assertEquals(listOf("Pairs", tv.orbit.classic.arcade.PAIRS_CHALLENGE_SCORES, tv.orbit.classic.arcade.PAIRS_SHOWTIME_SCORES), tv.orbit.classic.arcade.scoreTables("Pairs"))
}
}
@@ -90,7 +90,7 @@ class TitleTextFitsTest {
@Test fun theModeButtonSpellsEachModeOutInFull() {
// The mode's whole name on the button, after its ◆, in the title's 210 dp column.
val label = Font(Font.SANS_SERIF, Font.BOLD, 1).deriveFont(14f * 1.3f)
for (mode in listOf("Classic", "Signal Run", "Challenge", "Challenges", "40-Line Sprint", "Daily Challenge", "Daily · Draw Three")) {
for (mode in listOf("Classic", "Signal Run", "Challenge", "Challenges", "40-Line Sprint", "Daily Challenge", "Daily · Draw Three", "Orbit Deck", "Showtime") + tv.orbit.classic.PairsMode.entries.map { it.title }) {
val w = width(label, "◆ $mode")
assertTrue("Mode · $mode is ${"%.0f".format(w)} dp", w <= 230 - 2 * 12 - 4)
}