terminull-arcade 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  // src/shared/constants.ts
4
4
  var APP_NAME = "TERMINULL";
5
5
  var APP_TAGLINE = "Enter the Terminull. Play beyond the prompt.";
6
- var APP_VERSION = "1.0.0";
6
+ var APP_VERSION = "1.0.2";
7
7
  var MIN_TERMINAL_COLUMNS = 80;
8
8
  var MIN_TERMINAL_ROWS = 24;
9
9
  var ALL_GAMES_METADATA = {
@@ -83,6 +83,105 @@ var ALL_GAMES_METADATA = {
83
83
  { id: "hash_miner", title: "Crypto Sovereign", description: "Compute 5,000 hashes in one session" },
84
84
  { id: "matrix_unlocked", title: "The White Rabbit", description: "Cycle through all visual modes" }
85
85
  ]
86
+ },
87
+ "level-devil": {
88
+ id: "level-devil",
89
+ name: "Level Devil",
90
+ tagline: "Get to the door. Trust nothing. Expect betrayal.",
91
+ description: "The infamous rage platformer: maneuver your runner to the exit door across 8 devious levels filled with rising spikes, disappearing floors, runaway doors, and inverted gravity.",
92
+ category: "arcade",
93
+ difficultyLevels: ["easy", "normal", "hard", "insane"],
94
+ controls: [
95
+ { key: "A / D / Arrow Keys", action: "Move Runner", description: "Walk left and right" },
96
+ { key: "Space / Up / W", action: "Jump", description: "Leap over pits and traps" },
97
+ { key: "R", action: "Instant Retry", description: "Instantly restart current level" },
98
+ { key: "Esc / P", action: "Pause Menu", description: "Pause game or access options" },
99
+ { key: "Q", action: "Return to Menu", description: "Quit to arcade roster" }
100
+ ],
101
+ achievements: [
102
+ { id: "first_betrayal", title: "First Betrayal", description: "Fall victim to your first surprise trap" },
103
+ { id: "midway_survivor", title: "Midway Survivor", description: "Conquer Level 4 without quitting" },
104
+ { id: "devil_conquered", title: "Devil Conquered", description: "Complete all 8 devilish levels" }
105
+ ]
106
+ },
107
+ "cyber-dino": {
108
+ id: "cyber-dino",
109
+ name: "Cyber Dino",
110
+ tagline: "Leap over cacti and duck under pterodactyls in the endless desert",
111
+ description: "The iconic jumping dinosaur runner: sprint through the retro desert, leap over prickly cacti, duck under flying pterodactyls, and survive the day/night cycle.",
112
+ category: "arcade",
113
+ difficultyLevels: ["easy", "normal", "hard", "insane"],
114
+ controls: [
115
+ { key: "Space / Up / W", action: "Jump", description: "Leap over ground cacti" },
116
+ { key: "Down / S", action: "Duck / Fast Fall", description: "Crouch under flying pterodactyls" },
117
+ { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" },
118
+ { key: "R", action: "Restart Game", description: "Restart desert run" },
119
+ { key: "Q", action: "Return to Game List", description: "Quit to arcade roster" }
120
+ ],
121
+ achievements: [
122
+ { id: "first_leap", title: "First Stride", description: "Jump over your first 5 cacti" },
123
+ { id: "centurion_run", title: "Desert Sprint", description: "Reach a score of 500 meters" },
124
+ { id: "pterodactyl_evasion", title: "Sky Dodger", description: "Duck under 10 flying pterodactyls" }
125
+ ]
126
+ },
127
+ "cyber-breakout": {
128
+ id: "cyber-breakout",
129
+ name: "Cyber Breakout",
130
+ tagline: "Smash digital bricks, deflect energy orbs, deploy power capsules",
131
+ description: "High-octane brick breaker: slide your cyber paddle, deflect high-velocity energy orbs through multi-tier defensive firewalls, and collect rare power capsules across advancing security sectors.",
132
+ category: "arcade",
133
+ difficultyLevels: ["easy", "normal", "hard", "insane"],
134
+ controls: [
135
+ { key: "Left / Right / A / D", action: "Move Paddle", description: "Slide paddle across bottom rail" },
136
+ { key: "Space", action: "Launch / Fire Lasers", description: "Serve ball from paddle or fire laser blasters" },
137
+ { key: "Esc / P", action: "Pause Menu", description: "Open pause / exit dialog" },
138
+ { key: "R", action: "Restart Game", description: "Restart round" },
139
+ { key: "Q", action: "Quit", description: "Return to arcade menu" }
140
+ ],
141
+ achievements: [
142
+ { id: "first_smash", title: "Firewall Breach", description: "Destroy your first defensive brick" },
143
+ { id: "power_surge", title: "Capsule Overload", description: "Collect a rare power-up capsule" },
144
+ { id: "brick_demolisher", title: "Master Breaker", description: "Clear an entire brick wave" }
145
+ ]
146
+ },
147
+ "cyber-2048": {
148
+ id: "cyber-2048",
149
+ name: "Cyber 2048",
150
+ tagline: "Slide and synthesize memory blocks to reach the 2048 cyber singularity",
151
+ description: "The definitive sliding puzzle: shift memory blocks across a 4x4 matrix, synthesize matching numerical cells, unlock power combos, and strive to synthesize the legendary 2048 core.",
152
+ category: "puzzle",
153
+ difficultyLevels: ["easy", "normal", "hard", "insane"],
154
+ controls: [
155
+ { key: "Arrow Keys / WASD", action: "Slide Grid", description: "Shift all memory tiles in direction" },
156
+ { key: "U", action: "Undo Last Move", description: "Revert to previous board state" },
157
+ { key: "Esc / P", action: "Pause Menu", description: "Open pause / exit dialog" },
158
+ { key: "R", action: "Restart Game", description: "Reset board with fresh seed" },
159
+ { key: "Q", action: "Quit", description: "Return to arcade menu" }
160
+ ],
161
+ achievements: [
162
+ { id: "first_merge", title: "First Synthesis", description: "Synthesize your first matching pair of tiles" },
163
+ { id: "reach_1024", title: "Kilo Byte", description: "Synthesize a 1024 memory core" },
164
+ { id: "reach_2048", title: "Cyber Singularity", description: "Synthesize the legendary 2048 core" }
165
+ ]
166
+ },
167
+ "cyber-tower": {
168
+ id: "cyber-tower",
169
+ name: "Cyber Tower",
170
+ tagline: "Drop oscillating blocks with split-second precision to build a spire",
171
+ description: "Precision architectural stacking: drop high-altitude structural floors, trim overhangs with mathematical accuracy, chain perfect drops, and erect a skyscraper piercing the cyber stratosphere.",
172
+ category: "arcade",
173
+ difficultyLevels: ["easy", "normal", "hard", "insane"],
174
+ controls: [
175
+ { key: "Space / Down / Enter", action: "Drop Floor Block", description: "Release sliding floor onto tower" },
176
+ { key: "Esc / P", action: "Pause Menu", description: "Open pause / exit dialog" },
177
+ { key: "R", action: "Restart Game", description: "Demolish and rebuild from ground" },
178
+ { key: "Q", action: "Quit", description: "Return to arcade menu" }
179
+ ],
180
+ achievements: [
181
+ { id: "first_floor", title: "Ground Floor", description: "Successfully place your first tower floor" },
182
+ { id: "perfect_streak", title: "Architectural Perfection", description: "Land 3 consecutive PERFECT drops" },
183
+ { id: "stratosphere", title: "Orbit Reached", description: "Build a skyscraper 30 floors high" }
184
+ ]
86
185
  }
87
186
  };
88
187
 
