Add waiting arcade MVP

This commit is contained in:
Anthony Ettinger 2026-06-06 22:09:22 +00:00
parent b1d8fe475a
commit 4682b261c0
16 changed files with 1192 additions and 2 deletions

View file

@ -0,0 +1,49 @@
import type { GameAction, KeyEvent, TerminalFrame, WaitingGame } from "../types.js";
export class AgentSwarmGame implements WaitingGame {
readonly id = "agent-swarm";
readonly title = "Agent Swarm";
readonly description = "Route agents around blockers and collect approvals.";
readonly controls = [
{ key: "Arrow/WASD", action: "move lead agent" },
{ key: "L/Ctrl+G", action: "logs" },
{ key: "Esc", action: "pause" },
{ key: "Q", action: "quit" }
];
private x = 18;
private y = 8;
private tickCount = 0;
init() {
return;
}
tick() {
this.tickCount += 1;
}
input(event: KeyEvent): GameAction | void {
if (event.ctrl && event.name === "g") return { type: "toggle_logs" };
if (event.name === "escape") return { type: "pause" };
if (event.name === "q") return { type: "quit" };
if (event.name === "l") return { type: "toggle_logs" };
if (["up", "w", "k"].includes(event.name)) this.y = Math.max(2, this.y - 1);
if (["down", "s", "j"].includes(event.name)) this.y = Math.min(13, this.y + 1);
if (["left", "a", "h"].includes(event.name)) this.x = Math.max(4, this.x - 1);
if (["right", "d"].includes(event.name)) this.x = Math.min(50, this.x + 1);
}
render(frame: TerminalFrame) {
frame.box(0, 0, frame.width, frame.height - 5, this.title.toUpperCase());
frame.write(2, 4, "Guide the lead agent. Avoid blockers. Grab approvals.");
frame.write(6, 12, "B");
frame.write(10, 28, "B");
frame.write(5, 42, "$");
frame.write(12, 48, "A");
frame.write(this.y, this.x, "@");
frame.write(this.y + 1, Math.max(4, this.x - 4), "a a a");
frame.write(15, 4, `Swarm pulse: ${this.tickCount % 100}`);
frame.write(16, 4, "[Arrows/WASD] Move [L/Ctrl+G] Logs [Esc] Pause [Q] Quit");
}
}

View file

@ -0,0 +1,77 @@
import type { GameAction, GameContext, KeyEvent, TerminalFrame, WaitingGame } from "../types.js";
import { fit } from "../renderer.js";
const WORDS = ["LOGICSRC", "COMMAND BOARD", "AGENT SWARM", "PULL REQUEST", "TERMINAL", "SUPABASE", "COINPAY", "CRAWLPROOF", "UGIG", "SHIPT"];
const BAD_IDEAS = ["JIRA", "WATERFALL", "WEBPACK", "XML CONFIG", "VENDOR LOCK-IN", "MEETING", "BIG REWRITE", "GLOBAL STATE"];
export class HangmanGame implements WaitingGame {
readonly id = "hangman";
readonly title = "Logicsrc Hangman";
readonly description = "Guess terminal, agent, and Logicsrc words while a task runs.";
readonly controls = [
{ key: "A-Z", action: "guess" },
{ key: "L/Ctrl+G", action: "logs" },
{ key: "Esc", action: "pause" },
{ key: "Q", action: "quit" }
];
private word = WORDS[0] ?? "LOGICSRC";
private guesses = new Set<string>();
private mistakes = 0;
init(ctx: GameContext) {
this.word = WORDS[Math.floor(ctx.random() * WORDS.length)] ?? "LOGICSRC";
}
tick() {
return;
}
input(event: KeyEvent): GameAction | void {
if (event.ctrl && event.name === "g") {
return { type: "toggle_logs" };
}
if (event.name === "escape") {
return { type: "pause" };
}
if (event.name === "q") {
return { type: "quit" };
}
if (event.name === "l") {
return { type: "toggle_logs" };
}
if (/^[a-z]$/i.test(event.name)) {
const guess = event.name.toUpperCase();
if (!this.guesses.has(guess)) {
this.guesses.add(guess);
if (!this.word.includes(guess)) {
this.mistakes += 1;
}
}
}
}
render(frame: TerminalFrame) {
frame.box(0, 0, frame.width, frame.height - 5, this.title.toUpperCase());
frame.write(2, 4, "Phrase:");
frame.write(4, 4, this.maskedWord());
frame.write(6, 4, `Wrong guesses: ${this.mistakes}/6`);
frame.write(7, 4, BAD_IDEAS.slice(0, this.mistakes).join(" ") || "none yet");
frame.write(9, 4, fit(`Guessed: ${Array.from(this.guesses).sort().join(" ") || "none"}`, frame.width - 8));
const state = this.isWon() ? "solved" : this.mistakes >= 6 ? "reset with R or keep guessing" : "running";
frame.write(11, 4, `Round: ${state}`);
frame.write(13, 4, "[A-Z] Guess [L/Ctrl+G] Logs [Esc] Pause [Q] Quit");
}
private maskedWord() {
return this.word
.split("")
.map((char) => (char === " " ? " " : this.guesses.has(char) ? `${char} ` : "_ "))
.join("");
}
private isWon() {
return this.word.split("").every((char) => char === " " || this.guesses.has(char));
}
}

View file

@ -0,0 +1,83 @@
import type { GameAction, GameContext, KeyEvent, TerminalFrame, WaitingGame } from "../types.js";
type Cell = { mine: boolean; open: boolean; flag: boolean };
export class MinefieldGame implements WaitingGame {
readonly id = "minefield";
readonly title = "Deploy Minefield";
readonly description = "Clear risky deployment cells without triggering incidents.";
readonly controls = [
{ key: "Arrow/WASD", action: "move" },
{ key: "Space/Enter", action: "reveal" },
{ key: "F", action: "flag" },
{ key: "Q", action: "quit" }
];
private width = 8;
private height = 6;
private cells: Cell[] = [];
private cursor = { x: 0, y: 0 };
private state = "clear risky cells";
init(ctx: GameContext) {
this.cells = Array.from({ length: this.width * this.height }, (_, index) => ({
mine: index > 0 && ctx.random() < 0.16,
open: false,
flag: false
}));
}
tick() {
return;
}
input(event: KeyEvent): GameAction | void {
if (event.ctrl && event.name === "g") return { type: "toggle_logs" };
if (event.name === "escape") return { type: "pause" };
if (event.name === "q") return { type: "quit" };
if (event.name === "l") return { type: "toggle_logs" };
if (["up", "w", "k"].includes(event.name)) this.cursor.y = Math.max(0, this.cursor.y - 1);
if (["down", "s", "j"].includes(event.name)) this.cursor.y = Math.min(this.height - 1, this.cursor.y + 1);
if (["left", "a", "h"].includes(event.name)) this.cursor.x = Math.max(0, this.cursor.x - 1);
if (["right", "d"].includes(event.name)) this.cursor.x = Math.min(this.width - 1, this.cursor.x + 1);
if (event.name === "f") this.cell(this.cursor.x, this.cursor.y).flag = !this.cell(this.cursor.x, this.cursor.y).flag;
if (event.name === "space" || event.name === "return") this.reveal(this.cursor.x, this.cursor.y);
}
render(frame: TerminalFrame) {
frame.box(0, 0, frame.width, frame.height - 5, this.title.toUpperCase());
frame.write(2, 4, `Status: ${this.state}`);
for (let y = 0; y < this.height; y += 1) {
for (let x = 0; x < this.width; x += 1) {
const cell = this.cell(x, y);
const selected = this.cursor.x === x && this.cursor.y === y;
const value = cell.flag ? "F" : cell.open ? (cell.mine ? "!" : String(this.neighbors(x, y))) : "#";
frame.write(4 + y, 6 + x * 4, selected ? `[${value}]` : ` ${value} `);
}
}
frame.write(12, 4, "[Arrows/WASD] Move [Space/Enter] Reveal [F] Flag [Q] Quit");
}
private reveal(x: number, y: number) {
const cell = this.cell(x, y);
if (cell.flag) return;
cell.open = true;
this.state = cell.mine ? "incident triggered; keep mapping the blast radius" : "cell cleared";
}
private cell(x: number, y: number) {
return this.cells[y * this.width + x] ?? { mine: false, open: false, flag: false };
}
private neighbors(x: number, y: number) {
let count = 0;
for (let dy = -1; dy <= 1; dy += 1) {
for (let dx = -1; dx <= 1; dx += 1) {
if (dx !== 0 || dy !== 0) {
count += this.cell(x + dx, y + dy).mine ? 1 : 0;
}
}
}
return count;
}
}

View file