@@ -401,16 +500,22 @@ var TerminalRenderer = class {
401
500
  */
402
501
  renderFrame(content) {
403
502
  if (!process.stdout.isTTY) return;
404
- const lines = content.split("\n");
503
+ const termRows = process.stdout.rows || 24;
504
+ const rawLines = content.split("\n");
505
+ while (rawLines.length > 0 && rawLines[rawLines.length - 1] === "") {
506
+ rawLines.pop();
507
+ }
508
+ const maxLines = Math.min(rawLines.length, termRows);
405
509
  let output = "\x1B[?25l\x1B[H";
406
- for (let i = 0; i < lines.length; i++) {
407
- output += `${lines[i]}\x1B[K
510
+ for (let i = 0; i < maxLines; i++) {
511
+ const line = rawLines[i] || "";
512
+ output += i === maxLines - 1 ? `${line}\x1B[K` : `${line}\x1B[K
408
513
  `;
409
514
  }
410
- if (lines.length < this.previousLineCount) {
515
+ if (maxLines < this.previousLineCount) {
411
516
  output += "\x1B[J";
412
517
  }
413
- this.previousLineCount = lines.length;
518
+ this.previousLineCount = maxLines;
414
519
  process.stdout.write(output);
415
520
  }
416
521
  /**
@@ -473,9 +578,9 @@ var TerminalRenderer = class {
473
578
  });
474
579
  return [top, ...middle, bottom].join("\n");
475
580
  }
476
- renderHeader(options) {
581
+ renderHeader(options, customWidth) {
477
582
  const t = this.currentTheme;
478
- const cols = Math.min(process.stdout.columns || 80, 80);
583
+ const cols = customWidth || Math.min(process.stdout.columns || 80, 80);
479
584
  const leftPart = `${t.highlight(options.title)} ${options.category ? t.muted(`[${options.category.toUpperCase()}]`) : ""}`;
480
585
  const diffPart = options.difficulty ? t.secondary(`DIFF: ${options.difficulty.toUpperCase()}`) : "";
481
586
  const scorePart = options.score !== void 0 ? t.primary(`SCORE: ${options.score}`) : "";
@@ -483,19 +588,36 @@ var TerminalRenderer = class {
483
588
  const stats = [diffPart, scorePart, highPart].filter(Boolean).join(" \u2502 ");
484
589
  const cleanLeft = leftPart.replace(/\x1b\[[0-9;]*m/g, "").length;
485
590
  const cleanRight = stats.replace(/\x1b\[[0-9;]*m/g, "").length;
486
- const spaceCount = Math.max(2, cols - cleanLeft - cleanRight - 2);
487
- return `
488
- ${leftPart}${" ".repeat(spaceCount)}${stats}
489
- ${t.border("\u2500".repeat(cols - 4))}
490
- `;
591
+ const spaceCount = Math.max(2, cols - cleanLeft - cleanRight);
592
+ return `${leftPart}${" ".repeat(spaceCount)}${stats}
593
+ ${t.border("\u2500".repeat(cols))}`;
491
594
  }
492
- renderFooter(instructions) {
595
+ renderFooter(instructions, customWidth) {
493
596
  const t = this.currentTheme;
494
- const cols = Math.min(process.stdout.columns || 80, 80);
495
- return `
496
- ${t.border("\u2500".repeat(cols - 4))}
497
- ${t.muted(instructions)}
498
- `;
597
+ const cols = customWidth || Math.min(process.stdout.columns || 80, 80);
598
+ return `${t.border("\u2500".repeat(cols))}
599
+ ${t.muted(instructions)}`;
600
+ }
601
+ /**
602
+ * Centers a multi-line text block both horizontally and vertically within the terminal window.
603
+ */
604
+ centerBlock(content, blockWidth) {
605
+ const termCols = process.stdout.columns || 80;
606
+ const termRows = process.stdout.rows || 24;
607
+ const lines = content.replace(/^\n+/, "").replace(/\n+$/, "").split("\n");
608
+ let width = blockWidth || 0;
609
+ if (!width) {
610
+ for (const line of lines) {
611
+ const clean = line.replace(/\x1b\[[0-9;]*m/g, "");
612
+ if (clean.length > width) width = clean.length;
613
+ }
614
+ }
615
+ const hPad = Math.max(0, Math.floor((termCols - width) / 2));
616
+ const maxVPad = Math.max(0, Math.floor((termRows - lines.length) / 2));
617
+ const vPad = Math.min(2, maxVPad);
618
+ const hSpace = " ".repeat(hPad);
619
+ const centeredLines = lines.map((l) => l.length === 0 ? "" : hSpace + l);
620
+ return (vPad > 0 ? "\n".repeat(vPad) : "") + centeredLines.join("\n");
499
621
  }
500
622
  };
501
623
  var defaultRenderer = new TerminalRenderer();
@@ -768,6 +890,39 @@ function wordWrap(text, maxWidth) {
768
890
 
769
891
  // src/core/menu.ts
770
892
  import chalk2 from "chalk";
893
+
894
+ // src/core/update-check.ts
895
+ async function checkForUpdate() {
896
+ try {
897
+ const res = await fetch("https://registry.npmjs.org/terminull-arcade/latest", {
898
+ signal: AbortSignal.timeout(1200)
899
+ });
900
+ if (!res.ok) return null;
901
+ const data = await res.json();
902
+ if (!data.version) return null;
903
+ const hasUpdate = isNewerVersion(data.version, APP_VERSION);
904
+ return {
905
+ hasUpdate,
906
+ currentVersion: APP_VERSION,
907
+ latestVersion: data.version
908
+ };
909
+ } catch {
910
+ return null;
911
+ }
912
+ }
913
+ function isNewerVersion(latest, current) {
914
+ const lParts = latest.split(".").map((n) => parseInt(n, 10) || 0);
915
+ const cParts = current.split(".").map((n) => parseInt(n, 10) || 0);
916
+ for (let i = 0; i < Math.max(lParts.length, cParts.length); i++) {
917
+ const l = lParts[i] || 0;
918
+ const c = cParts[i] || 0;
919
+ if (l > c) return true;
920
+ if (l < c) return false;
921
+ }
922
+ return false;
923
+ }
924
+
925
+ // src/core/menu.ts
771
926
  var HACKER_STAGE_1 = [
772
927
  "ACCESSING ORBITAL DEFENSE SATELLITE...",
773
928
  "LOCATING PENTAGON FIBER-OPTIC TRUNK...",
@@ -816,7 +971,9 @@ async function playArcadeLoadingScreen(game, renderer = defaultRenderer, storage
816
971
  "packet-man": "Tip: Grab Super Capacitors to hunt blue daemons for combos!",
817
972
  "cyber-viper": "Tip: Snag rare golden bonus orbs quickly for 5x points!",
818
973
  "void-invaders": "Tip: Blast descending aliens before they touch ground! 3 lives.",
819
- "hash-matrix": "Tip: Press Space to freeze stream, M for mode, C for color theme!"
974
+ "hash-matrix": "Tip: Press Space to freeze stream, M for mode, C for color theme!",
975
+ "level-devil": "Tip: Expect betrayal. If a door or floor looks safe, it definitely is not.",
976
+ "cyber-dino": "Tip: Press Space/Up to leap over cacti, Down/S to duck under pterodactyls!"
820
977
  };
821
978
  const tip = tips[game.id] || "Tip: Press Esc or P at any time to pause or access settings.";
822
979
  const pick = (arr) => arr[Math.floor(Math.random() * arr.length)];
@@ -843,12 +1000,7 @@ async function playArcadeLoadingScreen(game, renderer = defaultRenderer, storage
843
1000
  ""
844
1001
  ];
845
1002
  const box = renderer.createBox(innerLines, width, "TERMINULL ARCADE SYSTEM");
846
- renderer.draw(`
847
-
848
-
849
- ${box}
850
-
851
- `);
1003
+ renderer.draw(renderer.centerBlock(box, width));
852
1004
  await new Promise((r) => setTimeout(r, step.delay));
853
1005
  }
854
1006
  }
@@ -865,6 +1017,7 @@ var ArcadeMenu = class {
865
1017
  onSelectCallback = null;
866
1018
  animTimer = null;
867
1019
  animFrame = 0;
1020
+ updateInfo = null;
868
1021
  constructor(storage = defaultStorage, achievements = defaultAchievements, renderer = defaultRenderer) {
869
1022
  this.storage = storage;
870
1023
  this.achievements = achievements;
@@ -877,6 +1030,12 @@ var ArcadeMenu = class {
877
1030
  this.renderer.setTheme(profile.settings.theme);
878
1031
  this.renderer.enterScreen();
879
1032
  this.render();
1033
+ checkForUpdate().then((info) => {
1034
+ if (info?.hasUpdate) {
1035
+ this.updateInfo = info;
1036
+ this.render();
1037
+ }
1038
+ });
880
1039
  if (!profile.settings.reducedMotion) {
881
1040
  this.animTimer = setInterval(() => {
882
1041
  this.animFrame = (this.animFrame + 1) % 2;
@@ -906,7 +1065,7 @@ var ArcadeMenu = class {
906
1065
  }
907
1066
  }
908
1067
  getFilteredGames() {
909
- const all = Object.values(ALL_GAMES_METADATA);
1068
+ const all = Object.values(ALL_GAMES_METADATA).filter((g) => g.id !== "level-devil");
910
1069
  if (!this.searchQuery.trim()) return all;
911
1070
  const q = this.searchQuery.toLowerCase();
912
1071
  return all.filter(
@@ -1058,7 +1217,7 @@ var ArcadeMenu = class {
1058
1217
  } else if (this.currentTab === "settings") {
1059
1218
  body = this.renderSettingsTab();
1060
1219
  }
1061
- this.renderer.draw(body);
1220
+ this.renderer.draw(this.renderer.centerBlock(body, 72));
1062
1221
  }
1063
1222
  renderFunkyBanner() {
1064
1223
  const t = this.renderer.getTheme();
@@ -1116,6 +1275,8 @@ var ArcadeMenu = class {
1116
1275
  `;
1117
1276
  const searchBar = this.isSearching ? ` ${t.warning("SEARCH >")} ${this.searchQuery}\u2588
1118
1277
  ` : this.searchQuery ? ` ${t.muted("Filtered by:")} "${this.searchQuery}" (Press / to edit)
1278
+ ` : "";
1279
+ const updateBar = this.updateInfo?.hasUpdate ? ` ${t.warning(`[UPDATE AVAILABLE: v${this.updateInfo.currentVersion} -> v${this.updateInfo.latestVersion} \u2502 Run: npx terminull-arcade@latest]`)}
1119
1280
  ` : "";
1120
1281
  const listLines = ["", t.highlight("ARCADE SELECTION:")];
1121
1282
  for (let i = 0; i < filtered.length; i++) {
@@ -1133,7 +1294,7 @@ var ArcadeMenu = class {
1133
1294
  }
1134
1295
  listLines.push("");
1135
1296
  listLines.push(t.border("\u2500\u2500 QUICK CONTROLS \u2500\u2500\u2500\u2500"));
1136
- listLines.push(` ${t.primary("[1-4]")} ${t.muted("Select / Play")}`);
1297
+ listLines.push(` ${t.primary("[1-5]")} ${t.muted("Select / Play")}`);
1137
1298
  listLines.push(` ${t.secondary("[D]")} ${this.renderDifficultyBadge(this.selectedDifficulty)}`);
1138
1299
  listLines.push(` ${t.accent("[T]")} ${t.muted("Theme:")} ${t.highlight(profile.settings.theme.toUpperCase())}`);
1139
1300
  listLines.push(` ${t.muted("[B] Sound:")} ${profile.settings.soundEnabled ? t.success("ON") : t.muted("OFF")}`);
@@ -1149,11 +1310,11 @@ var ArcadeMenu = class {
1149
1310
  const achs = this.achievements.getAchievementsForGame(activeGame.id);
1150
1311
  const unlockedAchs = achs.filter((a) => a.unlocked).length;
1151
1312
  detailLines.push(t.highlight(activeGame.name.toUpperCase()));
1152
- for (const line of wordWrap(activeGame.tagline, 40)) {
1313
+ for (const line of wordWrap(activeGame.tagline, 36)) {
1153
1314
  detailLines.push(t.secondary(line));
1154
1315
  }
1155
1316
  detailLines.push("");
1156
- for (const line of wordWrap(activeGame.description, 40)) {
1317
+ for (const line of wordWrap(activeGame.description, 36)) {
1157
1318
  detailLines.push(line);
1158
1319
  }
1159
1320
  detailLines.push("");
@@ -1166,23 +1327,23 @@ var ArcadeMenu = class {
1166
1327
  detailLines.push(` ${t.primary(ctrl.key.padEnd(14))} ${ctrl.action}`);
1167
1328
  }
1168
1329
  }
1169
- const detailBox = this.renderer.createBox(detailLines, 46, "TELEMETRY");
1330
+ const detailBox = this.renderer.createBox(detailLines, 42, "TELEMETRY");
1170
1331
  const detailBoxLines = detailBox.split("\n");
1171
1332
  const combinedLines = [];
1172
1333
  const maxRows = Math.max(listLines.length, detailBoxLines.length);
1173
1334
  for (let r = 0; r < maxRows; r++) {
1174
- const left = padRightVisible(listLines[r] || "", 30);
1335
+ const left = padRightVisible(listLines[r] || "", 26);
1175
1336
  const right = detailBoxLines[r] || "";
1176
1337
  combinedLines.push(` ${left} ${right}`);
1177
1338
  }
1178
1339
  const footer = [
1179
- ` ${t.border("\u2500".repeat(74))}`,
1180
- ` ${t.primary("Enter/Space")}: Play \u2502 ${t.secondary("1-4")}: Select \u2502 ${t.accent("D")}: Difficulty \u2502 ${t.primary("T")}: Theme \u2502 ${t.muted("Q")}: Exit`
1340
+ ` ${t.border("\u2500".repeat(72))}`,
1341
+ ` ${t.primary("Enter/Space")}: Play \u2502 ${t.secondary("1-5")}: Select \u2502 ${t.accent("D")}: Diff \u2502 ${t.primary("T")}: Theme \u2502 ${t.muted("Q")}: Exit`
1181
1342
  ].join("\n");
1182
1343
  return `
1183
1344
  ${banner}
1184
1345
  ${tabs}
1185
- ${searchBar}
1346
+ ${updateBar}${searchBar}
1186
1347
  ${combinedLines.join("\n")}
1187
1348
 
1188
1349
  ${footer}
@@ -2724,11 +2885,7 @@ var VoidInvadersGame = class {
2724
2885
  t.primary("Press Space or Enter to engage armada \u2502 Esc / Q to Exit")
2725
2886
  ];
2726
2887
  const box = this.renderer.createBox(lines, 64, "SPACE INVADERS MANUAL");
2727
- this.renderer.clear();
2728
- this.renderer.draw(`
2729
-
2730
- ${box}
2731
- `);
2888
+ this.renderer.renderFrame(this.renderer.centerBlock(box, 64));
2732
2889
  return;
2733
2890
  }
2734
2891
  if (this.isPaused) {
@@ -2748,24 +2905,21 @@ ${box}
2748
2905
  t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Return to Game List")
2749
2906
  ];
2750
2907
  const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
2751
- this.renderer.clear();
2752
- this.renderer.draw(`
2753
-
2754
- ${pauseBox}
2755
- `);
2908
+ this.renderer.renderFrame(this.renderer.centerBlock(pauseBox, 64));
2756
2909
  return;
2757
2910
  }
2911
+ const totalWidth = ARENA_WIDTH + 2;
2758
2912
  const header = this.renderer.renderHeader({
2759
2913
  title: "SPACE INVADERS",
2760
2914
  category: "ARCADE",
2761
2915
  difficulty: this.config?.difficulty,
2762
2916
  score: this.state.score
2763
- });
2917
+ }, totalWidth);
2764
2918
  const hudLines = [];
2765
2919
  const livesStr = `${t.muted("Cannons:")} ${t.highlight("\u25B2\u2550\u25B2 ".repeat(Math.max(0, this.state.lives)))}`;
2766
2920
  const defeatedStr = `${t.muted("Destroyed:")} ${t.primary(this.state.invadersDestroyed.toString())}`;
2767
2921
  const levelStr = `${t.muted("Level:")} ${t.secondary(this.state.wave.toString())}`;
2768
- hudLines.push(` ${livesStr} ${defeatedStr} ${levelStr}`);
2922
+ hudLines.push(`${livesStr} ${defeatedStr} ${levelStr}`);
2769
2923
  const grid = [];
2770
2924
  for (let y = 0; y < ARENA_HEIGHT; y++) {
2771
2925
  grid.push(new Array(ARENA_WIDTH).fill(" "));
@@ -2788,7 +2942,7 @@ ${pauseBox}
2788
2942
  grid[PLAYER_Y][px + 2] = "\u25B2";
2789
2943
  }
2790
2944
  const boardLines = [];
2791
- boardLines.push(` ${t.border("\u250C" + "\u2500".repeat(ARENA_WIDTH) + "\u2510")}`);
2945
+ boardLines.push(t.border("\u250C" + "\u2500".repeat(ARENA_WIDTH) + "\u2510"));
2792
2946
  for (let y = 0; y < ARENA_HEIGHT; y++) {
2793
2947
  let row = "";
2794
2948
  for (let x = 0; x < ARENA_WIDTH; x++) {
@@ -2809,24 +2963,22 @@ ${pauseBox}
2809
2963
  row += ch;
2810
2964
  }
2811
2965
  }
2812
- boardLines.push(` ${t.border("\u2502")}${row}${t.border("\u2502")}`);
2966
+ boardLines.push(`${t.border("\u2502")}${row}${t.border("\u2502")}`);
2813
2967
  }
2814
- boardLines.push(` ${t.border("\u2514" + "\u2500".repeat(ARENA_WIDTH) + "\u2518")}`);
2968
+ boardLines.push(t.border("\u2514" + "\u2500".repeat(ARENA_WIDTH) + "\u2518"));
2815
2969
  if (this.state.isGameOver) {
2816
- boardLines.push(`
2817
- ${t.error("\u{1F4A5} DEFENSES BREACHED! EARTH OVERRUN.")}`);
2818
- boardLines.push(` ${t.accent(`Invaders Destroyed: ${this.state.invadersDestroyed} \u2502 Final Score: ${this.state.score}`)}`);
2819
- boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Return to Game List.")}`);
2970
+ boardLines.push("");
2971
+ boardLines.push(t.error("\u{1F4A5} DEFENSES BREACHED! EARTH OVERRUN."));
2972
+ boardLines.push(t.accent(`Invaders Destroyed: ${this.state.invadersDestroyed} \u2502 Final Score: ${this.state.score}`));
2973
+ boardLines.push(t.muted("Press R to Re-engage, or Esc / Q to Return to Game List."));
2820
2974
  } else {
2821
- boardLines.push(`
2822
- ${t.muted("Controls: Left/Right / A/D: Move \u2502 Space: Fire \u2502 Esc/P: Pause \u2502 Q: Return to Game List")}`);
2975
+ boardLines.push("");
2976
+ boardLines.push(t.muted("Controls: Left/Right / A/D: Move \u2502 Space: Fire \u2502 Esc/P: Pause \u2502 Q: Return to Game List"));
2823
2977
  }
2824
- this.renderer.clear();
2825
- this.renderer.draw(`
2826
- ${header}
2978
+ const fullCanvas = `${header}
2827
2979
  ${hudLines.join("\n")}
2828
- ${boardLines.join("\n")}
2829
- `);
2980
+ ${boardLines.join("\n")}`;
2981
+ this.renderer.renderFrame(this.renderer.centerBlock(fullCanvas, totalWidth));
2830
2982
  }
2831
2983
  getState() {
2832
2984
  return this.state;
@@ -3217,6 +3369,2465 @@ var HashMatrixGame = class {
3217
3369
  }
3218
3370
  };
3219
3371
 
3372
+ // src/games/cyber-dino/index.ts
3373
+ var ARENA_WIDTH2 = 70;
3374
+ var ARENA_HEIGHT2 = 14;
3375
+ var GROUND_ROW = 10;
3376
+ var DINO_X = 6;
3377
+ var CyberDinoGame = class {
3378
+ id = "cyber-dino";
3379
+ metadata = ALL_GAMES_METADATA["cyber-dino"];
3380
+ config = null;
3381
+ renderer = defaultRenderer;
3382
+ input = new TerminalInputHandler();
3383
+ rng = new DeterministicRNG();
3384
+ gameLoopTimer = null;
3385
+ obstacleIdCounter = 0;
3386
+ tickIntervalMs = 50;
3387
+ // Smooth ~20 FPS runner
3388
+ state = {
3389
+ dinoY: 0,
3390
+ dinoVelocityY: 0,
3391
+ isGrounded: true,
3392
+ isDucking: false,
3393
+ duckTicksRemaining: 0,
3394
+ runFrame: 0,
3395
+ score: 0,
3396
+ highScore: 0,
3397
+ speed: 1,
3398
+ isNightMode: false,
3399
+ nightModeCountdown: 0,
3400
+ obstacles: [],
3401
+ groundOffset: 0,
3402
+ cactiCleared: 0,
3403
+ pterodactylsDucked: 0,
3404
+ isGameOver: false
3405
+ };
3406
+ isPaused = false;
3407
+ pauseMenuIndex = 0;
3408
+ showTutorial = true;
3409
+ ticksSinceLastObstacle = 0;
3410
+ init(config) {
3411
+ this.config = config;
3412
+ this.renderer.setTheme(config.theme);
3413
+ this.rng = new DeterministicRNG(config.seed || Date.now());
3414
+ if (config.skipTutorial !== void 0) {
3415
+ this.showTutorial = !config.skipTutorial;
3416
+ }
3417
+ const speedMap = {
3418
+ easy: 60,
3419
+ normal: 45,
3420
+ hard: 35,
3421
+ insane: 25
3422
+ };
3423
+ this.tickIntervalMs = speedMap[config.difficulty] || 45;
3424
+ this.resetState(config.difficulty);
3425
+ }
3426
+ start() {
3427
+ this.isPaused = false;
3428
+ this.render();
3429
+ this.input.start(
3430
+ (key) => this.handleInput(key),
3431
+ () => {
3432
+ this.destroy();
3433
+ this.config?.onExit?.();
3434
+ }
3435
+ );
3436
+ if (!this.showTutorial) {
3437
+ this.scheduleNextTick();
3438
+ }
3439
+ }
3440
+ pause() {
3441
+ this.isPaused = true;
3442
+ if (this.gameLoopTimer) {
3443
+ clearTimeout(this.gameLoopTimer);
3444
+ this.gameLoopTimer = null;
3445
+ }
3446
+ }
3447
+ resume() {
3448
+ this.isPaused = false;
3449
+ this.scheduleNextTick();
3450
+ }
3451
+ restart() {
3452
+ this.resetState(this.config?.difficulty || "normal");
3453
+ this.render();
3454
+ this.scheduleNextTick();
3455
+ }
3456
+ saveState() {
3457
+ return {
3458
+ state: this.state,
3459
+ showTutorial: this.showTutorial
3460
+ };
3461
+ }
3462
+ loadState(saved) {
3463
+ if (saved["state"]) this.state = saved["state"];
3464
+ if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
3465
+ }
3466
+ handleInputForTest(key) {
3467
+ this.handleInput(key);
3468
+ }
3469
+ destroy() {
3470
+ if (this.gameLoopTimer) {
3471
+ clearTimeout(this.gameLoopTimer);
3472
+ this.gameLoopTimer = null;
3473
+ }
3474
+ this.input.stop();
3475
+ }
3476
+ resetState(difficulty) {
3477
+ this.state = {
3478
+ dinoY: 0,
3479
+ dinoVelocityY: 0,
3480
+ isGrounded: true,
3481
+ isDucking: false,
3482
+ duckTicksRemaining: 0,
3483
+ runFrame: 0,
3484
+ score: 0,
3485
+ highScore: this.state.highScore || 0,
3486
+ speed: difficulty === "easy" ? 0.9 : difficulty === "hard" ? 1.3 : difficulty === "insane" ? 1.6 : 1,
3487
+ isNightMode: false,
3488
+ nightModeCountdown: 0,
3489
+ obstacles: [],
3490
+ groundOffset: 0,
3491
+ cactiCleared: 0,
3492
+ pterodactylsDucked: 0,
3493
+ isGameOver: false
3494
+ };
3495
+ this.ticksSinceLastObstacle = 15;
3496
+ }
3497
+ scheduleNextTick() {
3498
+ if (this.isPaused || this.state.isGameOver || this.showTutorial) return;
3499
+ this.gameLoopTimer = setTimeout(() => {
3500
+ this.tick();
3501
+ this.scheduleNextTick();
3502
+ }, this.tickIntervalMs);
3503
+ }
3504
+ tick() {
3505
+ if (this.state.isGameOver || this.isPaused || this.showTutorial) return;
3506
+ this.state.score++;
3507
+ if (this.state.score % 100 === 0) {
3508
+ if (this.config?.soundEnabled) playTerminalBell();
3509
+ }
3510
+ if (this.state.score % 200 === 0) {
3511
+ this.state.speed = Math.min(2.5, this.state.speed + 0.08);
3512
+ }
3513
+ const cycle = this.state.score % 700;
3514
+ this.state.isNightMode = cycle >= 500;
3515
+ if (this.state.score % 3 === 0) {
3516
+ this.state.runFrame = (this.state.runFrame + 1) % 2;
3517
+ }
3518
+ if (!this.state.isGrounded) {
3519
+ this.state.dinoY += this.state.dinoVelocityY;
3520
+ this.state.dinoVelocityY -= 0.26;
3521
+ if (this.state.dinoY <= 0) {
3522
+ this.state.dinoY = 0;
3523
+ this.state.dinoVelocityY = 0;
3524
+ this.state.isGrounded = true;
3525
+ }
3526
+ }
3527
+ if (this.state.duckTicksRemaining > 0) {
3528
+ this.state.duckTicksRemaining--;
3529
+ if (this.state.duckTicksRemaining === 0) {
3530
+ this.state.isDucking = false;
3531
+ }
3532
+ }
3533
+ this.state.groundOffset = (this.state.groundOffset + 1) % ARENA_WIDTH2;
3534
+ const step = Math.max(1, Math.round(this.state.speed));
3535
+ const activeObstacles = [];
3536
+ for (const obs of this.state.obstacles) {
3537
+ obs.x -= step;
3538
+ if (obs.type.startsWith("pterodactyl")) {
3539
+ obs.wingFrame = ((obs.wingFrame || 0) + 1) % 2;
3540
+ }
3541
+ if (obs.x + obs.width < DINO_X && obs.x + obs.width >= DINO_X - step) {
3542
+ if (obs.type.startsWith("cactus")) {
3543
+ this.state.cactiCleared++;
3544
+ if (this.state.cactiCleared >= 5) {
3545
+ this.config?.onAchievementUnlock?.("first_leap");
3546
+ }
3547
+ } else if (this.state.isDucking) {
3548
+ this.state.pterodactylsDucked++;
3549
+ if (this.state.pterodactylsDucked >= 10) {
3550
+ this.config?.onAchievementUnlock?.("pterodactyl_evasion");
3551
+ }
3552
+ }
3553
+ }
3554
+ if (obs.x + obs.width > 0) {
3555
+ activeObstacles.push(obs);
3556
+ }
3557
+ }
3558
+ this.state.obstacles = activeObstacles;
3559
+ this.ticksSinceLastObstacle++;
3560
+ const minGap = Math.max(20, Math.floor(32 / this.state.speed));
3561
+ if (this.ticksSinceLastObstacle > minGap && this.rng.next() < 0.22) {
3562
+ this.spawnObstacle();
3563
+ this.ticksSinceLastObstacle = 0;
3564
+ }
3565
+ if (this.checkCollision()) {
3566
+ this.state.isGameOver = true;
3567
+ if (this.state.score > this.state.highScore) {
3568
+ this.state.highScore = this.state.score;
3569
+ }
3570
+ this.config?.onGameOver?.(this.state.score);
3571
+ if (this.config?.soundEnabled) playTerminalBell();
3572
+ this.render();
3573
+ return;
3574
+ }
3575
+ if (this.state.score >= 500) {
3576
+ this.config?.onAchievementUnlock?.("centurion_run");
3577
+ }
3578
+ this.config?.onScoreUpdate?.(this.state.score);
3579
+ this.render();
3580
+ }
3581
+ spawnObstacle() {
3582
+ const allowsPtero = this.state.score > 120;
3583
+ const rand = this.rng.next();
3584
+ let type = "cactus-small";
3585
+ let width = 2;
3586
+ let height = 2;
3587
+ let y = 0;
3588
+ if (allowsPtero && rand > 0.65) {
3589
+ if (rand > 0.85) {
3590
+ type = "pterodactyl-mid";
3591
+ y = 2;
3592
+ } else if (rand > 0.75) {
3593
+ type = "pterodactyl-low";
3594
+ y = 1;
3595
+ } else {
3596
+ type = "pterodactyl-high";
3597
+ y = 5;
3598
+ }
3599
+ width = 2;
3600
+ height = 2;
3601
+ } else {
3602
+ if (rand > 0.45) {
3603
+ type = "cactus-triple";
3604
+ width = 3;
3605
+ height = 2;
3606
+ } else if (rand > 0.22) {
3607
+ type = "cactus-double";
3608
+ width = 2;
3609
+ height = 2;
3610
+ } else {
3611
+ type = "cactus-small";
3612
+ width = 1;
3613
+ height = 2;
3614
+ }
3615
+ y = 0;
3616
+ }
3617
+ this.state.obstacles.push({
3618
+ id: ++this.obstacleIdCounter,
3619
+ x: ARENA_WIDTH2 - 2,
3620
+ y,
3621
+ width,
3622
+ height,
3623
+ type,
3624
+ wingFrame: 0
3625
+ });
3626
+ }
3627
+ checkCollision() {
3628
+ const dinoY = Math.floor(this.state.dinoY);
3629
+ const dinoHeight = this.state.isDucking ? 2 : 3;
3630
+ const dinoWidth = this.state.isDucking ? 5 : 4;
3631
+ const dinoLeft = DINO_X + 1;
3632
+ const dinoRight = DINO_X + dinoWidth - 2;
3633
+ const dinoBottom = dinoY;
3634
+ const dinoTop = dinoY + dinoHeight - 1;
3635
+ for (const obs of this.state.obstacles) {
3636
+ const obsLeft = Math.floor(obs.x);
3637
+ const obsRight = obsLeft + obs.width - 1;
3638
+ const obsBottom = obs.y;
3639
+ const obsTop = obs.y + obs.height - 1;
3640
+ const xOverlap = dinoRight >= obsLeft && dinoLeft <= obsRight;
3641
+ const yOverlap = dinoTop >= obsBottom && dinoBottom <= obsTop;
3642
+ if (xOverlap && yOverlap) {
3643
+ return true;
3644
+ }
3645
+ }
3646
+ return false;
3647
+ }
3648
+ handleInput(key) {
3649
+ if (this.showTutorial) {
3650
+ if (key.name === "return" || key.name === "space") {
3651
+ this.showTutorial = false;
3652
+ this.scheduleNextTick();
3653
+ this.render();
3654
+ } else if (key.name === "escape" || key.name === "q") {
3655
+ this.destroy();
3656
+ this.config?.onExit?.();
3657
+ }
3658
+ return;
3659
+ }
3660
+ if (this.isPaused) {
3661
+ if (key.name === "up" || key.name === "w") {
3662
+ this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
3663
+ this.render();
3664
+ } else if (key.name === "down" || key.name === "s") {
3665
+ this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
3666
+ this.render();
3667
+ } else if (key.name === "return" || key.name === "space") {
3668
+ if (this.pauseMenuIndex === 0) {
3669
+ this.isPaused = false;
3670
+ this.scheduleNextTick();
3671
+ this.render();
3672
+ } else if (this.pauseMenuIndex === 1) {
3673
+ this.isPaused = false;
3674
+ this.restart();
3675
+ } else if (this.pauseMenuIndex === 2) {
3676
+ this.destroy();
3677
+ this.config?.onExit?.();
3678
+ }
3679
+ } else if (key.name === "escape" || key.name === "p") {
3680
+ this.isPaused = false;
3681
+ this.scheduleNextTick();
3682
+ this.render();
3683
+ } else if (key.name === "q") {
3684
+ this.destroy();
3685
+ this.config?.onExit?.();
3686
+ }
3687
+ return;
3688
+ }
3689
+ if (key.name === "escape" || key.name === "p") {
3690
+ this.isPaused = true;
3691
+ this.pauseMenuIndex = 0;
3692
+ if (this.gameLoopTimer) {
3693
+ clearTimeout(this.gameLoopTimer);
3694
+ this.gameLoopTimer = null;
3695
+ }
3696
+ this.render();
3697
+ return;
3698
+ }
3699
+ if (key.name === "q") {
3700
+ this.destroy();
3701
+ this.config?.onExit?.();
3702
+ return;
3703
+ }
3704
+ if (this.state.isGameOver) {
3705
+ if (key.name === "r") {
3706
+ this.restart();
3707
+ } else if (key.name === "escape" || key.name === "q") {
3708
+ this.destroy();
3709
+ this.config?.onExit?.();
3710
+ }
3711
+ return;
3712
+ }
3713
+ if (key.name === "space" || key.name === "up" || key.name === "w") {
3714
+ if (this.state.isGrounded) {
3715
+ this.state.dinoVelocityY = 1.85;
3716
+ this.state.isGrounded = false;
3717
+ this.state.isDucking = false;
3718
+ if (this.config?.soundEnabled) playTerminalBell();
3719
+ }
3720
+ return;
3721
+ }
3722
+ if (key.name === "down" || key.name === "s") {
3723
+ if (!this.state.isGrounded) {
3724
+ this.state.dinoVelocityY = -1.6;
3725
+ } else {
3726
+ this.state.isDucking = true;
3727
+ this.state.duckTicksRemaining = 8;
3728
+ }
3729
+ return;
3730
+ }
3731
+ }
3732
+ render() {
3733
+ const t = this.renderer.getTheme();
3734
+ if (this.showTutorial) {
3735
+ const lines = [
3736
+ "",
3737
+ t.highlight("CYBER DINO // DESERT RUNNER MANUAL"),
3738
+ "",
3739
+ "\u2022 Press Space, Up, or W to LEAP over cacti.",
3740
+ "\u2022 Press Down or S to DUCK under flying pterodactyls!",
3741
+ "\u2022 Press Down while in air to FAST FALL back to earth.",
3742
+ "\u2022 Survive the endless desert as speed continuously escalates.",
3743
+ "\u2022 Experience the retro Day / Night cycle every 500 meters.",
3744
+ "",
3745
+ t.border("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),
3746
+ t.primary("Press Space or Enter to launch \u2502 Q to Return to Game List")
3747
+ ];
3748
+ const box = this.renderer.createBox(lines, 84, "CYBER DINO PROTOCOL");
3749
+ this.renderer.renderFrame(this.renderer.centerBlock(box, 84));
3750
+ return;
3751
+ }
3752
+ if (this.isPaused) {
3753
+ const pauseItems = ["Resume Run (Esc / Enter)", "Restart Desert (R)", "Return to Game List (Q)"];
3754
+ const pauseLines = [
3755
+ "",
3756
+ t.highlight("\u2550\u2550\u2550 CYBER DINO PAUSED \u2550\u2550\u2550"),
3757
+ "",
3758
+ ...pauseItems.map((item, idx) => {
3759
+ if (idx === this.pauseMenuIndex) {
3760
+ return t.primary(` \u25B6 ${t.highlight(item)}`);
3761
+ }
3762
+ return t.muted(` ${item}`);
3763
+ }),
3764
+ "",
3765
+ t.border("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),
3766
+ t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Q: Return to Game List")
3767
+ ];
3768
+ const pauseBox = this.renderer.createBox(pauseLines, 84, "SYSTEM PAUSE");
3769
+ this.renderer.renderFrame(this.renderer.centerBlock(pauseBox, 84));
3770
+ return;
3771
+ }
3772
+ const totalWidth = ARENA_WIDTH2 + 2;
3773
+ const header = this.renderer.renderHeader({
3774
+ title: "CYBER DINO",
3775
+ category: "ARCADE",
3776
+ difficulty: this.config?.difficulty,
3777
+ score: this.state.score,
3778
+ highScore: this.state.highScore
3779
+ }, totalWidth);
3780
+ const grid = Array.from(
3781
+ { length: ARENA_HEIGHT2 },
3782
+ () => Array.from({ length: ARENA_WIDTH2 }, () => " ")
3783
+ );
3784
+ if (this.state.isNightMode) {
3785
+ grid[1][70] = t.accent("\u263E");
3786
+ grid[2][16] = t.muted("\xB7");
3787
+ grid[1][34] = t.muted("\u2605");
3788
+ grid[3][52] = t.muted("\xB7");
3789
+ grid[2][78] = t.muted("\xB7");
3790
+ } else {
3791
+ const cloudX = (ARENA_WIDTH2 - Math.floor(this.state.score / 4)) % ARENA_WIDTH2;
3792
+ if (cloudX >= 0 && cloudX + 6 < ARENA_WIDTH2) {
3793
+ grid[1][cloudX] = t.muted("\u2601");
3794
+ grid[1][cloudX + 1] = t.muted("\u2601");
3795
+ }
3796
+ }
3797
+ for (let x = 0; x < ARENA_WIDTH2; x++) {
3798
+ grid[GROUND_ROW][x] = t.border("\u2550");
3799
+ }
3800
+ const pebbleCycle = "_..._..___^___..____...__^..____.._";
3801
+ for (let x = 0; x < ARENA_WIDTH2; x++) {
3802
+ const pIdx = (x + this.state.groundOffset) % pebbleCycle.length;
3803
+ grid[GROUND_ROW + 1][x] = t.muted(pebbleCycle[pIdx] || "_");
3804
+ }
3805
+ const dinoY = Math.floor(this.state.dinoY);
3806
+ const dinoRowBase = GROUND_ROW - 1 - dinoY;
3807
+ if (this.state.isDucking) {
3808
+ if (dinoRowBase - 1 >= 0) {
3809
+ this.writeSprite(grid, DINO_X, dinoRowBase - 1, " \u2584\u2588\u2588\u2588\u2588\u2588", t.highlight);
3810
+ }
3811
+ if (dinoRowBase >= 0 && dinoRowBase < ARENA_HEIGHT2) {
3812
+ this.writeSprite(grid, DINO_X, dinoRowBase, " \u2580\u2580 \u2580\u2580", t.primary);
3813
+ }
3814
+ } else {
3815
+ if (dinoRowBase - 2 >= 0) {
3816
+ this.writeSprite(grid, DINO_X, dinoRowBase - 2, " \u2584\u2588\u2588\u2588", t.highlight);
3817
+ }
3818
+ if (dinoRowBase - 1 >= 0) {
3819
+ this.writeSprite(grid, DINO_X, dinoRowBase - 1, " \u2588\u2580\u2588\u2588\u2588", t.primary);
3820
+ }
3821
+ if (dinoRowBase >= 0 && dinoRowBase < ARENA_HEIGHT2) {
3822
+ const feet = this.state.isGrounded ? this.state.runFrame === 0 ? " \u2580 " : " \u2580 " : " \u2580 \u2580 ";
3823
+ this.writeSprite(grid, DINO_X, dinoRowBase, feet, t.primary);
3824
+ }
3825
+ }
3826
+ for (const obs of this.state.obstacles) {
3827
+ const ox = Math.floor(obs.x);
3828
+ const obsRowBase = GROUND_ROW - 1 - obs.y;
3829
+ if (obs.type === "cactus-small") {
3830
+ this.writeSprite(grid, ox, obsRowBase - 1, "\u2588", t.secondary);
3831
+ this.writeSprite(grid, ox, obsRowBase, "\u2588", t.secondary);
3832
+ } else if (obs.type === "cactus-double") {
3833
+ this.writeSprite(grid, ox, obsRowBase - 1, "\u2584\u2588", t.secondary);
3834
+ this.writeSprite(grid, ox, obsRowBase, "\u2588\u2588", t.secondary);
3835
+ } else if (obs.type === "cactus-triple") {
3836
+ this.writeSprite(grid, ox, obsRowBase - 1, "\u2588 \u2588", t.secondary);
3837
+ this.writeSprite(grid, ox, obsRowBase, "\u2588\u2588\u2588", t.secondary);
3838
+ } else if (obs.type.startsWith("pterodactyl")) {
3839
+ const isWingsUp = obs.wingFrame === 0;
3840
+ if (isWingsUp) {
3841
+ this.writeSprite(grid, ox, obsRowBase - 1, "\u2580\u2584", t.warning);
3842
+ this.writeSprite(grid, ox, obsRowBase, "\u2588\u2588", t.warning);
3843
+ } else {
3844
+ this.writeSprite(grid, ox, obsRowBase - 1, "\u2588\u2588", t.warning);
3845
+ this.writeSprite(grid, ox, obsRowBase, " \u2580", t.warning);
3846
+ }
3847
+ }
3848
+ }
3849
+ const arenaLines = [
3850
+ t.border("\u250C" + "\u2500".repeat(ARENA_WIDTH2) + "\u2510"),
3851
+ ...grid.map((row) => `${t.border("\u2502")}${row.join("")}${t.border("\u2502")}`),
3852
+ t.border("\u2514" + "\u2500".repeat(ARENA_WIDTH2) + "\u2518")
3853
+ ];
3854
+ if (this.state.isGameOver) {
3855
+ arenaLines.push("");
3856
+ arenaLines.push(t.error("\u{1F4A5} GAME OVER! DINO COLLIDED."));
3857
+ arenaLines.push(t.accent(`Final Distance: ${this.state.score}m \u2502 Best Record: ${this.state.highScore}m`));
3858
+ arenaLines.push(t.muted("Press R to Re-engage, or Esc / Q to Return to Game List."));
3859
+ } else {
3860
+ arenaLines.push("");
3861
+ arenaLines.push(t.muted("Space/Up/W: Jump \u2502 Down/S: Duck/Fall \u2502 Esc/P: Pause \u2502 Q: Return to Game List"));
3862
+ }
3863
+ const fullCanvas = `${header}
3864
+ ${arenaLines.join("\n")}`;
3865
+ this.renderer.renderFrame(this.renderer.centerBlock(fullCanvas, totalWidth));
3866
+ }
3867
+ writeSprite(grid, x, y, text, colorize) {
3868
+ if (y < 0 || y >= ARENA_HEIGHT2) return;
3869
+ for (let i = 0; i < text.length; i++) {
3870
+ const px = x + i;
3871
+ if (px >= 0 && px < ARENA_WIDTH2) {
3872
+ const ch = text[i];
3873
+ if (ch !== " ") {
3874
+ grid[y][px] = colorize(ch);
3875
+ }
3876
+ }
3877
+ }
3878
+ }
3879
+ getState() {
3880
+ return this.state;
3881
+ }
3882
+ };
3883
+
3884
+ // src/games/cyber-breakout/index.ts
3885
+ var ARENA_WIDTH3 = 56;
3886
+ var ARENA_HEIGHT3 = 18;
3887
+ var PADDLE_Y = 16;
3888
+ var DEFAULT_PADDLE_WIDTH = 8;
3889
+ var EXPANDED_PADDLE_WIDTH = 12;
3890
+ var MAX_WAVES = 5;
3891
+ var CyberBreakoutGame = class {
3892
+ id = "cyber-breakout";
3893
+ metadata = ALL_GAMES_METADATA["cyber-breakout"];
3894
+ config = null;
3895
+ renderer = defaultRenderer;
3896
+ input = new TerminalInputHandler();
3897
+ rng = new DeterministicRNG();
3898
+ gameLoopTimer = null;
3899
+ tickIntervalMs = 45;
3900
+ // Smooth 22 FPS physics
3901
+ baseBallSpeed = 0.65;
3902
+ state = {
3903
+ paddleX: Math.floor((ARENA_WIDTH3 - DEFAULT_PADDLE_WIDTH) / 2),
3904
+ paddleWidth: DEFAULT_PADDLE_WIDTH,
3905
+ hasLaser: false,
3906
+ hasShield: false,
3907
+ laserTimer: 0,
3908
+ expandTimer: 0,
3909
+ balls: [],
3910
+ capsules: [],
3911
+ lasers: [],
3912
+ bricks: [],
3913
+ score: 0,
3914
+ lives: 3,
3915
+ wave: 1,
3916
+ bricksDestroyed: 0,
3917
+ isGameOver: false,
3918
+ isWon: false,
3919
+ combo: 0
3920
+ };
3921
+ isPaused = false;
3922
+ pauseMenuIndex = 0;
3923
+ showTutorial = true;
3924
+ nextEntityId = 1;
3925
+ init(config) {
3926
+ this.config = config;
3927
+ this.renderer.setTheme(config.theme);
3928
+ this.rng = new DeterministicRNG(config.seed || Date.now());
3929
+ if (config.skipTutorial !== void 0) {
3930
+ this.showTutorial = !config.skipTutorial;
3931
+ }
3932
+ this.applyDifficulty(config.difficulty);
3933
+ this.resetGame();
3934
+ }
3935
+ start() {
3936
+ this.isPaused = false;
3937
+ this.render();
3938
+ this.input.start(
3939
+ (key) => this.handleInput(key),
3940
+ () => {
3941
+ this.destroy();
3942
+ this.config?.onExit?.();
3943
+ }
3944
+ );
3945
+ if (!this.showTutorial) {
3946
+ this.scheduleNextTick();
3947
+ }
3948
+ }
3949
+ pause() {
3950
+ this.isPaused = true;
3951
+ if (this.gameLoopTimer) {
3952
+ clearTimeout(this.gameLoopTimer);
3953
+ this.gameLoopTimer = null;
3954
+ }
3955
+ }
3956
+ resume() {
3957
+ this.isPaused = false;
3958
+ this.scheduleNextTick();
3959
+ }
3960
+ restart() {
3961
+ this.resetGame();
3962
+ this.render();
3963
+ this.scheduleNextTick();
3964
+ }
3965
+ saveState() {
3966
+ return {
3967
+ state: this.state,
3968
+ showTutorial: this.showTutorial
3969
+ };
3970
+ }
3971
+ loadState(saved) {
3972
+ if (saved["state"]) this.state = saved["state"];
3973
+ if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
3974
+ }
3975
+ getState() {
3976
+ return this.state;
3977
+ }
3978
+ handleInputForTest(key) {
3979
+ this.handleInput(key);
3980
+ }
3981
+ destroy() {
3982
+ if (this.gameLoopTimer) {
3983
+ clearTimeout(this.gameLoopTimer);
3984
+ this.gameLoopTimer = null;
3985
+ }
3986
+ this.input.stop();
3987
+ }
3988
+ applyDifficulty(diff) {
3989
+ switch (diff) {
3990
+ case "easy":
3991
+ this.baseBallSpeed = 0.5;
3992
+ this.state.lives = 4;
3993
+ break;
3994
+ case "hard":
3995
+ this.baseBallSpeed = 0.8;
3996
+ this.state.lives = 2;
3997
+ break;
3998
+ case "insane":
3999
+ this.baseBallSpeed = 0.98;
4000
+ this.state.lives = 1;
4001
+ break;
4002
+ case "normal":
4003
+ default:
4004
+ this.baseBallSpeed = 0.65;
4005
+ this.state.lives = 3;
4006
+ break;
4007
+ }
4008
+ }
4009
+ resetGame() {
4010
+ this.state.score = 0;
4011
+ this.state.wave = 1;
4012
+ this.state.bricksDestroyed = 0;
4013
+ this.state.isGameOver = false;
4014
+ this.state.isWon = false;
4015
+ this.state.combo = 0;
4016
+ this.loadWave(1);
4017
+ }
4018
+ loadWave(waveNum) {
4019
+ this.state.wave = waveNum;
4020
+ this.state.paddleWidth = DEFAULT_PADDLE_WIDTH;
4021
+ this.state.paddleX = Math.floor((ARENA_WIDTH3 - DEFAULT_PADDLE_WIDTH) / 2);
4022
+ this.state.hasLaser = false;
4023
+ this.state.hasShield = false;
4024
+ this.state.laserTimer = 0;
4025
+ this.state.expandTimer = 0;
4026
+ this.state.capsules = [];
4027
+ this.state.lasers = [];
4028
+ this.state.combo = 0;
4029
+ this.state.balls = [
4030
+ {
4031
+ id: this.nextEntityId++,
4032
+ x: this.state.paddleX + Math.floor(this.state.paddleWidth / 2),
4033
+ y: PADDLE_Y - 1,
4034
+ vx: 0,
4035
+ vy: 0,
4036
+ attachedToPaddle: true
4037
+ }
4038
+ ];
4039
+ this.state.bricks = this.generateBricksForWave(waveNum);
4040
+ }
4041
+ generateBricksForWave(wave) {
4042
+ const bricks = [];
4043
+ const brickWidth = 4;
4044
+ const cols = 12;
4045
+ const startX = 4;
4046
+ const numRows = Math.min(3 + wave, 6);
4047
+ const capsuleTypes = ["expand", "laser", "multiball", "slow", "life", "shield"];
4048
+ for (let r = 0; r < numRows; r++) {
4049
+ const y = 2 + r;
4050
+ for (let c = 0; c < cols; c++) {
4051
+ if (wave === 2 && (r + c) % 3 === 0) continue;
4052
+ if (wave === 3 && r === 3 && (c < 3 || c > 8)) continue;
4053
+ if (wave >= 4 && r % 2 === 1 && c % 2 === 1) continue;
4054
+ let type = "green";
4055
+ let hits = 1;
4056
+ if (r === 0 || wave >= 3 && r === 1 && c % 2 === 0) {
4057
+ type = "gold";
4058
+ hits = 3;
4059
+ } else if (r === 1 || wave >= 2 && r === 2) {
4060
+ type = "cyan";
4061
+ hits = 2;
4062
+ } else if (c === 0 || c === cols - 1 || c === 5 && r === 2) {
4063
+ type = "explosive";
4064
+ hits = 1;
4065
+ }
4066
+ let capsule;
4067
+ if (this.rng.next() < 0.22) {
4068
+ type = "capsule";
4069
+ capsule = capsuleTypes[Math.floor(this.rng.next() * capsuleTypes.length)];
4070
+ }
4071
+ bricks.push({
4072
+ id: this.nextEntityId++,
4073
+ x: startX + c * brickWidth,
4074
+ y,
4075
+ width: brickWidth,
4076
+ type,
4077
+ hitsLeft: hits,
4078
+ maxHits: hits,
4079
+ capsule
4080
+ });
4081
+ }
4082
+ }
4083
+ return bricks;
4084
+ }
4085
+ launchBall() {
4086
+ for (const b of this.state.balls) {
4087
+ if (b.attachedToPaddle) {
4088
+ b.attachedToPaddle = false;
4089
+ const angle = (this.rng.next() - 0.5) * 0.8;
4090
+ b.vx = Math.sin(angle) * this.baseBallSpeed;
4091
+ b.vy = -Math.cos(angle) * this.baseBallSpeed;
4092
+ if (this.config?.soundEnabled) playTerminalBell();
4093
+ }
4094
+ }
4095
+ }
4096
+ fireLasers() {
4097
+ if (!this.state.hasLaser) return;
4098
+ this.state.lasers.push(
4099
+ {
4100
+ id: this.nextEntityId++,
4101
+ x: this.state.paddleX + 1,
4102
+ y: PADDLE_Y - 1
4103
+ },
4104
+ {
4105
+ id: this.nextEntityId++,
4106
+ x: this.state.paddleX + this.state.paddleWidth - 2,
4107
+ y: PADDLE_Y - 1
4108
+ }
4109
+ );
4110
+ if (this.config?.soundEnabled) playTerminalBell();
4111
+ }
4112
+ scheduleNextTick() {
4113
+ if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
4114
+ this.gameLoopTimer = setTimeout(() => {
4115
+ this.tick();
4116
+ this.scheduleNextTick();
4117
+ }, this.tickIntervalMs);
4118
+ }
4119
+ tick() {
4120
+ if (this.isPaused || this.showTutorial || this.state.isGameOver || this.state.isWon) return;
4121
+ if (this.state.laserTimer > 0) {
4122
+ this.state.laserTimer--;
4123
+ if (this.state.laserTimer === 0) this.state.hasLaser = false;
4124
+ }
4125
+ if (this.state.expandTimer > 0) {
4126
+ this.state.expandTimer--;
4127
+ if (this.state.expandTimer === 0) {
4128
+ this.state.paddleWidth = DEFAULT_PADDLE_WIDTH;
4129
+ if (this.state.paddleX + this.state.paddleWidth > ARENA_WIDTH3) {
4130
+ this.state.paddleX = ARENA_WIDTH3 - this.state.paddleWidth;
4131
+ }
4132
+ }
4133
+ }
4134
+ for (let i = this.state.lasers.length - 1; i >= 0; i--) {
4135
+ const laser = this.state.lasers[i];
4136
+ laser.y -= 1;
4137
+ let hit = false;
4138
+ for (const brick of this.state.bricks) {
4139
+ if (Math.round(laser.y) === brick.y && laser.x >= brick.x && laser.x < brick.x + brick.width) {
4140
+ this.hitBrick(brick);
4141
+ hit = true;
4142
+ break;
4143
+ }
4144
+ }
4145
+ if (hit || laser.y < 0) {
4146
+ this.state.lasers.splice(i, 1);
4147
+ }
4148
+ }
4149
+ for (let i = this.state.capsules.length - 1; i >= 0; i--) {
4150
+ const cap = this.state.capsules[i];
4151
+ cap.y += 0.35;
4152
+ if (Math.round(cap.y) >= PADDLE_Y && Math.round(cap.y) <= PADDLE_Y + 1 && cap.x >= this.state.paddleX - 1 && cap.x <= this.state.paddleX + this.state.paddleWidth) {
4153
+ this.applyCapsule(cap.type);
4154
+ this.state.capsules.splice(i, 1);
4155
+ continue;
4156
+ }
4157
+ if (cap.y >= ARENA_HEIGHT3) {
4158
+ this.state.capsules.splice(i, 1);
4159
+ }
4160
+ }
4161
+ for (let i = this.state.balls.length - 1; i >= 0; i--) {
4162
+ const ball = this.state.balls[i];
4163
+ if (ball.attachedToPaddle) {
4164
+ ball.x = this.state.paddleX + Math.floor(this.state.paddleWidth / 2);
4165
+ ball.y = PADDLE_Y - 1;
4166
+ continue;
4167
+ }
4168
+ ball.x += ball.vx;
4169
+ ball.y += ball.vy;
4170
+ if (ball.x <= 1) {
4171
+ ball.x = 1;
4172
+ ball.vx = Math.abs(ball.vx);
4173
+ if (this.config?.soundEnabled) playTerminalBell();
4174
+ } else if (ball.x >= ARENA_WIDTH3 - 2) {
4175
+ ball.x = ARENA_WIDTH3 - 2;
4176
+ ball.vx = -Math.abs(ball.vx);
4177
+ if (this.config?.soundEnabled) playTerminalBell();
4178
+ }
4179
+ if (ball.y <= 0) {
4180
+ ball.y = 0;
4181
+ ball.vy = Math.abs(ball.vy);
4182
+ if (this.config?.soundEnabled) playTerminalBell();
4183
+ }
4184
+ if (ball.vy > 0 && ball.y >= PADDLE_Y - 0.5 && ball.y <= PADDLE_Y + 0.8) {
4185
+ if (ball.x >= this.state.paddleX - 0.5 && ball.x <= this.state.paddleX + this.state.paddleWidth + 0.5) {
4186
+ const paddleCenter = this.state.paddleX + this.state.paddleWidth / 2;
4187
+ const hitOffset = (ball.x - paddleCenter) / (this.state.paddleWidth / 2);
4188
+ const clampedOffset = Math.max(-0.95, Math.min(0.95, hitOffset));
4189
+ const currentSpeed = Math.sqrt(ball.vx * ball.vx + ball.vy * ball.vy);
4190
+ ball.vx = clampedOffset * currentSpeed * 0.95;
4191
+ ball.vy = -Math.sqrt(Math.max(0.1, currentSpeed * currentSpeed - ball.vx * ball.vx));
4192
+ ball.y = PADDLE_Y - 1;
4193
+ this.state.combo = 0;
4194
+ if (this.config?.soundEnabled) playTerminalBell();
4195
+ continue;
4196
+ }
4197
+ }
4198
+ if (ball.y >= ARENA_HEIGHT3) {
4199
+ if (this.state.hasShield) {
4200
+ this.state.hasShield = false;
4201
+ ball.y = ARENA_HEIGHT3 - 2;
4202
+ ball.vy = -Math.abs(ball.vy);
4203
+ if (this.config?.soundEnabled) playTerminalBell();
4204
+ continue;
4205
+ }
4206
+ this.state.balls.splice(i, 1);
4207
+ }
4208
+ this.checkBallBrickCollisions(ball);
4209
+ }
4210
+ if (this.state.balls.length === 0) {
4211
+ this.handleLifeLost();
4212
+ return;
4213
+ }
4214
+ if (this.state.bricks.length === 0) {
4215
+ this.handleWaveCleared();
4216
+ return;
4217
+ }
4218
+ this.render();
4219
+ }
4220
+ checkBallBrickCollisions(ball) {
4221
+ const bx = Math.round(ball.x);
4222
+ const by = Math.round(ball.y);
4223
+ for (let i = this.state.bricks.length - 1; i >= 0; i--) {
4224
+ const brick = this.state.bricks[i];
4225
+ if (by === brick.y && bx >= brick.x && bx < brick.x + brick.width) {
4226
+ this.hitBrick(brick);
4227
+ ball.vy = -ball.vy;
4228
+ ball.y += ball.vy * 0.5;
4229
+ break;
4230
+ }
4231
+ }
4232
+ }
4233
+ hitBrick(brick) {
4234
+ brick.hitsLeft--;
4235
+ this.state.combo++;
4236
+ const comboBonus = Math.min(this.state.combo * 10, 100);
4237
+ if (brick.hitsLeft <= 0) {
4238
+ this.state.bricksDestroyed++;
4239
+ const idx = this.state.bricks.indexOf(brick);
4240
+ if (idx !== -1) {
4241
+ this.state.bricks.splice(idx, 1);
4242
+ }
4243
+ let pts = 50;
4244
+ if (brick.type === "cyan") pts = 100;
4245
+ else if (brick.type === "gold") pts = 200;
4246
+ else if (brick.type === "explosive") pts = 150;
4247
+ else if (brick.type === "capsule") pts = 120;
4248
+ this.addScore(pts + comboBonus);
4249
+ if (this.state.bricksDestroyed === 1) {
4250
+ this.config?.onAchievementUnlock?.("first_smash");
4251
+ }
4252
+ if (brick.type === "explosive") {
4253
+ this.triggerExplosion(brick.x, brick.y);
4254
+ }
4255
+ if (brick.capsule) {
4256
+ this.state.capsules.push({
4257
+ id: this.nextEntityId++,
4258
+ x: brick.x + Math.floor(brick.width / 2),
4259
+ y: brick.y,
4260
+ type: brick.capsule
4261
+ });
4262
+ }
4263
+ if (this.config?.soundEnabled) playTerminalBell();
4264
+ } else {
4265
+ this.addScore(25 + comboBonus);
4266
+ if (this.config?.soundEnabled) playTerminalBell();
4267
+ }
4268
+ }
4269
+ triggerExplosion(ex, ey) {
4270
+ for (let i = this.state.bricks.length - 1; i >= 0; i--) {
4271
+ const b = this.state.bricks[i];
4272
+ if (Math.abs(b.y - ey) <= 1 && Math.abs(b.x - ex) <= 6) {
4273
+ b.hitsLeft--;
4274
+ if (b.hitsLeft <= 0) {
4275
+ this.state.bricksDestroyed++;
4276
+ this.state.bricks.splice(i, 1);
4277
+ this.addScore(75);
4278
+ }
4279
+ }
4280
+ }
4281
+ }
4282
+ applyCapsule(type) {
4283
+ this.config?.onAchievementUnlock?.("power_surge");
4284
+ this.addScore(100);
4285
+ switch (type) {
4286
+ case "expand":
4287
+ this.state.paddleWidth = EXPANDED_PADDLE_WIDTH;
4288
+ this.state.expandTimer = 220;
4289
+ break;
4290
+ case "laser":
4291
+ this.state.hasLaser = true;
4292
+ this.state.laserTimer = 220;
4293
+ break;
4294
+ case "multiball":
4295
+ this.state.balls.push(
4296
+ {
4297
+ id: this.nextEntityId++,
4298
+ x: this.state.paddleX + 2,
4299
+ y: PADDLE_Y - 1,
4300
+ vx: -this.baseBallSpeed * 0.7,
4301
+ vy: -this.baseBallSpeed * 0.8,
4302
+ attachedToPaddle: false
4303
+ },
4304
+ {
4305
+ id: this.nextEntityId++,
4306
+ x: this.state.paddleX + this.state.paddleWidth - 2,
4307
+ y: PADDLE_Y - 1,
4308
+ vx: this.baseBallSpeed * 0.7,
4309
+ vy: -this.baseBallSpeed * 0.8,
4310
+ attachedToPaddle: false
4311
+ }
4312
+ );
4313
+ break;
4314
+ case "slow":
4315
+ for (const b of this.state.balls) {
4316
+ b.vx *= 0.75;
4317
+ b.vy *= 0.75;
4318
+ }
4319
+ break;
4320
+ case "life":
4321
+ this.state.lives++;
4322
+ break;
4323
+ case "shield":
4324
+ this.state.hasShield = true;
4325
+ break;
4326
+ }
4327
+ if (this.config?.soundEnabled) playTerminalBell();
4328
+ }
4329
+ handleLifeLost() {
4330
+ this.state.lives--;
4331
+ this.state.combo = 0;
4332
+ this.state.hasLaser = false;
4333
+ this.state.paddleWidth = DEFAULT_PADDLE_WIDTH;
4334
+ this.state.lasers = [];
4335
+ if (this.state.lives <= 0) {
4336
+ this.state.isGameOver = true;
4337
+ this.config?.onGameOver?.(this.state.score);
4338
+ if (this.config?.soundEnabled) playTerminalBell();
4339
+ this.render();
4340
+ return;
4341
+ }
4342
+ this.state.balls = [
4343
+ {
4344
+ id: this.nextEntityId++,
4345
+ x: this.state.paddleX + Math.floor(this.state.paddleWidth / 2),
4346
+ y: PADDLE_Y - 1,
4347
+ vx: 0,
4348
+ vy: 0,
4349
+ attachedToPaddle: true
4350
+ }
4351
+ ];
4352
+ if (this.config?.soundEnabled) playTerminalBell();
4353
+ this.render();
4354
+ }
4355
+ handleWaveCleared() {
4356
+ this.addScore(1e3 * this.state.wave);
4357
+ if (this.state.wave === 1) {
4358
+ this.config?.onAchievementUnlock?.("brick_demolisher");
4359
+ }
4360
+ if (this.state.wave >= MAX_WAVES) {
4361
+ this.state.isWon = true;
4362
+ this.config?.onGameOver?.(this.state.score);
4363
+ if (this.config?.soundEnabled) playTerminalBell();
4364
+ this.render();
4365
+ return;
4366
+ }
4367
+ this.loadWave(this.state.wave + 1);
4368
+ if (this.config?.soundEnabled) playTerminalBell();
4369
+ this.render();
4370
+ }
4371
+ addScore(pts) {
4372
+ this.state.score += pts;
4373
+ this.config?.onScoreUpdate?.(this.state.score);
4374
+ }
4375
+ handleInput(key) {
4376
+ if (this.showTutorial) {
4377
+ if (key.name === "return" || key.name === "space") {
4378
+ this.showTutorial = false;
4379
+ this.scheduleNextTick();
4380
+ this.render();
4381
+ } else if (key.name === "escape" || key.name === "q") {
4382
+ this.destroy();
4383
+ this.config?.onExit?.();
4384
+ }
4385
+ return;
4386
+ }
4387
+ if (this.isPaused) {
4388
+ if (key.name === "up" || key.name === "w") {
4389
+ this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
4390
+ this.render();
4391
+ } else if (key.name === "down" || key.name === "s") {
4392
+ this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
4393
+ this.render();
4394
+ } else if (key.name === "return" || key.name === "space") {
4395
+ if (this.pauseMenuIndex === 0) {
4396
+ this.isPaused = false;
4397
+ this.scheduleNextTick();
4398
+ this.render();
4399
+ } else if (this.pauseMenuIndex === 1) {
4400
+ this.isPaused = false;
4401
+ this.restart();
4402
+ } else if (this.pauseMenuIndex === 2) {
4403
+ this.destroy();
4404
+ this.config?.onExit?.();
4405
+ }
4406
+ } else if (key.name === "escape" || key.name === "p") {
4407
+ this.isPaused = false;
4408
+ this.scheduleNextTick();
4409
+ this.render();
4410
+ } else if (key.name === "q") {
4411
+ this.destroy();
4412
+ this.config?.onExit?.();
4413
+ }
4414
+ return;
4415
+ }
4416
+ if (key.name === "escape" || key.name === "p") {
4417
+ this.isPaused = true;
4418
+ this.pauseMenuIndex = 0;
4419
+ if (this.gameLoopTimer) {
4420
+ clearTimeout(this.gameLoopTimer);
4421
+ this.gameLoopTimer = null;
4422
+ }
4423
+ this.render();
4424
+ return;
4425
+ }
4426
+ if (key.name === "q") {
4427
+ this.destroy();
4428
+ this.config?.onExit?.();
4429
+ return;
4430
+ }
4431
+ if (key.name === "r") {
4432
+ this.restart();
4433
+ return;
4434
+ }
4435
+ if (this.state.isGameOver || this.state.isWon) {
4436
+ if (key.name === "return" || key.name === "space" || key.name === "r") {
4437
+ this.resetGame();
4438
+ this.render();
4439
+ this.scheduleNextTick();
4440
+ }
4441
+ return;
4442
+ }
4443
+ const step = 3;
4444
+ if (key.name === "left" || key.name === "a") {
4445
+ this.state.paddleX = Math.max(1, this.state.paddleX - step);
4446
+ this.render();
4447
+ } else if (key.name === "right" || key.name === "d") {
4448
+ this.state.paddleX = Math.min(ARENA_WIDTH3 - this.state.paddleWidth - 1, this.state.paddleX + step);
4449
+ this.render();
4450
+ }
4451
+ if (key.name === "space") {
4452
+ const hasAttached = this.state.balls.some((b) => b.attachedToPaddle);
4453
+ if (hasAttached) {
4454
+ this.launchBall();
4455
+ } else if (this.state.hasLaser) {
4456
+ this.fireLasers();
4457
+ }
4458
+ }
4459
+ }
4460
+ render() {
4461
+ const t = this.renderer.getTheme();
4462
+ const totalWidth = ARENA_WIDTH3 + 2;
4463
+ if (this.showTutorial) {
4464
+ const lines = [
4465
+ "",
4466
+ t.highlight("CYBER BREAKOUT // DEFENSE BREAKER PROTOCOL"),
4467
+ "",
4468
+ "\u2022 Slide your cyber paddle across the bottom rail to deflect energy orbs.",
4469
+ "\u2022 Smash through multi-tier defensive firewalls (Green, Cyan, Gold).",
4470
+ "\u2022 Collect rare power capsules: Expand Paddle, Laser Cannons, Multi-Ball.",
4471
+ "\u2022 Press SPACE to launch the ball from your paddle or fire armed lasers.",
4472
+ "\u2022 Clear all bricks in the sector to advance to the next defense wave.",
4473
+ "",
4474
+ t.muted("Controls:"),
4475
+ " Left / Right / A / D : Slide Paddle",
4476
+ " Space : Launch Ball / Fire Lasers",
4477
+ " P / Esc : Pause System",
4478
+ " R : Instant Restart",
4479
+ " Q : Quit to Arcade Menu",
4480
+ "",
4481
+ t.highlight("Press [ENTER] or [SPACE] to Initialize Circuit..."),
4482
+ ""
4483
+ ];
4484
+ const box = this.renderer.createBox(lines, totalWidth, "MISSION BRIEFING");
4485
+ this.renderer.draw(this.renderer.centerBlock(box, totalWidth));
4486
+ return;
4487
+ }
4488
+ if (this.isPaused) {
4489
+ const menuItems = ["RESUME BREAKOUT", "RESTART MISSION", "EXIT TO ROSTER"];
4490
+ const lines = [
4491
+ "",
4492
+ t.highlight("CYBER BREAKOUT // SYSTEM PAUSED"),
4493
+ "",
4494
+ ...menuItems.map((item, idx) => {
4495
+ if (idx === this.pauseMenuIndex) {
4496
+ return t.highlight(` \u25BA [ ${item} ]`);
4497
+ }
4498
+ return t.muted(` ${item} `);
4499
+ }),
4500
+ "",
4501
+ t.muted("Use Up/Down to select, Enter to confirm"),
4502
+ ""
4503
+ ];
4504
+ const box = this.renderer.createBox(lines, totalWidth, "SYSTEM PAUSED");
4505
+ this.renderer.draw(this.renderer.centerBlock(box, totalWidth));
4506
+ return;
4507
+ }
4508
+ if (this.state.isGameOver) {
4509
+ const lines = [
4510
+ "",
4511
+ t.error("SYSTEM TERMINATED // DEFENSE BREACH FAILED"),
4512
+ "",
4513
+ `Final Score: ${t.highlight(this.state.score.toLocaleString())}`,
4514
+ `Sectors Cleared: ${t.secondary((this.state.wave - 1).toString())}`,
4515
+ `Bricks Demolished: ${t.secondary(this.state.bricksDestroyed.toString())}`,
4516
+ "",
4517
+ t.highlight("Press [R] or [SPACE] to Retry Sector"),
4518
+ t.muted("Press [Q] to Return to Arcade Roster"),
4519
+ ""
4520
+ ];
4521
+ const box = this.renderer.createBox(lines, totalWidth, "MISSION DEFEAT");
4522
+ this.renderer.draw(this.renderer.centerBlock(box, totalWidth));
4523
+ return;
4524
+ }
4525
+ if (this.state.isWon) {
4526
+ const lines = [
4527
+ "",
4528
+ t.highlight("VICTORY // ALL SECURITY SECTORS BREACHED!"),
4529
+ "",
4530
+ `Legendary Score: ${t.highlight(this.state.score.toLocaleString())}`,
4531
+ `Total Demolished: ${t.secondary(this.state.bricksDestroyed.toString())}`,
4532
+ `Remaining Lives: ${t.secondary("\u2665 ".repeat(this.state.lives))}`,
4533
+ "",
4534
+ t.highlight("Press [R] or [SPACE] to Play Again"),
4535
+ t.muted("Press [Q] to Return to Arcade Roster"),
4536
+ ""
4537
+ ];
4538
+ const box = this.renderer.createBox(lines, totalWidth, "MISSION VICTORY");
4539
+ this.renderer.draw(this.renderer.centerBlock(box, totalWidth));
4540
+ return;
4541
+ }
4542
+ const livesDisplay = "\u2665 ".repeat(Math.max(0, this.state.lives));
4543
+ const scoreStr = `SCORE: ${this.state.score.toLocaleString()}`;
4544
+ const waveStr = `SECTOR ${this.state.wave}/${MAX_WAVES}`;
4545
+ const headerLine = `${t.secondary(waveStr)} ${t.highlight(scoreStr)} ${t.error(livesDisplay)}`;
4546
+ const arenaRows = [];
4547
+ const grid = Array.from(
4548
+ { length: ARENA_HEIGHT3 },
4549
+ () => Array.from({ length: ARENA_WIDTH3 }, () => " ")
4550
+ );
4551
+ for (const b of this.state.bricks) {
4552
+ if (b.y >= 0 && b.y < ARENA_HEIGHT3) {
4553
+ let brickChar = "\u2591";
4554
+ if (b.type === "gold") brickChar = "\u2593";
4555
+ else if (b.type === "cyan") brickChar = "\u2592";
4556
+ else if (b.type === "explosive") brickChar = "X";
4557
+ else if (b.type === "capsule") brickChar = "\u2605";
4558
+ for (let x = 0; x < b.width; x++) {
4559
+ const gx = b.x + x;
4560
+ if (gx >= 0 && gx < ARENA_WIDTH3) {
4561
+ grid[b.y][gx] = brickChar;
4562
+ }
4563
+ }
4564
+ }
4565
+ }
4566
+ for (const cap of this.state.capsules) {
4567
+ const cy = Math.round(cap.y);
4568
+ const cx = Math.round(cap.x);
4569
+ if (cy >= 0 && cy < ARENA_HEIGHT3 && cx >= 0 && cx < ARENA_WIDTH3) {
4570
+ let tag = "C";
4571
+ if (cap.type === "expand") tag = "E";
4572
+ else if (cap.type === "laser") tag = "L";
4573
+ else if (cap.type === "multiball") tag = "M";
4574
+ else if (cap.type === "slow") tag = "S";
4575
+ else if (cap.type === "life") tag = "+";
4576
+ grid[cy][cx] = tag;
4577
+ }
4578
+ }
4579
+ for (const laser of this.state.lasers) {
4580
+ const ly = Math.round(laser.y);
4581
+ const lx = Math.round(laser.x);
4582
+ if (ly >= 0 && ly < ARENA_HEIGHT3 && lx >= 0 && lx < ARENA_WIDTH3) {
4583
+ grid[ly][lx] = "\u2502";
4584
+ }
4585
+ }
4586
+ const py = PADDLE_Y;
4587
+ for (let x = 0; x < this.state.paddleWidth; x++) {
4588
+ const gx = this.state.paddleX + x;
4589
+ if (gx >= 0 && gx < ARENA_WIDTH3) {
4590
+ if (x === 0) grid[py][gx] = this.state.hasLaser ? "\u25B2" : "\u2590";
4591
+ else if (x === this.state.paddleWidth - 1) grid[py][gx] = this.state.hasLaser ? "\u25B2" : "\u258C";
4592
+ else grid[py][gx] = "\u2550";
4593
+ }
4594
+ }
4595
+ if (this.state.hasShield) {
4596
+ for (let gx = 0; gx < ARENA_WIDTH3; gx++) {
4597
+ grid[ARENA_HEIGHT3 - 1][gx] = "\u2500";
4598
+ }
4599
+ }
4600
+ for (const ball of this.state.balls) {
4601
+ const by = Math.round(ball.y);
4602
+ const bx = Math.round(ball.x);
4603
+ if (by >= 0 && by < ARENA_HEIGHT3 && bx >= 0 && bx < ARENA_WIDTH3) {
4604
+ grid[by][bx] = "\u25CF";
4605
+ }
4606
+ }
4607
+ for (let r = 0; r < ARENA_HEIGHT3; r++) {
4608
+ let rowStr = "";
4609
+ for (let c = 0; c < ARENA_WIDTH3; c++) {
4610
+ const char = grid[r][c];
4611
+ if (char === "\u2593") rowStr += t.warning("\u2593");
4612
+ else if (char === "\u2592") rowStr += t.secondary("\u2592");
4613
+ else if (char === "\u2591") rowStr += t.primary("\u2591");
4614
+ else if (char === "X") rowStr += t.error("X");
4615
+ else if (char === "\u2605") rowStr += t.highlight("\u2605");
4616
+ else if (char === "\u25CF") rowStr += t.highlight("\u25CF");
4617
+ else if (char === "\u25B2") rowStr += t.error("\u25B2");
4618
+ else if (char === "\u2502") rowStr += t.error("\u2502");
4619
+ else if (char === "\u2590" || char === "\u258C" || char === "\u2550") rowStr += t.secondary(char);
4620
+ else if (char === "\u2500") rowStr += t.secondary("\u2500");
4621
+ else if (char === "E" || char === "L" || char === "M" || char === "+" || char === "S" || char === "C") {
4622
+ rowStr += t.highlight(char);
4623
+ } else {
4624
+ rowStr += " ";
4625
+ }
4626
+ }
4627
+ arenaRows.push(`\u2551${rowStr}\u2551`);
4628
+ }
4629
+ const topBorder = `\u2554${"\u2550".repeat(ARENA_WIDTH3)}\u2557`;
4630
+ const bottomBorder = `\u255A${"\u2550".repeat(ARENA_WIDTH3)}\u255D`;
4631
+ let powerStatus = "";
4632
+ if (this.state.hasLaser) powerStatus += t.error(" [LASERS ARMED] ");
4633
+ if (this.state.expandTimer > 0) powerStatus += t.secondary(" [PADDLE EXPANDED] ");
4634
+ if (this.state.hasShield) powerStatus += t.highlight(" [SHIELD ACTIVE] ");
4635
+ const frameLines = [
4636
+ headerLine,
4637
+ powerStatus ? powerStatus : t.muted("Clear all bricks to advance sector"),
4638
+ topBorder,
4639
+ ...arenaRows,
4640
+ bottomBorder,
4641
+ t.muted("Controls: A/D/Arrows: Slide | Space: Launch/Laser | P: Pause | R: Retry | Q: Quit")
4642
+ ];
4643
+ const renderedBlock = this.renderer.centerBlock(frameLines.join("\n"), totalWidth);
4644
+ this.renderer.draw(renderedBlock);
4645
+ }
4646
+ };
4647
+
4648
+ // src/games/cyber-2048/index.ts
4649
+ import chalk4 from "chalk";
4650
+ var GRID_SIZE = 4;
4651
+ var TOTAL_WIDTH = 58;
4652
+ var Cyber2048Game = class {
4653
+ id = "cyber-2048";
4654
+ metadata = ALL_GAMES_METADATA["cyber-2048"];
4655
+ config = null;
4656
+ renderer = defaultRenderer;
4657
+ input = new TerminalInputHandler();
4658
+ rng = new DeterministicRNG();
4659
+ state = {
4660
+ grid: [
4661
+ [0, 0, 0, 0],
4662
+ [0, 0, 0, 0],
4663
+ [0, 0, 0, 0],
4664
+ [0, 0, 0, 0]
4665
+ ],
4666
+ score: 0,
4667
+ bestScore: 0,
4668
+ moves: 0,
4669
+ undosLeft: 3,
4670
+ highestTile: 2,
4671
+ hasWon: false,
4672
+ continueAfterWin: false,
4673
+ isGameOver: false,
4674
+ lastMergedValue: 0
4675
+ };
4676
+ history = [];
4677
+ isPaused = false;
4678
+ pauseMenuIndex = 0;
4679
+ showTutorial = true;
4680
+ burstCells = /* @__PURE__ */ new Map();
4681
+ burstTimer = null;
4682
+ init(config) {
4683
+ this.config = config;
4684
+ this.renderer.setTheme(config.theme);
4685
+ this.rng = new DeterministicRNG(config.seed || Date.now());
4686
+ if (config.skipTutorial !== void 0) {
4687
+ this.showTutorial = !config.skipTutorial;
4688
+ }
4689
+ this.applyDifficulty(config.difficulty);
4690
+ this.resetGame();
4691
+ }
4692
+ start() {
4693
+ this.isPaused = false;
4694
+ this.render();
4695
+ this.input.start(
4696
+ (key) => this.handleInput(key),
4697
+ () => {
4698
+ this.destroy();
4699
+ this.config?.onExit?.();
4700
+ }
4701
+ );
4702
+ }
4703
+ pause() {
4704
+ this.isPaused = true;
4705
+ this.render();
4706
+ }
4707
+ resume() {
4708
+ this.isPaused = false;
4709
+ this.render();
4710
+ }
4711
+ restart() {
4712
+ this.resetGame();
4713
+ this.render();
4714
+ }
4715
+ saveState() {
4716
+ return {
4717
+ state: this.state,
4718
+ history: this.history,
4719
+ showTutorial: this.showTutorial
4720
+ };
4721
+ }
4722
+ loadState(saved) {
4723
+ if (saved["state"]) this.state = saved["state"];
4724
+ if (saved["history"]) this.history = saved["history"];
4725
+ if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
4726
+ }
4727
+ getState() {
4728
+ return this.state;
4729
+ }
4730
+ handleInputForTest(key) {
4731
+ this.handleInput(key);
4732
+ }
4733
+ destroy() {
4734
+ if (this.burstTimer) {
4735
+ clearTimeout(this.burstTimer);
4736
+ this.burstTimer = null;
4737
+ }
4738
+ this.input.stop();
4739
+ }
4740
+ applyDifficulty(diff) {
4741
+ switch (diff) {
4742
+ case "easy":
4743
+ this.state.undosLeft = 999;
4744
+ break;
4745
+ case "hard":
4746
+ this.state.undosLeft = 1;
4747
+ break;
4748
+ case "insane":
4749
+ this.state.undosLeft = 0;
4750
+ break;
4751
+ case "normal":
4752
+ default:
4753
+ this.state.undosLeft = 3;
4754
+ break;
4755
+ }
4756
+ }
4757
+ resetGame() {
4758
+ this.state.grid = [
4759
+ [0, 0, 0, 0],
4760
+ [0, 0, 0, 0],
4761
+ [0, 0, 0, 0],
4762
+ [0, 0, 0, 0]
4763
+ ];
4764
+ this.state.score = 0;
4765
+ this.state.moves = 0;
4766
+ this.state.highestTile = 2;
4767
+ this.state.hasWon = false;
4768
+ this.state.continueAfterWin = false;
4769
+ this.state.isGameOver = false;
4770
+ this.state.lastMergedValue = 0;
4771
+ this.history = [];
4772
+ this.spawnTile();
4773
+ this.spawnTile();
4774
+ }
4775
+ spawnTile() {
4776
+ const emptyCells = [];
4777
+ for (let r = 0; r < GRID_SIZE; r++) {
4778
+ for (let c = 0; c < GRID_SIZE; c++) {
4779
+ if (this.state.grid[r][c] === 0) {
4780
+ emptyCells.push({ r, c });
4781
+ }
4782
+ }
4783
+ }
4784
+ if (emptyCells.length === 0) return false;
4785
+ const chosen = emptyCells[Math.floor(this.rng.next() * emptyCells.length)];
4786
+ const val = this.rng.next() < 0.9 ? 2 : 4;
4787
+ this.state.grid[chosen.r][chosen.c] = val;
4788
+ return true;
4789
+ }
4790
+ slideLine(line) {
4791
+ const nonZeroes = line.filter((v) => v !== 0);
4792
+ const newLine = [];
4793
+ const mergedValues = [];
4794
+ const mergedIndices = [];
4795
+ let points = 0;
4796
+ let i = 0;
4797
+ while (i < nonZeroes.length) {
4798
+ if (i + 1 < nonZeroes.length && nonZeroes[i] === nonZeroes[i + 1]) {
4799
+ const mergedVal = nonZeroes[i] * 2;
4800
+ mergedIndices.push(newLine.length);
4801
+ newLine.push(mergedVal);
4802
+ mergedValues.push(mergedVal);
4803
+ points += mergedVal;
4804
+ i += 2;
4805
+ } else {
4806
+ newLine.push(nonZeroes[i]);
4807
+ i++;
4808
+ }
4809
+ }
4810
+ while (newLine.length < GRID_SIZE) {
4811
+ newLine.push(0);
4812
+ }
4813
+ return { newLine, points, mergedIndices, mergedValues };
4814
+ }
4815
+ slide(dir) {
4816
+ if (this.state.isGameOver) return false;
4817
+ const oldGrid = this.state.grid.map((row) => [...row]);
4818
+ const oldScore = this.state.score;
4819
+ const oldMoves = this.state.moves;
4820
+ let gainedPoints = 0;
4821
+ const allMergedValues = [];
4822
+ const mergedCoords = [];
4823
+ const newGrid = [
4824
+ [0, 0, 0, 0],
4825
+ [0, 0, 0, 0],
4826
+ [0, 0, 0, 0],
4827
+ [0, 0, 0, 0]
4828
+ ];
4829
+ if (dir === "left") {
4830
+ for (let r = 0; r < GRID_SIZE; r++) {
4831
+ const res = this.slideLine(oldGrid[r]);
4832
+ newGrid[r] = res.newLine;
4833
+ gainedPoints += res.points;
4834
+ allMergedValues.push(...res.mergedValues);
4835
+ for (const idx of res.mergedIndices) {
4836
+ mergedCoords.push({ r, c: idx, val: newGrid[r][idx] });
4837
+ }
4838
+ }
4839
+ } else if (dir === "right") {
4840
+ for (let r = 0; r < GRID_SIZE; r++) {
4841
+ const reversed = [...oldGrid[r]].reverse();
4842
+ const res = this.slideLine(reversed);
4843
+ newGrid[r] = res.newLine.reverse();
4844
+ gainedPoints += res.points;
4845
+ allMergedValues.push(...res.mergedValues);
4846
+ for (const idx of res.mergedIndices) {
4847
+ const finalCol = GRID_SIZE - 1 - idx;
4848
+ mergedCoords.push({ r, c: finalCol, val: newGrid[r][finalCol] });
4849
+ }
4850
+ }
4851
+ } else if (dir === "up") {
4852
+ for (let c = 0; c < GRID_SIZE; c++) {
4853
+ const col = [oldGrid[0][c], oldGrid[1][c], oldGrid[2][c], oldGrid[3][c]];
4854
+ const res = this.slideLine(col);
4855
+ for (let r = 0; r < GRID_SIZE; r++) {
4856
+ newGrid[r][c] = res.newLine[r];
4857
+ }
4858
+ gainedPoints += res.points;
4859
+ allMergedValues.push(...res.mergedValues);
4860
+ for (const idx of res.mergedIndices) {
4861
+ mergedCoords.push({ r: idx, c, val: newGrid[idx][c] });
4862
+ }
4863
+ }
4864
+ } else if (dir === "down") {
4865
+ for (let c = 0; c < GRID_SIZE; c++) {
4866
+ const col = [oldGrid[3][c], oldGrid[2][c], oldGrid[1][c], oldGrid[0][c]];
4867
+ const res = this.slideLine(col);
4868
+ const rev = res.newLine.reverse();
4869
+ for (let r = 0; r < GRID_SIZE; r++) {
4870
+ newGrid[r][c] = rev[r];
4871
+ }
4872
+ gainedPoints += res.points;
4873
+ allMergedValues.push(...res.mergedValues);
4874
+ for (const idx of res.mergedIndices) {
4875
+ const finalRow = GRID_SIZE - 1 - idx;
4876
+ mergedCoords.push({ r: finalRow, c, val: newGrid[finalRow][c] });
4877
+ }
4878
+ }
4879
+ }
4880
+ let changed = false;
4881
+ for (let r = 0; r < GRID_SIZE; r++) {
4882
+ for (let c = 0; c < GRID_SIZE; c++) {
4883
+ if (newGrid[r][c] !== oldGrid[r][c]) {
4884
+ changed = true;
4885
+ break;
4886
+ }
4887
+ }
4888
+ if (changed) break;
4889
+ }
4890
+ if (!changed) {
4891
+ return false;
4892
+ }
4893
+ this.history.push({
4894
+ grid: oldGrid,
4895
+ score: oldScore,
4896
+ moves: oldMoves
4897
+ });
4898
+ if (this.history.length > 10) {
4899
+ this.history.shift();
4900
+ }
4901
+ this.state.grid = newGrid;
4902
+ this.state.score += gainedPoints;
4903
+ this.state.moves++;
4904
+ if (this.state.score > this.state.bestScore) {
4905
+ this.state.bestScore = this.state.score;
4906
+ }
4907
+ this.config?.onScoreUpdate?.(this.state.score);
4908
+ for (let r = 0; r < GRID_SIZE; r++) {
4909
+ for (let c = 0; c < GRID_SIZE; c++) {
4910
+ const v = this.state.grid[r][c];
4911
+ if (v > this.state.highestTile) {
4912
+ this.state.highestTile = v;
4913
+ }
4914
+ }
4915
+ }
4916
+ if (mergedCoords.length > 0) {
4917
+ this.burstCells.clear();
4918
+ for (const m of mergedCoords) {
4919
+ this.burstCells.set(`${m.r},${m.c}`, { val: m.val, frame: 1 });
4920
+ }
4921
+ if (this.burstTimer) {
4922
+ clearTimeout(this.burstTimer);
4923
+ this.burstTimer = null;
4924
+ }
4925
+ this.burstTimer = setTimeout(() => {
4926
+ let hasRemaining = false;
4927
+ for (const [key, b] of this.burstCells.entries()) {
4928
+ if (b.frame === 1) {
4929
+ b.frame = 2;
4930
+ hasRemaining = true;
4931
+ } else {
4932
+ this.burstCells.delete(key);
4933
+ }
4934
+ }
4935
+ this.render();
4936
+ if (hasRemaining) {
4937
+ this.burstTimer = setTimeout(() => {
4938
+ this.burstCells.clear();
4939
+ this.burstTimer = null;
4940
+ this.render();
4941
+ }, 90);
4942
+ } else {
4943
+ this.burstTimer = null;
4944
+ }
4945
+ }, 90);
4946
+ } else {
4947
+ this.burstCells.clear();
4948
+ }
4949
+ if (allMergedValues.length > 0) {
4950
+ this.state.lastMergedValue = Math.max(...allMergedValues);
4951
+ this.config?.onAchievementUnlock?.("first_merge");
4952
+ if (allMergedValues.some((v) => v >= 1024)) {
4953
+ this.config?.onAchievementUnlock?.("reach_1024");
4954
+ }
4955
+ if (allMergedValues.some((v) => v >= 2048) && !this.state.hasWon) {
4956
+ this.state.hasWon = true;
4957
+ this.config?.onAchievementUnlock?.("reach_2048");
4958
+ if (this.config?.soundEnabled) playTerminalBell();
4959
+ }
4960
+ }
4961
+ this.spawnTile();
4962
+ if (this.config?.soundEnabled) playTerminalBell();
4963
+ if (this.checkGameOver()) {
4964
+ this.state.isGameOver = true;
4965
+ this.config?.onGameOver?.(this.state.score);
4966
+ if (this.config?.soundEnabled) playTerminalBell();
4967
+ }
4968
+ return true;
4969
+ }
4970
+ undo() {
4971
+ if (this.history.length === 0 || this.state.undosLeft <= 0) return false;
4972
+ const prev = this.history.pop();
4973
+ this.state.grid = prev.grid;
4974
+ this.state.score = prev.score;
4975
+ this.state.moves = prev.moves;
4976
+ this.state.undosLeft--;
4977
+ this.state.isGameOver = false;
4978
+ let max = 2;
4979
+ for (let r = 0; r < GRID_SIZE; r++) {
4980
+ for (let c = 0; c < GRID_SIZE; c++) {
4981
+ if (this.state.grid[r][c] > max) max = this.state.grid[r][c];
4982
+ }
4983
+ }
4984
+ this.state.highestTile = max;
4985
+ if (this.config?.soundEnabled) playTerminalBell();
4986
+ this.render();
4987
+ return true;
4988
+ }
4989
+ checkGameOver() {
4990
+ for (let r = 0; r < GRID_SIZE; r++) {
4991
+ for (let c = 0; c < GRID_SIZE; c++) {
4992
+ if (this.state.grid[r][c] === 0) return false;
4993
+ }
4994
+ }
4995
+ for (let r = 0; r < GRID_SIZE; r++) {
4996
+ for (let c = 0; c < GRID_SIZE; c++) {
4997
+ const val = this.state.grid[r][c];
4998
+ if (c + 1 < GRID_SIZE && val === this.state.grid[r][c + 1]) return false;
4999
+ if (r + 1 < GRID_SIZE && val === this.state.grid[r + 1][c]) return false;
5000
+ }
5001
+ }
5002
+ return true;
5003
+ }
5004
+ handleInput(key) {
5005
+ if (this.showTutorial) {
5006
+ if (key.name === "return" || key.name === "space") {
5007
+ this.showTutorial = false;
5008
+ this.render();
5009
+ } else if (key.name === "escape" || key.name === "q") {
5010
+ this.destroy();
5011
+ this.config?.onExit?.();
5012
+ }
5013
+ return;
5014
+ }
5015
+ if (this.isPaused) {
5016
+ if (key.name === "up" || key.name === "w") {
5017
+ this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
5018
+ this.render();
5019
+ } else if (key.name === "down" || key.name === "s") {
5020
+ this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
5021
+ this.render();
5022
+ } else if (key.name === "return" || key.name === "space") {
5023
+ if (this.pauseMenuIndex === 0) {
5024
+ this.isPaused = false;
5025
+ this.render();
5026
+ } else if (this.pauseMenuIndex === 1) {
5027
+ this.isPaused = false;
5028
+ this.restart();
5029
+ } else if (this.pauseMenuIndex === 2) {
5030
+ this.destroy();
5031
+ this.config?.onExit?.();
5032
+ }
5033
+ } else if (key.name === "escape" || key.name === "p") {
5034
+ this.isPaused = false;
5035
+ this.render();
5036
+ } else if (key.name === "q") {
5037
+ this.destroy();
5038
+ this.config?.onExit?.();
5039
+ }
5040
+ return;
5041
+ }
5042
+ if (this.state.hasWon && !this.state.continueAfterWin) {
5043
+ if (key.name === "c" || key.name === "space" || key.name === "return") {
5044
+ this.state.continueAfterWin = true;
5045
+ this.render();
5046
+ return;
5047
+ } else if (key.name === "r") {
5048
+ this.restart();
5049
+ return;
5050
+ } else if (key.name === "q") {
5051
+ this.destroy();
5052
+ this.config?.onExit?.();
5053
+ return;
5054
+ }
5055
+ }
5056
+ if (this.state.isGameOver) {
5057
+ if (key.name === "r" || key.name === "space" || key.name === "return") {
5058
+ this.restart();
5059
+ } else if (key.name === "u") {
5060
+ this.undo();
5061
+ } else if (key.name === "q") {
5062
+ this.destroy();
5063
+ this.config?.onExit?.();
5064
+ }
5065
+ return;
5066
+ }
5067
+ if (key.name === "escape" || key.name === "p") {
5068
+ this.isPaused = true;
5069
+ this.pauseMenuIndex = 0;
5070
+ this.render();
5071
+ return;
5072
+ }
5073
+ if (key.name === "q") {
5074
+ this.destroy();
5075
+ this.config?.onExit?.();
5076
+ return;
5077
+ }
5078
+ if (key.name === "r") {
5079
+ this.restart();
5080
+ return;
5081
+ }
5082
+ if (key.name === "u") {
5083
+ this.undo();
5084
+ return;
5085
+ }
5086
+ let moved = false;
5087
+ if (key.name === "left" || key.name === "a") {
5088
+ moved = this.slide("left");
5089
+ } else if (key.name === "right" || key.name === "d") {
5090
+ moved = this.slide("right");
5091
+ } else if (key.name === "up" || key.name === "w") {
5092
+ moved = this.slide("up");
5093
+ } else if (key.name === "down" || key.name === "s") {
5094
+ moved = this.slide("down");
5095
+ }
5096
+ if (moved) {
5097
+ this.render();
5098
+ }
5099
+ }
5100
+ renderCellLine(r, c, lineIdx) {
5101
+ const val = this.state.grid[r][c];
5102
+ const key = `${r},${c}`;
5103
+ const burst = this.burstCells.get(key);
5104
+ if (val === 0) {
5105
+ if (lineIdx === 1) return chalk4.hex("#2a3b4c")(" \xB7 ");
5106
+ return " ";
5107
+ }
5108
+ const valStr = val.toString().padStart(Math.floor((7 + val.toString().length) / 2)).padEnd(7);
5109
+ if (burst) {
5110
+ if (burst.frame === 1) {
5111
+ if (lineIdx === 0) return chalk4.bold.yellowBright(" \u2726 * \u2726 ");
5112
+ if (lineIdx === 1) return chalk4.bold.black.bgWhite(`\u2605${valStr}\u2605`);
5113
+ if (lineIdx === 2) return chalk4.bold.yellowBright(" \u2726 * \u2726 ");
5114
+ } else {
5115
+ if (lineIdx === 0) return chalk4.bold.whiteBright("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5116
+ if (lineIdx === 1) return chalk4.bold.black.bgHex("#ffd700")(`\u258C${valStr}\u2590`);
5117
+ if (lineIdx === 2) return chalk4.bold.yellow("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5118
+ }
5119
+ }
5120
+ return this.getTileLayer(val, valStr, lineIdx);
5121
+ }
5122
+ getTileLayer(val, valStr, lineIdx) {
5123
+ switch (val) {
5124
+ case 2:
5125
+ if (lineIdx === 0) return chalk4.hex("#e0e0e0")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5126
+ if (lineIdx === 1) return chalk4.hex("#424242")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#424242")("\u2588");
5127
+ return chalk4.hex("#9e9e9e")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5128
+ case 4:
5129
+ if (lineIdx === 0) return chalk4.hex("#80deea")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5130
+ if (lineIdx === 1) return chalk4.hex("#00838f")("\u2588") + chalk4.bold.hex("#e0f7fa")(valStr) + chalk4.hex("#00838f")("\u2588");
5131
+ return chalk4.hex("#006064")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5132
+ case 8:
5133
+ if (lineIdx === 0) return chalk4.hex("#4dd0e1")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5134
+ if (lineIdx === 1) return chalk4.hex("#0097a7")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#0097a7")("\u2588");
5135
+ return chalk4.hex("#006064")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5136
+ case 16:
5137
+ if (lineIdx === 0) return chalk4.hex("#4fc3f7")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5138
+ if (lineIdx === 1) return chalk4.hex("#0288d1")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#0288d1")("\u2588");
5139
+ return chalk4.hex("#01579b")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5140
+ case 32:
5141
+ if (lineIdx === 0) return chalk4.hex("#ffb74d")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5142
+ if (lineIdx === 1) return chalk4.hex("#f57c00")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#f57c00")("\u2588");
5143
+ return chalk4.hex("#e65100")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5144
+ case 64:
5145
+ if (lineIdx === 0) return chalk4.hex("#ff9800")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5146
+ if (lineIdx === 1) return chalk4.hex("#e65100")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#e65100")("\u2588");
5147
+ return chalk4.hex("#bf360c")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5148
+ case 128:
5149
+ if (lineIdx === 0) return chalk4.hex("#ff4081")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5150
+ if (lineIdx === 1) return chalk4.hex("#c2185b")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#c2185b")("\u2588");
5151
+ return chalk4.hex("#880e4f")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5152
+ case 256:
5153
+ if (lineIdx === 0) return chalk4.hex("#ea80fc")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5154
+ if (lineIdx === 1) return chalk4.hex("#aa00ff")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#aa00ff")("\u2588");
5155
+ return chalk4.hex("#4a148c")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5156
+ case 512:
5157
+ if (lineIdx === 0) return chalk4.hex("#69f0ae")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5158
+ if (lineIdx === 1) return chalk4.hex("#00c853")("\u2588") + chalk4.bold.white(valStr) + chalk4.hex("#00c853")("\u2588");
5159
+ return chalk4.hex("#1b5e20")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5160
+ case 1024:
5161
+ if (lineIdx === 0) return chalk4.hex("#00e5ff")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5162
+ if (lineIdx === 1) return chalk4.hex("#0091ea")("\u2588") + chalk4.bold.hex("#ffffff")(valStr) + chalk4.hex("#0091ea")("\u2588");
5163
+ return chalk4.hex("#01579b")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5164
+ case 2048:
5165
+ if (lineIdx === 0) return chalk4.bold.white.bgHex("#ffd700")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5166
+ if (lineIdx === 1) return chalk4.bold.black.bgHex("#ffd700")(`\u26A1${valStr.slice(1, -1)}\u26A1`);
5167
+ return chalk4.hex("#ff8f00")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5168
+ default:
5169
+ if (lineIdx === 0) return chalk4.bold.white.bgHex("#ff0055")("\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584");
5170
+ if (lineIdx === 1) return chalk4.bold.white.bgHex("#aa00ff")(`\u2605${valStr.slice(1, -1)}\u2605`);
5171
+ return chalk4.hex("#4a148c")("\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580\u2580");
5172
+ }
5173
+ }
5174
+ render() {
5175
+ const t = this.renderer.getTheme();
5176
+ if (this.showTutorial) {
5177
+ const lines = [
5178
+ "",
5179
+ t.highlight("CYBER 2048 // MEMORY SYNTHESIS PROTOCOL"),
5180
+ "",
5181
+ "\u2022 Slide the 4x4 matrix using ARROWS or WASD.",
5182
+ "\u2022 When two matching memory cores touch, they synthesize into one!",
5183
+ "\u2022 2 + 2 = 4, 4 + 4 = 8, 8 + 8 = 16 ... up to the 2048 SINGULARITY.",
5184
+ "\u2022 Made an accidental move? Press U to undo your last slide.",
5185
+ "\u2022 Strive to maximize your synthesized score before the matrix fills!",
5186
+ "",
5187
+ t.muted("Controls:"),
5188
+ " Arrow Keys / WASD : Slide Grid in Direction",
5189
+ " U : Undo Last Move",
5190
+ " P / Esc : Pause Menu",
5191
+ " R : Instant Restart",
5192
+ " Q : Quit to Arcade Menu",
5193
+ "",
5194
+ t.highlight("Press [ENTER] or [SPACE] to Initialize Matrix..."),
5195
+ ""
5196
+ ];
5197
+ const box2 = this.renderer.createBox(lines, TOTAL_WIDTH, "MISSION BRIEFING");
5198
+ this.renderer.draw(this.renderer.centerBlock(box2, TOTAL_WIDTH));
5199
+ return;
5200
+ }
5201
+ if (this.isPaused) {
5202
+ const menuItems = ["RESUME MATRIX", "RESTART MATRIX", "EXIT TO ROSTER"];
5203
+ const lines = [
5204
+ "",
5205
+ t.highlight("CYBER 2048 // MATRIX SUSPENDED"),
5206
+ "",
5207
+ ...menuItems.map((item, idx) => {
5208
+ if (idx === this.pauseMenuIndex) {
5209
+ return t.highlight(` \u25BA [ ${item} ]`);
5210
+ }
5211
+ return t.muted(` ${item} `);
5212
+ }),
5213
+ "",
5214
+ t.muted("Use Up/Down to select, Enter to confirm"),
5215
+ ""
5216
+ ];
5217
+ const box2 = this.renderer.createBox(lines, TOTAL_WIDTH, "SYSTEM PAUSED");
5218
+ this.renderer.draw(this.renderer.centerBlock(box2, TOTAL_WIDTH));
5219
+ return;
5220
+ }
5221
+ if (this.state.hasWon && !this.state.continueAfterWin) {
5222
+ const lines = [
5223
+ "",
5224
+ chalk4.bold.yellowBright("\u2605 \u2605 \u2605 CYBER SINGULARITY REACHED! 2048! \u2605 \u2605 \u2605"),
5225
+ "",
5226
+ `Total Score: ${t.highlight(this.state.score.toLocaleString())}`,
5227
+ `Total Moves: ${t.secondary(this.state.moves.toString())}`,
5228
+ `Highest Core: ${chalk4.bold.black.bgYellowBright(" 2048 ")}`,
5229
+ "",
5230
+ t.highlight("Press [C] or [SPACE] to Continue Endless Mode"),
5231
+ t.muted("Press [R] to Restart Matrix | Press [Q] to Quit"),
5232
+ ""
5233
+ ];
5234
+ const box2 = this.renderer.createBox(lines, TOTAL_WIDTH, "VICTORY ACHIEVED");
5235
+ this.renderer.draw(this.renderer.centerBlock(box2, TOTAL_WIDTH));
5236
+ return;
5237
+ }
5238
+ if (this.state.isGameOver) {
5239
+ const lines = [
5240
+ "",
5241
+ t.error("MATRIX LOCKED // NO VALID SYNTHESIS MOVES REMAINING"),
5242
+ "",
5243
+ `Final Score: ${t.highlight(this.state.score.toLocaleString())}`,
5244
+ `Total Moves: ${t.secondary(this.state.moves.toString())}`,
5245
+ `Peak Memory Core: ${t.secondary(this.state.highestTile.toString())}`,
5246
+ "",
5247
+ this.state.undosLeft > 0 ? t.secondary(`Press [U] to Undo (${this.state.undosLeft} left)`) : "",
5248
+ t.highlight("Press [R] or [SPACE] to Reset Board"),
5249
+ t.muted("Press [Q] to Return to Arcade Roster"),
5250
+ ""
5251
+ ].filter(Boolean);
5252
+ const box2 = this.renderer.createBox(lines, TOTAL_WIDTH, "MATRIX LOCKED");
5253
+ this.renderer.draw(this.renderer.centerBlock(box2, TOTAL_WIDTH));
5254
+ return;
5255
+ }
5256
+ const scoreStr = this.state.score.toString().padStart(6, "0");
5257
+ const highStr = this.state.bestScore.toString().padStart(6, "0");
5258
+ const undoStr = `${this.state.undosLeft > 900 ? "\u221E" : this.state.undosLeft}/3`;
5259
+ const topBar = ` ${chalk4.cyan("SCORE:")} ${chalk4.whiteBright.bold(scoreStr)} ${chalk4.cyan("HIGH:")} ${chalk4.whiteBright.bold(highStr)} ${chalk4.cyan("UNDO:")} ${chalk4.yellowBright.bold(undoStr)}`;
5260
+ const gridRows = [];
5261
+ const topGridBorder = chalk4.cyan(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2566\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2566\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2566\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557");
5262
+ const rowDivider = chalk4.cyan(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256C\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256C\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256C\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563");
5263
+ const bottomGridBorder = chalk4.cyan(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2569\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2569\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2569\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D");
5264
+ gridRows.push(topGridBorder);
5265
+ for (let r = 0; r < GRID_SIZE; r++) {
5266
+ for (let lineIdx = 0; lineIdx < 3; lineIdx++) {
5267
+ const lineParts = [0, 1, 2, 3].map((c) => this.renderCellLine(r, c, lineIdx));
5268
+ gridRows.push(
5269
+ chalk4.cyan(" \u2551 ") + lineParts.join(chalk4.cyan(" \u2551 ")) + chalk4.cyan(" \u2551")
5270
+ );
5271
+ }
5272
+ if (r < GRID_SIZE - 1) {
5273
+ gridRows.push(rowDivider);
5274
+ }
5275
+ }
5276
+ gridRows.push(bottomGridBorder);
5277
+ const bottomBar = ` ${chalk4.cyan("Arrows:")} ${chalk4.whiteBright("SLIDE")} ${chalk4.cyan("U:")} ${chalk4.whiteBright(`UNDO(${this.state.undosLeft > 900 ? "\u221E" : this.state.undosLeft})`)} ${chalk4.cyan("ESC:")} ${chalk4.whiteBright("MENU")}`;
5278
+ const frameLines = [
5279
+ "",
5280
+ topBar,
5281
+ "",
5282
+ ...gridRows,
5283
+ "",
5284
+ bottomBar,
5285
+ ""
5286
+ ];
5287
+ const box = this.renderer.centerBlock(frameLines.join("\n"), TOTAL_WIDTH);
5288
+ this.renderer.draw(box);
5289
+ }
5290
+ };
5291
+
5292
+ // src/games/cyber-tower/index.ts
5293
+ import chalk5 from "chalk";
5294
+ var ARENA_WIDTH4 = 54;
5295
+ var ARENA_HEIGHT4 = 17;
5296
+ var TOTAL_WIDTH2 = 58;
5297
+ var STARTING_WIDTH = 18;
5298
+ var DROP_Y = 2;
5299
+ var TOP_FLOOR_Y = 5;
5300
+ var PALETTE = [
5301
+ chalk5.cyanBright,
5302
+ chalk5.greenBright,
5303
+ chalk5.yellowBright,
5304
+ chalk5.magentaBright,
5305
+ chalk5.blueBright,
5306
+ chalk5.redBright,
5307
+ chalk5.hex("#00ffff"),
5308
+ chalk5.hex("#ff007f")
5309
+ ];
5310
+ var CyberTowerGame = class {
5311
+ id = "cyber-tower";
5312
+ metadata = ALL_GAMES_METADATA["cyber-tower"];
5313
+ config = null;
5314
+ renderer = defaultRenderer;
5315
+ input = new TerminalInputHandler();
5316
+ rng = new DeterministicRNG();
5317
+ gameLoopTimer = null;
5318
+ tickIntervalMs = 45;
5319
+ // Smooth 22 FPS physics
5320
+ baseSpeed = 0.85;
5321
+ state = {
5322
+ currentX: 4,
5323
+ currentVx: 0.85,
5324
+ currentWidth: STARTING_WIDTH,
5325
+ floors: [],
5326
+ fallingDebris: [],
5327
+ floorsStacked: 0,
5328
+ score: 0,
5329
+ bestScore: 0,
5330
+ perfectStreak: 0,
5331
+ maxStreak: 0,
5332
+ isPerfect: false,
5333
+ perfectFlashTicks: 0,
5334
+ isGameOver: false,
5335
+ altitude: 0
5336
+ };
5337
+ isPaused = false;
5338
+ pauseMenuIndex = 0;
5339
+ showTutorial = true;
5340
+ nextDebrisId = 1;
5341
+ init(config) {
5342
+ this.config = config;
5343
+ this.renderer.setTheme(config.theme);
5344
+ this.rng = new DeterministicRNG(config.seed || Date.now());
5345
+ if (config.skipTutorial !== void 0) {
5346
+ this.showTutorial = !config.skipTutorial;
5347
+ }
5348
+ this.applyDifficulty(config.difficulty);
5349
+ this.resetGame();
5350
+ }
5351
+ start() {
5352
+ this.isPaused = false;
5353
+ this.render();
5354
+ this.input.start(
5355
+ (key) => this.handleInput(key),
5356
+ () => {
5357
+ this.destroy();
5358
+ this.config?.onExit?.();
5359
+ }
5360
+ );
5361
+ if (!this.showTutorial) {
5362
+ this.scheduleNextTick();
5363
+ }
5364
+ }
5365
+ pause() {
5366
+ this.isPaused = true;
5367
+ if (this.gameLoopTimer) {
5368
+ clearTimeout(this.gameLoopTimer);
5369
+ this.gameLoopTimer = null;
5370
+ }
5371
+ }
5372
+ resume() {
5373
+ this.isPaused = false;
5374
+ this.scheduleNextTick();
5375
+ }
5376
+ restart() {
5377
+ this.resetGame();
5378
+ this.render();
5379
+ this.scheduleNextTick();
5380
+ }
5381
+ saveState() {
5382
+ return {
5383
+ state: this.state,
5384
+ showTutorial: this.showTutorial
5385
+ };
5386
+ }
5387
+ loadState(saved) {
5388
+ if (saved["state"]) this.state = saved["state"];
5389
+ if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
5390
+ }
5391
+ getState() {
5392
+ return this.state;
5393
+ }
5394
+ handleInputForTest(key) {
5395
+ this.handleInput(key);
5396
+ }
5397
+ destroy() {
5398
+ if (this.gameLoopTimer) {
5399
+ clearTimeout(this.gameLoopTimer);
5400
+ this.gameLoopTimer = null;
5401
+ }
5402
+ this.input.stop();
5403
+ }
5404
+ applyDifficulty(diff) {
5405
+ switch (diff) {
5406
+ case "easy":
5407
+ this.baseSpeed = 0.6;
5408
+ this.state.currentWidth = 20;
5409
+ break;
5410
+ case "hard":
5411
+ this.baseSpeed = 1.1;
5412
+ this.state.currentWidth = 14;
5413
+ break;
5414
+ case "insane":
5415
+ this.baseSpeed = 1.35;
5416
+ this.state.currentWidth = 12;
5417
+ break;
5418
+ case "normal":
5419
+ default:
5420
+ this.baseSpeed = 0.85;
5421
+ this.state.currentWidth = STARTING_WIDTH;
5422
+ break;
5423
+ }
5424
+ this.state.currentVx = this.baseSpeed;
5425
+ }
5426
+ resetGame() {
5427
+ const baseFloorWidth = this.state.currentWidth;
5428
+ const baseFloorX = Math.floor((ARENA_WIDTH4 - baseFloorWidth) / 2);
5429
+ this.state.floors = [
5430
+ {
5431
+ x: baseFloorX,
5432
+ width: baseFloorWidth,
5433
+ floorNumber: 0,
5434
+ colorIndex: 0
5435
+ }
5436
+ ];
5437
+ this.state.fallingDebris = [];
5438
+ this.state.floorsStacked = 0;
5439
+ this.state.score = 0;
5440
+ this.state.perfectStreak = 0;
5441
+ this.state.maxStreak = 0;
5442
+ this.state.isPerfect = false;
5443
+ this.state.perfectFlashTicks = 0;
5444
+ this.state.isGameOver = false;
5445
+ this.state.altitude = 0;
5446
+ this.state.currentX = 4;
5447
+ this.state.currentVx = this.baseSpeed;
5448
+ }
5449
+ scheduleNextTick() {
5450
+ if (this.isPaused || this.state.isGameOver || this.showTutorial) return;
5451
+ this.gameLoopTimer = setTimeout(() => {
5452
+ this.tick();
5453
+ this.scheduleNextTick();
5454
+ }, this.tickIntervalMs);
5455
+ }
5456
+ tick() {
5457
+ if (this.isPaused || this.showTutorial || this.state.isGameOver) return;
5458
+ this.state.currentX += this.state.currentVx;
5459
+ if (this.state.currentX <= 2) {
5460
+ this.state.currentX = 2;
5461
+ this.state.currentVx = Math.abs(this.state.currentVx);
5462
+ } else if (this.state.currentX + this.state.currentWidth >= ARENA_WIDTH4 - 2) {
5463
+ this.state.currentX = ARENA_WIDTH4 - this.state.currentWidth - 2;
5464
+ this.state.currentVx = -Math.abs(this.state.currentVx);
5465
+ }
5466
+ for (let i = this.state.fallingDebris.length - 1; i >= 0; i--) {
5467
+ const d = this.state.fallingDebris[i];
5468
+ d.y += 0.8;
5469
+ if (d.y >= ARENA_HEIGHT4) {
5470
+ this.state.fallingDebris.splice(i, 1);
5471
+ }
5472
+ }
5473
+ if (this.state.perfectFlashTicks > 0) {
5474
+ this.state.perfectFlashTicks--;
5475
+ if (this.state.perfectFlashTicks === 0) {
5476
+ this.state.isPerfect = false;
5477
+ }
5478
+ }
5479
+ this.render();
5480
+ }
5481
+ dropFloor() {
5482
+ if (this.state.isGameOver) return false;
5483
+ const topFloor = this.state.floors[this.state.floors.length - 1];
5484
+ const curX = this.state.currentX;
5485
+ const curWidth = this.state.currentWidth;
5486
+ const overlapStart = Math.max(curX, topFloor.x);
5487
+ const overlapEnd = Math.min(curX + curWidth, topFloor.x + topFloor.width);
5488
+ const overlapWidth = overlapEnd - overlapStart;
5489
+ if (overlapWidth <= 0.8) {
5490
+ this.state.fallingDebris.push({
5491
+ id: this.nextDebrisId++,
5492
+ x: curX,
5493
+ y: DROP_Y,
5494
+ width: curWidth,
5495
+ colorIndex: (this.state.floorsStacked + 1) % PALETTE.length
5496
+ });
5497
+ this.state.isGameOver = true;
5498
+ this.config?.onGameOver?.(this.state.score);
5499
+ if (this.config?.soundEnabled) playTerminalBell();
5500
+ this.render();
5501
+ return false;
5502
+ }
5503
+ const diff = Math.abs(curX - topFloor.x);
5504
+ const isPerfect = diff <= 0.85;
5505
+ let newX = overlapStart;
5506
+ let newWidth = Math.round(overlapWidth);
5507
+ if (isPerfect) {
5508
+ newX = topFloor.x;
5509
+ newWidth = topFloor.width;
5510
+ this.state.perfectStreak++;
5511
+ if (this.state.perfectStreak > this.state.maxStreak) {
5512
+ this.state.maxStreak = this.state.perfectStreak;
5513
+ }
5514
+ this.state.isPerfect = true;
5515
+ this.state.perfectFlashTicks = 5;
5516
+ const perfectBonus = 200 + this.state.perfectStreak * 100;
5517
+ this.addScore(perfectBonus);
5518
+ if (this.state.perfectStreak === 3) {
5519
+ this.config?.onAchievementUnlock?.("perfect_streak");
5520
+ }
5521
+ if (this.state.perfectStreak >= 3 && newWidth < STARTING_WIDTH) {
5522
+ newWidth = Math.min(STARTING_WIDTH, newWidth + 1);
5523
+ }
5524
+ } else {
5525
+ this.state.perfectStreak = 0;
5526
+ this.state.isPerfect = false;
5527
+ this.addScore(100);
5528
+ if (curX < topFloor.x) {
5529
+ const sliceWidth = topFloor.x - curX;
5530
+ this.state.fallingDebris.push({
5531
+ id: this.nextDebrisId++,
5532
+ x: curX,
5533
+ y: DROP_Y,
5534
+ width: Math.round(sliceWidth),
5535
+ colorIndex: (this.state.floorsStacked + 1) % PALETTE.length
5536
+ });
5537
+ } else if (curX + curWidth > topFloor.x + topFloor.width) {
5538
+ const sliceX = topFloor.x + topFloor.width;
5539
+ const sliceWidth = curX + curWidth - sliceX;
5540
+ this.state.fallingDebris.push({
5541
+ id: this.nextDebrisId++,
5542
+ x: sliceX,
5543
+ y: DROP_Y,
5544
+ width: Math.round(sliceWidth),
5545
+ colorIndex: (this.state.floorsStacked + 1) % PALETTE.length
5546
+ });
5547
+ }
5548
+ }
5549
+ this.state.floorsStacked++;
5550
+ this.state.altitude = this.state.floorsStacked * 12;
5551
+ this.state.floors.push({
5552
+ x: newX,
5553
+ width: newWidth,
5554
+ floorNumber: this.state.floorsStacked,
5555
+ colorIndex: this.state.floorsStacked % PALETTE.length
5556
+ });
5557
+ if (this.state.floorsStacked === 1) {
5558
+ this.config?.onAchievementUnlock?.("first_floor");
5559
+ }
5560
+ if (this.state.floorsStacked === 30) {
5561
+ this.config?.onAchievementUnlock?.("stratosphere");
5562
+ }
5563
+ if (this.config?.soundEnabled) playTerminalBell();
5564
+ this.state.currentWidth = newWidth;
5565
+ const speedBoost = Math.min(0.7, this.state.floorsStacked * 0.015);
5566
+ const direction = this.state.currentVx > 0 ? -1 : 1;
5567
+ this.state.currentVx = (this.baseSpeed + speedBoost) * direction;
5568
+ this.state.currentX = direction > 0 ? 3 : ARENA_WIDTH4 - newWidth - 3;
5569
+ this.render();
5570
+ return true;
5571
+ }
5572
+ addScore(pts) {
5573
+ this.state.score += pts;
5574
+ if (this.state.score > this.state.bestScore) {
5575
+ this.state.bestScore = this.state.score;
5576
+ }
5577
+ this.config?.onScoreUpdate?.(this.state.score);
5578
+ }
5579
+ handleInput(key) {
5580
+ if (this.showTutorial) {
5581
+ if (key.name === "return" || key.name === "space") {
5582
+ this.showTutorial = false;
5583
+ this.scheduleNextTick();
5584
+ this.render();
5585
+ } else if (key.name === "escape" || key.name === "q") {
5586
+ this.destroy();
5587
+ this.config?.onExit?.();
5588
+ }
5589
+ return;
5590
+ }
5591
+ if (this.isPaused) {
5592
+ if (key.name === "up" || key.name === "w") {
5593
+ this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
5594
+ this.render();
5595
+ } else if (key.name === "down" || key.name === "s") {
5596
+ this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
5597
+ this.render();
5598
+ } else if (key.name === "return" || key.name === "space") {
5599
+ if (this.pauseMenuIndex === 0) {
5600
+ this.isPaused = false;
5601
+ this.scheduleNextTick();
5602
+ this.render();
5603
+ } else if (this.pauseMenuIndex === 1) {
5604
+ this.isPaused = false;
5605
+ this.restart();
5606
+ } else if (this.pauseMenuIndex === 2) {
5607
+ this.destroy();
5608
+ this.config?.onExit?.();
5609
+ }
5610
+ } else if (key.name === "escape" || key.name === "p") {
5611
+ this.isPaused = false;
5612
+ this.scheduleNextTick();
5613
+ this.render();
5614
+ } else if (key.name === "q") {
5615
+ this.destroy();
5616
+ this.config?.onExit?.();
5617
+ }
5618
+ return;
5619
+ }
5620
+ if (key.name === "escape" || key.name === "p") {
5621
+ this.isPaused = true;
5622
+ this.pauseMenuIndex = 0;
5623
+ if (this.gameLoopTimer) {
5624
+ clearTimeout(this.gameLoopTimer);
5625
+ this.gameLoopTimer = null;
5626
+ }
5627
+ this.render();
5628
+ return;
5629
+ }
5630
+ if (key.name === "q") {
5631
+ this.destroy();
5632
+ this.config?.onExit?.();
5633
+ return;
5634
+ }
5635
+ if (key.name === "r") {
5636
+ this.restart();
5637
+ return;
5638
+ }
5639
+ if (this.state.isGameOver) {
5640
+ if (key.name === "return" || key.name === "space" || key.name === "r") {
5641
+ this.resetGame();
5642
+ this.render();
5643
+ this.scheduleNextTick();
5644
+ }
5645
+ return;
5646
+ }
5647
+ if (key.name === "space" || key.name === "return" || key.name === "down" || key.name === "w") {
5648
+ this.dropFloor();
5649
+ }
5650
+ }
5651
+ render() {
5652
+ const t = this.renderer.getTheme();
5653
+ if (this.showTutorial) {
5654
+ const lines = [
5655
+ "",
5656
+ t.highlight("CYBER TOWER // PRECISION STACKING PROTOCOL"),
5657
+ "",
5658
+ "\u2022 An oscillating structural floor slides across the upper rail.",
5659
+ "\u2022 Press [SPACE] or [DOWN] to drop the block onto the tower spire.",
5660
+ "\u2022 Overhangs are sliced off! The tower becomes narrower on mistakes.",
5661
+ "\u2022 Time your drop with perfection to chain PERFECT combos and restore width!",
5662
+ "\u2022 Reach into the cyber stratosphere and build the tallest spire.",
5663
+ "",
5664
+ t.muted("Controls:"),
5665
+ " Space / Down / Enter : Drop Floor Block",
5666
+ " P / Esc : Pause System",
5667
+ " R : Instant Demolish & Rebuild",
5668
+ " Q : Quit to Arcade Menu",
5669
+ "",
5670
+ t.highlight("Press [ENTER] or [SPACE] to Initialize Crane..."),
5671
+ ""
5672
+ ];
5673
+ const box2 = this.renderer.createBox(lines, TOTAL_WIDTH2, "MISSION BRIEFING");
5674
+ this.renderer.draw(this.renderer.centerBlock(box2, TOTAL_WIDTH2));
5675
+ return;
5676
+ }
5677
+ if (this.isPaused) {
5678
+ const menuItems = ["RESUME CONSTRUCTION", "REBUILD SPIRE", "EXIT TO ROSTER"];
5679
+ const lines = [
5680
+ "",
5681
+ t.highlight("CYBER TOWER // CONSTRUCTION SUSPENDED"),
5682
+ "",
5683
+ ...menuItems.map((item, idx) => {
5684
+ if (idx === this.pauseMenuIndex) {
5685
+ return t.highlight(` \u25BA [ ${item} ]`);
5686
+ }
5687
+ return t.muted(` ${item} `);
5688
+ }),
5689
+ "",
5690
+ t.muted("Use Up/Down to select, Enter to confirm"),
5691
+ ""
5692
+ ];
5693
+ const box2 = this.renderer.createBox(lines, TOTAL_WIDTH2, "SYSTEM PAUSED");
5694
+ this.renderer.draw(this.renderer.centerBlock(box2, TOTAL_WIDTH2));
5695
+ return;
5696
+ }
5697
+ if (this.state.isGameOver) {
5698
+ const lines = [
5699
+ "",
5700
+ t.error("TOWER COLLAPSED // STRUCTURAL FAILURE"),
5701
+ "",
5702
+ `Floors Stacked: ${t.highlight(this.state.floorsStacked.toString())}`,
5703
+ `Peak Altitude: ${t.secondary(`${this.state.altitude}m`)}`,
5704
+ `Final Score: ${t.highlight(this.state.score.toLocaleString())}`,
5705
+ `Max Perfect Combo: ${t.secondary(`x${this.state.maxStreak}`)}`,
5706
+ "",
5707
+ t.highlight("Press [R] or [SPACE] to Rebuild Spire"),
5708
+ t.muted("Press [Q] to Return to Arcade Roster"),
5709
+ ""
5710
+ ];
5711
+ const box2 = this.renderer.createBox(lines, TOTAL_WIDTH2, "TOWER COLLAPSED");
5712
+ this.renderer.draw(this.renderer.centerBlock(box2, TOTAL_WIDTH2));
5713
+ return;
5714
+ }
5715
+ const floorStr = `FLOOR: ${this.state.floorsStacked}`;
5716
+ const altStr = `ALT: ${this.state.altitude}m`;
5717
+ const scoreStr = `SCORE: ${this.state.score.toLocaleString()}`;
5718
+ const perfectStr = this.state.perfectStreak > 0 ? chalk5.bold.yellowBright(`PERFECT x${this.state.perfectStreak}!`) : "";
5719
+ const topBar = `${t.secondary(floorStr)} ${t.highlight(altStr)} ${t.accent(scoreStr)} ${perfectStr}`;
5720
+ const grid = Array.from(
5721
+ { length: ARENA_HEIGHT4 },
5722
+ () => Array.from({ length: ARENA_WIDTH4 }, () => " ")
5723
+ );
5724
+ const colorGrid = Array.from(
5725
+ { length: ARENA_HEIGHT4 },
5726
+ () => Array.from({ length: ARENA_WIDTH4 }, () => null)
5727
+ );
5728
+ const stars = [
5729
+ { r: 0, c: 8 },
5730
+ { r: 1, c: 45 },
5731
+ { r: 3, c: 12 },
5732
+ { r: 4, c: 48 },
5733
+ { r: 6, c: 6 },
5734
+ { r: 7, c: 40 }
5735
+ ];
5736
+ for (const star of stars) {
5737
+ grid[star.r][star.c] = "\xB7";
5738
+ }
5739
+ const cx = Math.round(this.state.currentX);
5740
+ const cw = this.state.currentWidth;
5741
+ const curColorIdx = (this.state.floorsStacked + 1) % PALETTE.length;
5742
+ for (let x = 0; x < cw; x++) {
5743
+ const gx = cx + x;
5744
+ if (gx >= 0 && gx < ARENA_WIDTH4) {
5745
+ grid[DROP_Y][gx] = "\u2588";
5746
+ colorGrid[DROP_Y][gx] = curColorIdx;
5747
+ }
5748
+ }
5749
+ for (let x = 0; x < cw; x += 4) {
5750
+ const gx = cx + x;
5751
+ if (gx >= 0 && gx < ARENA_WIDTH4) {
5752
+ grid[DROP_Y + 1][gx] = "\u25BC";
5753
+ }
5754
+ }
5755
+ for (const d of this.state.fallingDebris) {
5756
+ const dy = Math.round(d.y);
5757
+ const dx = Math.round(d.x);
5758
+ if (dy >= 0 && dy < ARENA_HEIGHT4) {
5759
+ for (let x = 0; x < d.width; x++) {
5760
+ const gx = dx + x;
5761
+ if (gx >= 0 && gx < ARENA_WIDTH4) {
5762
+ grid[dy][gx] = "\u2592";
5763
+ colorGrid[dy][gx] = d.colorIndex;
5764
+ }
5765
+ }
5766
+ }
5767
+ }
5768
+ const visibleFloorsCount = Math.min(10, this.state.floors.length);
5769
+ const startIndex = this.state.floors.length - 1;
5770
+ for (let i = 0; i < visibleFloorsCount; i++) {
5771
+ const floor = this.state.floors[startIndex - i];
5772
+ const rowY = TOP_FLOOR_Y + i;
5773
+ if (rowY < ARENA_HEIGHT4 - 1) {
5774
+ const fx = Math.round(floor.x);
5775
+ for (let x = 0; x < floor.width; x++) {
5776
+ const gx = fx + x;
5777
+ if (gx >= 0 && gx < ARENA_WIDTH4) {
5778
+ grid[rowY][gx] = "\u2588";
5779
+ colorGrid[rowY][gx] = floor.colorIndex;
5780
+ }
5781
+ }
5782
+ }
5783
+ }
5784
+ if (this.state.floors.length <= 10) {
5785
+ for (let x = 2; x < ARENA_WIDTH4 - 2; x++) {
5786
+ grid[ARENA_HEIGHT4 - 1][x] = "\u2550";
5787
+ }
5788
+ }
5789
+ const arenaLines = [];
5790
+ for (let r = 0; r < ARENA_HEIGHT4; r++) {
5791
+ let line = "";
5792
+ for (let c = 0; c < ARENA_WIDTH4; c++) {
5793
+ const char = grid[r][c];
5794
+ const colorIdx = colorGrid[r][c];
5795
+ if (colorIdx !== null && char === "\u2588") {
5796
+ const colorFn = PALETTE[colorIdx];
5797
+ line += colorFn("\u2588");
5798
+ } else if (colorIdx !== null && char === "\u2592") {
5799
+ line += chalk5.gray("\u2592");
5800
+ } else if (char === "\u25BC") {
5801
+ line += t.muted("\u25BC");
5802
+ } else if (char === "\u2550") {
5803
+ line += t.secondary("\u2550");
5804
+ } else if (char === "\xB7") {
5805
+ line += chalk5.gray("\xB7");
5806
+ } else {
5807
+ line += " ";
5808
+ }
5809
+ }
5810
+ arenaLines.push(`\u2551${line}\u2551`);
5811
+ }
5812
+ const topBorder = `\u2554${"\u2550".repeat(ARENA_WIDTH4)}\u2557`;
5813
+ const bottomBorder = `\u255A${"\u2550".repeat(ARENA_WIDTH4)}\u255D`;
5814
+ let statusMsg = t.muted("Press SPACE to drop floor onto spire");
5815
+ if (this.state.isPerfect) {
5816
+ statusMsg = chalk5.bold.yellowBright("\u2605 \u2605 \u2605 PERFECT DROP! WIDTH PRESERVED! \u2605 \u2605 \u2605");
5817
+ }
5818
+ const frameLines = [
5819
+ topBar,
5820
+ statusMsg,
5821
+ topBorder,
5822
+ ...arenaLines,
5823
+ bottomBorder,
5824
+ t.muted("Controls: Space / Down: Drop Floor | P: Pause | R: Reset | Q: Quit")
5825
+ ];
5826
+ const box = this.renderer.centerBlock(frameLines.join("\n"), TOTAL_WIDTH2);
5827
+ this.renderer.draw(box);
5828
+ }
5829
+ };
5830
+
3220
5831
  export {
3221
5832
  APP_NAME,
3222
5833
  APP_TAGLINE,
@@ -3251,6 +5862,10 @@ export {
3251
5862
  PacketManGame,
3252
5863
  CyberViperGame,
3253
5864
  VoidInvadersGame,
3254
- HashMatrixGame
5865
+ HashMatrixGame,
5866
+ CyberDinoGame,
5867
+ CyberBreakoutGame,
5868
+ Cyber2048Game,
5869
+ CyberTowerGame
3255
5870
  };
3256
- //# sourceMappingURL=chunk-BIOTUQT7.js.map
5871
+ //# sourceMappingURL=chunk-EQAKR7UF.js.map