@ -0,0 +1,62 @@
import type { GameAction, GameContext, KeyEvent, TerminalFrame, WaitingGame } from "../types.js";
export class MoonRunnerGame implements WaitingGame {
readonly id = "moon-runner";
readonly title = "Moon Runner";
readonly description = "Jump over failed builds and collect green checks.";
readonly controls = [
{ key: "Space/Up", action: "jump" },
{ key: "L/Ctrl+G", action: "logs" },
{ key: "Esc", action: "pause" },
{ key: "Q", action: "quit" }
];
private runnerY = 0;
private velocity = 0;
private obstacleX = 46;
private score = 0;
private random = Math.random;
init(ctx: GameContext) {
this.random = ctx.random;
}
tick(deltaMs: number) {
const step = Math.max(1, Math.round(deltaMs / 60));
this.obstacleX -= step;
if (this.obstacleX < 4) {
this.obstacleX = 42 + Math.floor(this.random() * 24);
this.score += 1;
}
this.velocity -= 0.08 * step;
this.runnerY = Math.max(0, this.runnerY + this.velocity);
if (this.runnerY === 0 && this.velocity < 0) {
this.velocity = 0;
}
if (this.obstacleX >= 8 && this.obstacleX <= 10 && this.runnerY < 1) {
this.score = 0;
this.obstacleX = 46;
}
}
input(event: KeyEvent): GameAction | void {
if (event.ctrl && event.name === "g") return { type: "toggle_logs" };
if (event.name === "escape") return { type: "pause" };
if (event.name === "q") return { type: "quit" };
if (event.name === "l") return { type: "toggle_logs" };
if (["space", "up", "w"].includes(event.name) && this.runnerY === 0) {
this.velocity = 1.15;
}
}
render(frame: TerminalFrame) {
const ground = Math.max(7, frame.height - 9);
frame.box(0, 0, frame.width, frame.height - 5, `${this.title.toUpperCase()} CHECKS ${this.score}`);
frame.write(ground + 1, 4, "_".repeat(Math.max(10, frame.width - 8)));
frame.write(ground - Math.round(this.runnerY), 9, "@");
frame.write(ground, this.obstacleX, "X");
frame.write(ground - 2, Math.max(18, this.obstacleX + 10), "+");
frame.write(2, 4, "Low gravity. High uptime.");
frame.write(ground + 3, 4, "[Space/Up] Jump [L/Ctrl+G] Logs [Esc] Pause [Q] Quit");
}
}

View file

@ -0,0 +1,78 @@
import type { GameAction, GameContext, KeyEvent, TerminalFrame, WaitingGame } from "../types.js";
type Point = { x: number; y: number };
export class SnakeGame implements WaitingGame {
readonly id = "snake";
readonly title = "Token Snake";
readonly description = "Eat task tokens, grow the trail, and avoid blockers.";
readonly controls = [
{ key: "Arrow/WASD", action: "move" },
{ key: "L/Ctrl+G", action: "logs" },
{ key: "Esc", action: "pause" },
{ key: "Q", action: "quit" }
];
private snake: Point[] = [{ x: 12, y: 6 }];
private direction: Point = { x: 1, y: 0 };
private token: Point = { x: 20, y: 6 };
private elapsed = 0;
private score = 0;
private random = Math.random;
init(ctx: GameContext) {
this.random = ctx.random;
}
tick(deltaMs: number) {
this.elapsed += deltaMs;
if (this.elapsed < 150) {
return;
}
this.elapsed = 0;
const head = this.snake[0] ?? { x: 12, y: 6 };
const next = { x: head.x + this.direction.x, y: head.y + this.direction.y };
const maxX = 38;
const maxY = 12;
if (next.x < 1 || next.x > maxX || next.y < 1 || next.y > maxY || this.snake.some((point) => point.x === next.x && point.y === next.y)) {
this.snake = [{ x: 12, y: 6 }];
this.direction = { x: 1, y: 0 };
this.score = 0;
return;
}
this.snake.unshift(next);
if (next.x === this.token.x && next.y === this.token.y) {
this.score += 1;
this.token = { x: 1 + Math.floor(this.random() * maxX), y: 1 + Math.floor(this.random() * maxY) };
} else {
this.snake.pop();
}
}
input(event: KeyEvent): GameAction | void {
if (event.ctrl && event.name === "g") return { type: "toggle_logs" };
if (event.name === "escape") return { type: "pause" };
if (event.name === "q") return { type: "quit" };
if (event.name === "l") return { type: "toggle_logs" };
if (["up", "w", "k"].includes(event.name) && this.direction.y !== 1) this.direction = { x: 0, y: -1 };
if (["down", "s", "j"].includes(event.name) && this.direction.y !== -1) this.direction = { x: 0, y: 1 };
if (["left", "a", "h"].includes(event.name) && this.direction.x !== 1) this.direction = { x: -1, y: 0 };
if (["right", "d", "l"].includes(event.name) && this.direction.x !== -1) this.direction = { x: 1, y: 0 };
}
render(frame: TerminalFrame) {
frame.box(0, 0, frame.width, frame.height - 5, `${this.title.toUpperCase()} SCORE ${this.score}`);
for (let y = 1; y <= 12; y += 1) {
for (let x = 1; x <= 38; x += 1) {
frame.write(y + 2, x + 4, ".");
}
}
frame.write(this.token.y + 2, this.token.x + 4, "$");
for (const [index, point] of this.snake.entries()) {
frame.write(point.y + 2, point.x + 4, index === 0 ? "@" : "o");
}
frame.write(16, 4, "[Arrows/WASD] Move [L/Ctrl+G] Logs [Esc] Pause [Q] Quit");
}
}