terminull-arcade 1.0.1 → 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.
@@ -1,3294 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/shared/constants.ts
4
- var APP_NAME = "TERMINULL";
5
- var APP_TAGLINE = "Enter the Terminull. Play beyond the prompt.";
6
- var APP_VERSION = "1.0.0";
7
- var MIN_TERMINAL_COLUMNS = 80;
8
- var MIN_TERMINAL_ROWS = 24;
9
- var ALL_GAMES_METADATA = {
10
- "packet-man": {
11
- id: "packet-man",
12
- name: "Packet Man",
13
- tagline: "Chomp byte pellets and evade rogue memory daemons",
14
- description: "Classic maze arcade: navigate labyrinths, chomp pellets, grab Super Capacitors, and hunt vulnerable daemons.",
15
- category: "arcade",
16
- difficultyLevels: ["easy", "normal", "hard", "insane"],
17
- controls: [
18
- { key: "Arrow Keys / WASD", action: "Move Packet Man", description: "Navigate through corridors" },
19
- { key: "Esc / P", action: "Pause Menu", description: "Open pause / exit dialog" },
20
- { key: "R", action: "Restart Game", description: "Restart round" },
21
- { key: "Q", action: "Quit", description: "Return to arcade menu" }
22
- ],
23
- achievements: [
24
- { id: "first_chomp", title: "First Nibble", description: "Chomp 50 byte pellets" },
25
- { id: "daemon_slayer", title: "Kernel Purge", description: "Chomp all 4 daemons in a single power surge" },
26
- { id: "maze_sweeper", title: "Zero Remaining", description: "Clear an entire memory maze board" }
27
- ]
28
- },
29
- "cyber-viper": {
30
- id: "cyber-viper",
31
- name: "Cyber Viper",
32
- tagline: "Slither through the grid, feast on energy apples, avoid your tail",
33
- description: "The definitive classic snake arcade: grow longer with every bite, snag golden bonus orbs, and test your reflexes.",
34
- category: "arcade",
35
- difficultyLevels: ["easy", "normal", "hard", "insane"],
36
- controls: [
37
- { key: "Arrow Keys / WASD", action: "Steer Viper", description: "Turn direction" },
38
- { key: "Esc / P", action: "Pause Menu", description: "Open pause / exit dialog" },
39
- { key: "R", action: "Restart", description: "Try again immediately" },
40
- { key: "Q", action: "Quit", description: "Return to arcade menu" }
41
- ],
42
- achievements: [
43
- { id: "first_bite", title: "First Crunch", description: "Eat your first energy apple" },
44
- { id: "golden_feast", title: "Golden Appetite", description: "Snag a rare golden power orb" },
45
- { id: "long_viper", title: "Anaconda Protocol", description: "Reach a snake length of 25 segments" }
46
- ]
47
- },
48
- "neon-circuit": {
49
- id: "neon-circuit",
50
- name: "Neon Circuit",
51
- tagline: "Route pure energy through node grids",
52
- description: "Pipe puzzle: rotate circuit conduits to bridge power source to target nodes before moves run out.",
53
- category: "puzzle",
54
- difficultyLevels: ["easy", "normal", "hard", "insane"],
55
- controls: [
56
- { key: "Arrow Keys / WASD", action: "Navigate Grid", description: "Move circuit cursor" },
57
- { key: "Space / Enter", action: "Rotate Tile", description: "Rotate wire 90 degrees clockwise" },
58
- { key: "R", action: "Reset Grid", description: "Reset puzzle to initial state" },
59
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
60
- ],
61
- achievements: [
62
- { id: "first_spark", title: "First Spark", description: "Complete your first circuit" },
63
- { id: "overclocked", title: "Overclocked Flow", description: "Complete a level with 5+ moves remaining" },
64
- { id: "grid_master", title: "Grid Overlord", description: "Solve an insane circuit puzzle" }
65
- ]
66
- },
67
- "byte-runner": {
68
- id: "byte-runner",
69
- name: "Byte Runner",
70
- tagline: "Sprint down the endless 3-lane packet highway",
71
- description: "High-speed lane runner: dodge obstacles, jump over blocks, collect bytes, and grab shields.",
72
- category: "arcade",
73
- difficultyLevels: ["easy", "normal", "hard", "insane"],
74
- controls: [
75
- { key: "Left / Right / A / D", action: "Change Lane", description: "Shift between 3 lanes" },
76
- { key: "Up / W / Space", action: "Phase Jump", description: "Hop over obstacles" },
77
- { key: "Down / S", action: "Dive / Slide", description: "Fast drop" },
78
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
79
- ],
80
- achievements: [
81
- { id: "packet_chaser", title: "Packet Chaser", description: "Collect 50 clean byte clusters" },
82
- { id: "shield_matrix", title: "Hardened Buffer", description: "Absorb a collision with an active shield" },
83
- { id: "hyperspeed", title: "Fiber Velocity", description: "Reach a distance score over 5,000" }
84
- ]
85
- },
86
- "void-invaders": {
87
- id: "void-invaders",
88
- name: "Void Invaders",
89
- tagline: "Defend orbital defenses against descending alien waves",
90
- description: "Classic vertical space shooter: maneuver laser gunship, blast invaders, and shoot mystery saucers.",
91
- category: "arcade",
92
- difficultyLevels: ["easy", "normal", "hard", "insane"],
93
- controls: [
94
- { key: "Left / Right / A / D", action: "Move Cannon", description: "Slide gunship along bottom" },
95
- { key: "Space", action: "Fire Laser", description: "Shoot plasma cannons" },
96
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
97
- ],
98
- achievements: [
99
- { id: "alien_down", title: "First Contact", description: "Destroy your first alien invader" },
100
- { id: "mothership_shot", title: "UFO Hunter", description: "Shoot down a high-value red mothership" },
101
- { id: "wave_cleared", title: "Sky Guardian", description: "Clear an entire invader armada wave" }
102
- ]
103
- },
104
- "bit-breaker": {
105
- id: "bit-breaker",
106
- name: "Bit Breaker",
107
- tagline: "Smash through walls of multi-colored arcade bricks",
108
- description: "Addictive paddle breakout: angle ricocheting balls, shatter bricks, and unleash multi-ball chaos.",
109
- category: "arcade",
110
- difficultyLevels: ["easy", "normal", "hard", "insane"],
111
- controls: [
112
- { key: "Left / Right / A / D", action: "Move Paddle", description: "Control paddle position" },
113
- { key: "Space", action: "Launch Ball", description: "Release ball from paddle" },
114
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
115
- ],
116
- achievements: [
117
- { id: "brick_crusher", title: "First Smash", description: "Break 20 arcade bricks" },
118
- { id: "paddle_virtuoso", title: "Iron Reflexes", description: "Maintain a 30-hit paddle rally" },
119
- { id: "board_clear", title: "Demolition Pro", description: "Clear an entire brick formation" }
120
- ]
121
- },
122
- "stack-tower": {
123
- id: "stack-tower",
124
- name: "Stack Tower",
125
- tagline: "Rotate and drop falling geometric blocks into complete lines",
126
- description: "The all-time classic block-stacker: clear lines, trigger 4-line combos, and survive speedups.",
127
- category: "puzzle",
128
- difficultyLevels: ["easy", "normal", "hard", "insane"],
129
- controls: [
130
- { key: "Left / Right", action: "Move Block", description: "Shift block horizontally" },
131
- { key: "Up / Space", action: "Rotate", description: "Rotate block 90 degrees" },
132
- { key: "Down", action: "Soft Drop", description: "Accelerate fall" },
133
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
134
- ],
135
- achievements: [
136
- { id: "line_clear", title: "Single Clear", description: "Clear your first horizontal line" },
137
- { id: "quad_clear", title: "Tetra Smash", description: "Clear 4 lines in a single drop" },
138
- { id: "tower_master", title: "Block Master", description: "Score over 10,000 points" }
139
- ]
140
- },
141
- "data-hopper": {
142
- id: "data-hopper",
143
- name: "Data Hopper",
144
- tagline: "Hop across busy highways and rushing rivers",
145
- description: "Frogger-style road crosser: dodge speeding traffic, leap onto floating logs, and reach home safely.",
146
- category: "arcade",
147
- difficultyLevels: ["easy", "normal", "hard", "insane"],
148
- controls: [
149
- { key: "Arrow Keys / WASD", action: "Hop Direction", description: "Leap one grid tile" },
150
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" },
151
- { key: "R", action: "Restart Hop", description: "Restart crossing" },
152
- { key: "Q", action: "Quit", description: "Return to arcade menu" }
153
- ],
154
- achievements: [
155
- { id: "safe_crossing", title: "First Crossing", description: "Deliver a hopper safely home" },
156
- { id: "traffic_dodger", title: "Speedy Legs", description: "Cross the highway without stopping" },
157
- { id: "all_home", title: "Family Reunion", description: "Fill all 5 home bases" }
158
- ]
159
- },
160
- "flappy-byte": {
161
- id: "flappy-byte",
162
- name: "Flappy Byte",
163
- tagline: "Tap to flap through narrow pipe gaps",
164
- description: "Fast-paced flapping arcade: maintain altitude, navigate pipe gates, and chase high score streaks.",
165
- category: "arcade",
166
- difficultyLevels: ["easy", "normal", "hard", "insane"],
167
- controls: [
168
- { key: "Space / Up", action: "Flap Wings", description: "Thrust upward against gravity" },
169
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" },
170
- { key: "R", action: "Restart Flight", description: "Try again immediately" },
171
- { key: "Q", action: "Quit", description: "Return to arcade menu" }
172
- ],
173
- achievements: [
174
- { id: "first_pipe", title: "First Flight", description: "Pass your first obstacle pipe" },
175
- { id: "bronze_flyer", title: "Bronze Aviator", description: "Score 10 consecutive gates" },
176
- { id: "silver_flyer", title: "Silver Aviator", description: "Score 25 consecutive gates" }
177
- ]
178
- },
179
- "cyber-pong": {
180
- id: "cyber-pong",
181
- name: "Cyber Pong",
182
- tagline: "High-speed tennis rally against smart AI opponent",
183
- description: "The quintessential arcade rally: deflection angles, spin shots, and first to 7 points takes victory.",
184
- category: "arcade",
185
- difficultyLevels: ["easy", "normal", "hard", "insane"],
186
- controls: [
187
- { key: "Up / Down / W / S", action: "Move Paddle", description: "Adjust paddle height" },
188
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" },
189
- { key: "R", action: "Restart Match", description: "New set" },
190
- { key: "Q", action: "Quit", description: "Return to arcade menu" }
191
- ],
192
- achievements: [
193
- { id: "first_point", title: "First Serve", description: "Score a point against opponent" },
194
- { id: "shutout", title: "Flawless Set", description: "Win a match without conceding a point" },
195
- { id: "rally_champion", title: "Table Sovereign", description: "Win on insane difficulty" }
196
- ]
197
- },
198
- "meteor-drift": {
199
- id: "meteor-drift",
200
- name: "Meteor Drift",
201
- tagline: "Thrust, rotate, and blast space rocks into dust",
202
- description: "Asteroids-style space drift: 360-degree rotation, momentum thrust physics, and asteroid splitting.",
203
- category: "arcade",
204
- difficultyLevels: ["easy", "normal", "hard", "insane"],
205
- controls: [
206
- { key: "Left / Right", action: "Rotate Ship", description: "Turn ship heading" },
207
- { key: "Up / W", action: "Thrust Engine", description: "Accelerate forward" },
208
- { key: "Space", action: "Fire Cannons", description: "Blast space rocks" },
209
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
210
- ],
211
- achievements: [
212
- { id: "rock_smasher", title: "First Stardust", description: "Break your first giant asteroid" },
213
- { id: "drift_king", title: "Inertia Master", description: "Destroy 10 rocks while coasting" },
214
- { id: "sector_clear", title: "Cosmic Ace", description: "Survive 3 asteroid waves" }
215
- ]
216
- },
217
- "core-defuser": {
218
- id: "core-defuser",
219
- name: "Core Defuser",
220
- tagline: "Uncover safe tiles and flag hidden mines",
221
- description: "Classic minesweeper logic: reveal numbers, deduce danger zones, and flag every hidden explosive.",
222
- category: "puzzle",
223
- difficultyLevels: ["easy", "normal", "hard", "insane"],
224
- controls: [
225
- { key: "Arrow Keys / WASD", action: "Move Pointer", description: "Inspect grid cells" },
226
- { key: "Space", action: "Reveal Cell", description: "Uncover target cell" },
227
- { key: "F", action: "Flag Mine", description: "Mark dangerous tile" },
228
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
229
- ],
230
- achievements: [
231
- { id: "safe_step", title: "First Discovery", description: "Reveal a cell with zero casualties" },
232
- { id: "flag_master", title: "EOD Technician", description: "Flag 5 real mines correctly" },
233
- { id: "grid_defused", title: "Bomb Squad Master", description: "Complete a minefield without detonation" }
234
- ]
235
- }
236
- };
237
-
238
- // src/shared/types.ts
239
- import { z } from "zod";
240
- var UserSettingsSchema = z.object({
241
- theme: z.enum(["default", "retro-green", "neon", "minimal", "high-contrast"]).default("default"),
242
- soundEnabled: z.boolean().default(true),
243
- reducedMotion: z.boolean().default(false),
244
- colorblindMode: z.boolean().default(false)
245
- });
246
- var UserProfileSchema = z.object({
247
- version: z.number().default(1),
248
- createdAt: z.string(),
249
- lastPlayedAt: z.string(),
250
- settings: UserSettingsSchema,
251
- highScores: z.record(z.string(), z.number()).default({}),
252
- playCounts: z.record(z.string(), z.number()).default({}),
253
- totalTimePlayedSec: z.record(z.string(), z.number()).default({}),
254
- unlockedAchievements: z.record(z.string(), z.array(z.string())).default({}),
255
- savedStates: z.record(z.string(), z.record(z.string(), z.unknown())).default({})
256
- });
257
-
258
- // src/core/storage.ts
259
- import fs from "fs";
260
- import path from "path";
261
- import os from "os";
262
- var StorageManager = class {
263
- configDir;
264
- filePath;
265
- cachedProfile = null;
266
- constructor(customDir) {
267
- this.configDir = customDir || path.join(os.homedir(), ".config", "terminull");
268
- this.filePath = path.join(this.configDir, "profile.json");
269
- }
270
- getProfilePath() {
271
- return this.filePath;
272
- }
273
- ensureDirectory() {
274
- if (!fs.existsSync(this.configDir)) {
275
- fs.mkdirSync(this.configDir, { recursive: true });
276
- }
277
- }
278
- getProfile() {
279
- if (this.cachedProfile) {
280
- return this.cachedProfile;
281
- }
282
- try {
283
- this.ensureDirectory();
284
- if (fs.existsSync(this.filePath)) {
285
- const raw = fs.readFileSync(this.filePath, "utf-8");
286
- const parsed = JSON.parse(raw);
287
- const result = UserProfileSchema.safeParse(parsed);
288
- if (result.success) {
289
- this.cachedProfile = result.data;
290
- return this.cachedProfile;
291
- }
292
- }
293
- } catch {
294
- }
295
- const defaultProfile = {
296
- version: 1,
297
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
298
- lastPlayedAt: (/* @__PURE__ */ new Date()).toISOString(),
299
- settings: {
300
- theme: "default",
301
- soundEnabled: true,
302
- reducedMotion: false,
303
- colorblindMode: false
304
- },
305
- highScores: {},
306
- playCounts: {},
307
- totalTimePlayedSec: {},
308
- unlockedAchievements: {},
309
- savedStates: {}
310
- };
311
- this.saveProfile(defaultProfile);
312
- this.cachedProfile = defaultProfile;
313
- return defaultProfile;
314
- }
315
- saveProfile(profile) {
316
- try {
317
- this.ensureDirectory();
318
- profile.lastPlayedAt = (/* @__PURE__ */ new Date()).toISOString();
319
- fs.writeFileSync(this.filePath, JSON.stringify(profile, null, 2), "utf-8");
320
- this.cachedProfile = profile;
321
- } catch (err) {
322
- console.error("Warning: Unable to save profile to disk:", err);
323
- }
324
- }
325
- recordScore(gameId, score) {
326
- const profile = this.getProfile();
327
- const currentHigh = profile.highScores[gameId] || 0;
328
- const isNewHigh = score > currentHigh;
329
- if (isNewHigh) {
330
- profile.highScores[gameId] = score;
331
- }
332
- profile.playCounts[gameId] = (profile.playCounts[gameId] || 0) + 1;
333
- this.saveProfile(profile);
334
- return isNewHigh;
335
- }
336
- getHighScore(gameId) {
337
- const profile = this.getProfile();
338
- return profile.highScores[gameId] || 0;
339
- }
340
- addPlayTime(gameId, seconds) {
341
- const profile = this.getProfile();
342
- profile.totalTimePlayedSec[gameId] = (profile.totalTimePlayedSec[gameId] || 0) + seconds;
343
- this.saveProfile(profile);
344
- }
345
- unlockAchievement(gameId, achievementId) {
346
- const profile = this.getProfile();
347
- const list = profile.unlockedAchievements[gameId] || [];
348
- if (!list.includes(achievementId)) {
349
- list.push(achievementId);
350
- profile.unlockedAchievements[gameId] = list;
351
- this.saveProfile(profile);
352
- return true;
353
- }
354
- return false;
355
- }
356
- updateSettings(partialSettings) {
357
- const profile = this.getProfile();
358
- profile.settings = {
359
- ...profile.settings,
360
- ...partialSettings
361
- };
362
- this.saveProfile(profile);
363
- return profile;
364
- }
365
- saveGameState(gameId, state) {
366
- const profile = this.getProfile();
367
- profile.savedStates[gameId] = state;
368
- this.saveProfile(profile);
369
- }
370
- loadGameState(gameId) {
371
- const profile = this.getProfile();
372
- return profile.savedStates[gameId] || null;
373
- }
374
- resetProfile() {
375
- const cleanProfile = {
376
- version: 1,
377
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
378
- lastPlayedAt: (/* @__PURE__ */ new Date()).toISOString(),
379
- settings: {
380
- theme: "default",
381
- soundEnabled: true,
382
- reducedMotion: false,
383
- colorblindMode: false
384
- },
385
- highScores: {},
386
- playCounts: {},
387
- totalTimePlayedSec: {},
388
- unlockedAchievements: {},
389
- savedStates: {}
390
- };
391
- this.saveProfile(cleanProfile);
392
- }
393
- };
394
- var defaultStorage = new StorageManager();
395
-
396
- // src/core/achievements.ts
397
- var AchievementManager = class {
398
- storage;
399
- pendingNotifications = [];
400
- constructor(storage = defaultStorage) {
401
- this.storage = storage;
402
- }
403
- getAchievementsForGame(gameId) {
404
- const meta = ALL_GAMES_METADATA[gameId];
405
- if (!meta) return [];
406
- const profile = this.storage.getProfile();
407
- const unlockedIds = profile.unlockedAchievements[gameId] || [];
408
- return meta.achievements.map((ach) => ({
409
- achievement: ach,
410
- unlocked: unlockedIds.includes(ach.id)
411
- }));
412
- }
413
- unlock(gameId, achievementId) {
414
- const meta = ALL_GAMES_METADATA[gameId];
415
- if (!meta) return false;
416
- const ach = meta.achievements.find((a) => a.id === achievementId);
417
- if (!ach) return false;
418
- const newlyUnlocked = this.storage.unlockAchievement(gameId, achievementId);
419
- if (newlyUnlocked) {
420
- this.pendingNotifications.push({
421
- gameId,
422
- achievement: ach,
423
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
424
- });
425
- return true;
426
- }
427
- return false;
428
- }
429
- popNotifications() {
430
- const list = [...this.pendingNotifications];
431
- this.pendingNotifications = [];
432
- return list;
433
- }
434
- getTotalStats() {
435
- let totalCount = 0;
436
- let unlockedCount = 0;
437
- const profile = this.storage.getProfile();
438
- for (const [gameId, meta] of Object.entries(ALL_GAMES_METADATA)) {
439
- totalCount += meta.achievements.length;
440
- const unlocked = profile.unlockedAchievements[gameId] || [];
441
- unlockedCount += unlocked.length;
442
- }
443
- const percentage = totalCount > 0 ? Math.round(unlockedCount / totalCount * 100) : 0;
444
- return { unlockedCount, totalCount, percentage };
445
- }
446
- };
447
- var defaultAchievements = new AchievementManager();
448
-
449
- // src/core/theme.ts
450
- import chalk from "chalk";
451
- var THEMES = {
452
- default: {
453
- name: "default",
454
- displayName: "Cyberpunk Cyan/Magenta",
455
- primary: (t) => chalk.cyanBright(t),
456
- secondary: (t) => chalk.magentaBright(t),
457
- accent: (t) => chalk.yellowBright(t),
458
- muted: (t) => chalk.gray(t),
459
- success: (t) => chalk.greenBright(t),
460
- warning: (t) => chalk.yellow(t),
461
- error: (t) => chalk.redBright(t),
462
- highlight: (t) => chalk.bold.cyan(t),
463
- border: (t) => chalk.cyan(t)
464
- },
465
- "retro-green": {
466
- name: "retro-green",
467
- displayName: "CRT Phosphor Green",
468
- primary: (t) => chalk.greenBright(t),
469
- secondary: (t) => chalk.green(t),
470
- accent: (t) => chalk.whiteBright(t),
471
- muted: (t) => chalk.hex("#1f5f1f")(t),
472
- success: (t) => chalk.greenBright(t),
473
- warning: (t) => chalk.hex("#7fff00")(t),
474
- error: (t) => chalk.hex("#33ff33").underline(t),
475
- highlight: (t) => chalk.bold.greenBright(t),
476
- border: (t) => chalk.green(t)
477
- },
478
- neon: {
479
- name: "neon",
480
- displayName: "Electric Neon Violet",
481
- primary: (t) => chalk.hex("#b829ea")(t),
482
- secondary: (t) => chalk.hex("#00ffff")(t),
483
- accent: (t) => chalk.hex("#ff007f")(t),
484
- muted: (t) => chalk.hex("#555577")(t),
485
- success: (t) => chalk.hex("#39ff14")(t),
486
- warning: (t) => chalk.hex("#ffe600")(t),
487
- error: (t) => chalk.hex("#ff073a")(t),
488
- highlight: (t) => chalk.bold.hex("#00ffff")(t),
489
- border: (t) => chalk.hex("#b829ea")(t)
490
- },
491
- minimal: {
492
- name: "minimal",
493
- displayName: "Monochrome Minimalist",
494
- primary: (t) => chalk.whiteBright(t),
495
- secondary: (t) => chalk.gray(t),
496
- accent: (t) => chalk.white(t),
497
- muted: (t) => chalk.hex("#444444")(t),
498
- success: (t) => chalk.whiteBright(t),
499
- warning: (t) => chalk.italic(t),
500
- error: (t) => chalk.underline(t),
501
- highlight: (t) => chalk.bold.white(t),
502
- border: (t) => chalk.gray(t)
503
- },
504
- "high-contrast": {
505
- name: "high-contrast",
506
- displayName: "Accessibility High Contrast",
507
- primary: (t) => chalk.yellowBright(t),
508
- secondary: (t) => chalk.cyanBright(t),
509
- accent: (t) => chalk.whiteBright(t),
510
- muted: (t) => chalk.white(t),
511
- success: (t) => chalk.bold.greenBright(t),
512
- warning: (t) => chalk.bold.yellowBright(t),
513
- error: (t) => chalk.bold.redBright(t),
514
- highlight: (t) => chalk.bold.underline.yellowBright(t),
515
- border: (t) => chalk.yellowBright(t)
516
- }
517
- };
518
- function getTheme(themeName = "default") {
519
- return THEMES[themeName] || THEMES.default;
520
- }
521
-
522
- // src/core/renderer.ts
523
- var TerminalRenderer = class {
524
- inAltBuffer = false;
525
- currentTheme = getTheme("default");
526
- setTheme(themeName) {
527
- this.currentTheme = getTheme(themeName);
528
- }
529
- getTheme() {
530
- return this.currentTheme;
531
- }
532
- previousLineCount = 0;
533
- enterScreen() {
534
- if (!this.inAltBuffer && process.stdout.isTTY) {
535
- process.stdout.write("\x1B[?1049h\x1B[?25l\x1B[2J\x1B[H");
536
- this.inAltBuffer = true;
537
- this.previousLineCount = 0;
538
- }
539
- }
540
- exitScreen() {
541
- if (this.inAltBuffer && process.stdout.isTTY) {
542
- process.stdout.write("\x1B[?25h\x1B[?1049l");
543
- this.inAltBuffer = false;
544
- }
545
- }
546
- /**
547
- * Safe frame render with zero flickering.
548
- * Repaints lines in place with cursor hidden and atomic buffer write,
549
- * avoiding full-screen blanking clears.
550
- */
551
- renderFrame(content) {
552
- if (!process.stdout.isTTY) return;
553
- const lines = content.split("\n");
554
- let output = "\x1B[?25l\x1B[H";
555
- for (let i = 0; i < lines.length; i++) {
556
- output += `${lines[i]}\x1B[K
557
- `;
558
- }
559
- if (lines.length < this.previousLineCount) {
560
- output += "\x1B[J";
561
- }
562
- this.previousLineCount = lines.length;
563
- process.stdout.write(output);
564
- }
565
- /**
566
- * Retained for compatibility. Forwards to flicker-free renderFrame.
567
- */
568
- draw(content) {
569
- this.renderFrame(content);
570
- }
571
- /**
572
- * Intentionally no-op during active game loop to prevent blank-frame visual strobing.
573
- */
574
- clear() {
575
- }
576
- /**
577
- * Explicit full screen wipe when transitioning between major modes.
578
- */
579
- forceClear() {
580
- if (process.stdout.isTTY) {
581
- process.stdout.write("\x1B[2J\x1B[H");
582
- this.previousLineCount = 0;
583
- }
584
- }
585
- isWindowAdequate() {
586
- const width = process.stdout.columns || 80;
587
- const height = process.stdout.rows || 24;
588
- return {
589
- adequate: width >= MIN_TERMINAL_COLUMNS && height >= MIN_TERMINAL_ROWS,
590
- width,
591
- height
592
- };
593
- }
594
- renderSizeWarning() {
595
- const { width, height } = this.isWindowAdequate();
596
- const t = this.currentTheme;
597
- return `
598
- ${t.warning("\u26A0\uFE0F TERMINAL WINDOW TOO COMPACT")}
599
-
600
- Current: ${t.error(`${width} x ${height}`)}
601
- Required: ${t.success(`${MIN_TERMINAL_COLUMNS} x ${MIN_TERMINAL_ROWS}`)}
602
-
603
- ${t.muted("Please enlarge your terminal window or reduce zoom.")}
604
- `;
605
- }
606
- createBox(lines, width = 76, title = "") {
607
- const t = this.currentTheme;
608
- const topBarLen = Math.max(0, width - 4 - (title ? title.length + 2 : 0));
609
- const titleSection = title ? ` ${t.primary(title)} ` : "";
610
- const top = t.border(`\u250C\u2500${titleSection}${"\u2500".repeat(topBarLen)}\u2510`);
611
- const bottom = t.border(`\u2514${"\u2500".repeat(width - 2)}\u2518`);
612
- const middle = lines.map((line) => {
613
- const cleanLen = line.replace(/\x1b\[[0-9;]*m/g, "").length;
614
- const padLen = Math.max(0, width - 4 - cleanLen);
615
- return `${t.border("\u2502")} ${line}${" ".repeat(padLen)}${t.border("\u2502")}`;
616
- });
617
- return [top, ...middle, bottom].join("\n");
618
- }
619
- renderHeader(options) {
620
- const t = this.currentTheme;
621
- const cols = Math.min(process.stdout.columns || 80, 80);
622
- const leftPart = `${t.highlight(options.title)} ${options.category ? t.muted(`[${options.category.toUpperCase()}]`) : ""}`;
623
- const diffPart = options.difficulty ? t.secondary(`DIFF: ${options.difficulty.toUpperCase()}`) : "";
624
- const scorePart = options.score !== void 0 ? t.primary(`SCORE: ${options.score}`) : "";
625
- const highPart = options.highScore !== void 0 ? t.accent(`BEST: ${options.highScore}`) : "";
626
- const stats = [diffPart, scorePart, highPart].filter(Boolean).join(" \u2502 ");
627
- const cleanLeft = leftPart.replace(/\x1b\[[0-9;]*m/g, "").length;
628
- const cleanRight = stats.replace(/\x1b\[[0-9;]*m/g, "").length;
629
- const spaceCount = Math.max(2, cols - cleanLeft - cleanRight - 2);
630
- return `
631
- ${leftPart}${" ".repeat(spaceCount)}${stats}
632
- ${t.border("\u2500".repeat(cols - 4))}
633
- `;
634
- }
635
- renderFooter(instructions) {
636
- const t = this.currentTheme;
637
- const cols = Math.min(process.stdout.columns || 80, 80);
638
- return `
639
- ${t.border("\u2500".repeat(cols - 4))}
640
- ${t.muted(instructions)}
641
- `;
642
- }
643
- };
644
- var defaultRenderer = new TerminalRenderer();
645
-
646
- // src/core/input.ts
647
- import readline from "readline";
648
- var TerminalInputHandler = class {
649
- isListening = false;
650
- keyPressCallback = null;
651
- onExitCallback = null;
652
- constructor() {
653
- this.handleKeypress = this.handleKeypress.bind(this);
654
- }
655
- start(onKey, onExit) {
656
- if (this.isListening) return;
657
- this.keyPressCallback = onKey;
658
- this.onExitCallback = onExit || null;
659
- if (process.stdin.isTTY) {
660
- process.stdin.setRawMode(true);
661
- process.stdin.resume();
662
- readline.emitKeypressEvents(process.stdin);
663
- process.stdin.on("keypress", this.handleKeypress);
664
- this.isListening = true;
665
- }
666
- }
667
- stop() {
668
- if (!this.isListening) return;
669
- if (process.stdin.isTTY) {
670
- process.stdin.removeListener("keypress", this.handleKeypress);
671
- process.stdin.setRawMode(false);
672
- process.stdin.pause();
673
- }
674
- this.isListening = false;
675
- this.keyPressCallback = null;
676
- this.onExitCallback = null;
677
- }
678
- handleKeypress(_ch, key) {
679
- if (!key) return;
680
- if (key.ctrl && key.name === "c") {
681
- this.stop();
682
- if (this.onExitCallback) {
683
- this.onExitCallback();
684
- } else {
685
- process.stdout.write("\x1B[?25h\x1B[0m\n");
686
- process.exit(0);
687
- }
688
- return;
689
- }
690
- if (this.keyPressCallback) {
691
- this.keyPressCallback({
692
- name: key.name || "",
693
- ctrl: !!key.ctrl,
694
- shift: !!key.shift,
695
- meta: !!key.meta,
696
- sequence: key.sequence || ""
697
- });
698
- }
699
- }
700
- };
701
-
702
- // src/core/engine.ts
703
- var TerminullEngine = class {
704
- gamesRegistry = /* @__PURE__ */ new Map();
705
- activeGame = null;
706
- storage;
707
- achievements;
708
- renderer;
709
- input;
710
- isPaused = false;
711
- pauseMenuIndex = 0;
712
- currentDifficulty = "normal";
713
- sessionStartTime = 0;
714
- onQuitToMenuCallback;
715
- constructor(storage = defaultStorage, achievements = defaultAchievements, renderer = defaultRenderer) {
716
- this.storage = storage;
717
- this.achievements = achievements;
718
- this.renderer = renderer;
719
- this.input = new TerminalInputHandler();
720
- if (process.stdout.on) {
721
- process.stdout.on("resize", () => {
722
- if (this.activeGame && !this.isPaused) {
723
- }
724
- });
725
- }
726
- }
727
- registerGame(id, factory) {
728
- this.gamesRegistry.set(id, factory);
729
- }
730
- getRegisteredGames() {
731
- return Array.from(this.gamesRegistry.keys());
732
- }
733
- launchGame(id, difficulty = "normal", events) {
734
- const factory = this.gamesRegistry.get(id);
735
- if (!factory) {
736
- console.error(`Error: Game '${id}' is not yet installed or registered.`);
737
- return;
738
- }
739
- this.onQuitToMenuCallback = events?.onQuitToMenu;
740
- this.currentDifficulty = difficulty;
741
- this.activeGame = factory();
742
- const profile = this.storage.getProfile();
743
- const themeName = profile.settings.theme;
744
- this.renderer.setTheme(themeName);
745
- this.renderer.enterScreen();
746
- this.isPaused = false;
747
- this.sessionStartTime = Date.now();
748
- this.activeGame.init({
749
- difficulty,
750
- theme: themeName,
751
- soundEnabled: profile.settings.soundEnabled,
752
- reducedMotion: profile.settings.reducedMotion,
753
- onExit: () => {
754
- this.quitGame();
755
- },
756
- onScoreUpdate: (score) => {
757
- this.storage.recordScore(id, score);
758
- },
759
- onGameOver: (finalScore) => {
760
- this.storage.recordScore(id, finalScore);
761
- const elapsedSec = Math.round((Date.now() - this.sessionStartTime) / 1e3);
762
- this.storage.addPlayTime(id, elapsedSec);
763
- },
764
- onAchievementUnlock: (achId) => {
765
- this.achievements.unlock(id, achId);
766
- }
767
- });
768
- this.activeGame.start();
769
- }
770
- togglePause() {
771
- if (!this.activeGame) return;
772
- if (!this.isPaused) {
773
- this.isPaused = true;
774
- this.activeGame.pause();
775
- this.pauseMenuIndex = 0;
776
- this.renderPauseMenu();
777
- } else {
778
- this.isPaused = false;
779
- this.activeGame.resume();
780
- }
781
- }
782
- renderPauseMenu() {
783
- const t = this.renderer.getTheme();
784
- const items = [
785
- "Resume Game",
786
- "Restart Round",
787
- `Difficulty: [ ${this.currentDifficulty.toUpperCase()} ]`,
788
- "Quit to Arcade Menu"
789
- ];
790
- const lines = [
791
- "",
792
- t.highlight("\u2550\u2550\u2550 PAUSE SUBROUTINE \u2550\u2550\u2550"),
793
- "",
794
- ...items.map((item, idx) => {
795
- if (idx === this.pauseMenuIndex) {
796
- return t.primary(` \u25B6 ${t.highlight(item)}`);
797
- }
798
- return t.muted(` ${item}`);
799
- }),
800
- "",
801
- 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"),
802
- t.muted("Use Up/Down to navigate, Enter to select, P to resume")
803
- ];
804
- const box = this.renderer.createBox(lines, 60, "SYSTEM HALT");
805
- this.renderer.draw(`
806
-
807
- ${box}`);
808
- }
809
- handlePauseInput(keyName) {
810
- if (keyName === "up" || keyName === "w") {
811
- this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 4) % 4;
812
- this.renderPauseMenu();
813
- } else if (keyName === "down" || keyName === "s") {
814
- this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 4;
815
- this.renderPauseMenu();
816
- } else if (keyName === "return" || keyName === "space") {
817
- if (this.pauseMenuIndex === 0) {
818
- this.togglePause();
819
- } else if (this.pauseMenuIndex === 1) {
820
- this.isPaused = false;
821
- this.activeGame?.restart();
822
- } else if (this.pauseMenuIndex === 2) {
823
- const diffs = ["easy", "normal", "hard", "insane"];
824
- const currIdx = diffs.indexOf(this.currentDifficulty);
825
- this.currentDifficulty = diffs[(currIdx + 1) % diffs.length];
826
- this.renderPauseMenu();
827
- } else if (this.pauseMenuIndex === 3) {
828
- this.quitGame();
829
- }
830
- } else if (keyName === "p" || keyName === "escape") {
831
- this.togglePause();
832
- }
833
- }
834
- quitGame() {
835
- if (this.activeGame) {
836
- const elapsedSec = Math.round((Date.now() - this.sessionStartTime) / 1e3);
837
- this.storage.addPlayTime(this.activeGame.id, elapsedSec);
838
- this.activeGame.destroy();
839
- this.activeGame = null;
840
- }
841
- this.isPaused = false;
842
- this.renderer.exitScreen();
843
- if (this.onQuitToMenuCallback) {
844
- this.onQuitToMenuCallback();
845
- } else {
846
- process.exit(0);
847
- }
848
- }
849
- getActiveGame() {
850
- return this.activeGame;
851
- }
852
- isGamePaused() {
853
- return this.isPaused;
854
- }
855
- };
856
- var defaultEngine = new TerminullEngine();
857
-
858
- // src/shared/utils.ts
859
- function checkTerminalDimensions() {
860
- const cols = process.stdout.columns || 80;
861
- const rows = process.stdout.rows || 24;
862
- return {
863
- adequate: cols >= MIN_TERMINAL_COLUMNS && rows >= MIN_TERMINAL_ROWS,
864
- cols,
865
- rows,
866
- minCols: MIN_TERMINAL_COLUMNS,
867
- minRows: MIN_TERMINAL_ROWS
868
- };
869
- }
870
- function playTerminalBell(enabled = true) {
871
- if (enabled && process.stdout.isTTY) {
872
- process.stdout.write("\x07");
873
- }
874
- }
875
- function formatTime(seconds) {
876
- const mins = Math.floor(seconds / 60);
877
- const secs = Math.floor(seconds % 60);
878
- return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
879
- }
880
- function clamp(val, min, max) {
881
- return Math.max(min, Math.min(max, val));
882
- }
883
- function padCenter(str, width) {
884
- if (str.length >= width) return str.slice(0, width);
885
- const left = Math.floor((width - str.length) / 2);
886
- const right = width - str.length - left;
887
- return " ".repeat(left) + str + " ".repeat(right);
888
- }
889
-
890
- // src/core/menu.ts
891
- var ArcadeMenu = class {
892
- storage;
893
- achievements;
894
- renderer;
895
- input;
896
- selectedIndex = 0;
897
- searchQuery = "";
898
- isSearching = false;
899
- currentTab = "arcade";
900
- selectedDifficulty = "normal";
901
- onSelectCallback = null;
902
- constructor(storage = defaultStorage, achievements = defaultAchievements, renderer = defaultRenderer) {
903
- this.storage = storage;
904
- this.achievements = achievements;
905
- this.renderer = renderer;
906
- this.input = new TerminalInputHandler();
907
- }
908
- open(onSelect) {
909
- this.onSelectCallback = onSelect;
910
- const profile = this.storage.getProfile();
911
- this.renderer.setTheme(profile.settings.theme);
912
- this.renderer.enterScreen();
913
- this.render();
914
- this.input.start(
915
- (key) => this.handleInput(key),
916
- () => {
917
- this.renderer.exitScreen();
918
- process.exit(0);
919
- }
920
- );
921
- }
922
- close() {
923
- this.input.stop();
924
- this.renderer.exitScreen();
925
- }
926
- getFilteredGames() {
927
- const all = Object.values(ALL_GAMES_METADATA);
928
- if (!this.searchQuery.trim()) return all;
929
- const q = this.searchQuery.toLowerCase();
930
- return all.filter(
931
- (g) => g.name.toLowerCase().includes(q) || g.category.toLowerCase().includes(q) || g.id.toLowerCase().includes(q) || g.description.toLowerCase().includes(q)
932
- );
933
- }
934
- handleInput(key) {
935
- const filtered = this.getFilteredGames();
936
- if (this.isSearching) {
937
- if (key.name === "return" || key.name === "escape") {
938
- this.isSearching = false;
939
- } else if (key.name === "backspace") {
940
- this.searchQuery = this.searchQuery.slice(0, -1);
941
- this.selectedIndex = 0;
942
- } else if (key.sequence && key.sequence.length === 1 && !key.name) {
943
- this.searchQuery += key.sequence;
944
- this.selectedIndex = 0;
945
- }
946
- this.render();
947
- return;
948
- }
949
- if (key.name === "tab") {
950
- const tabs = ["arcade", "stats", "settings"];
951
- const nextIdx = (tabs.indexOf(this.currentTab) + 1) % tabs.length;
952
- this.currentTab = tabs[nextIdx];
953
- this.render();
954
- return;
955
- }
956
- if (this.currentTab === "arcade") {
957
- if (key.name === "up" || key.name === "k") {
958
- this.selectedIndex = (this.selectedIndex - 1 + filtered.length) % Math.max(1, filtered.length);
959
- this.render();
960
- } else if (key.name === "down" || key.name === "j") {
961
- this.selectedIndex = (this.selectedIndex + 1) % Math.max(1, filtered.length);
962
- this.render();
963
- } else if (key.name === "d") {
964
- const diffs = ["easy", "normal", "hard", "insane"];
965
- const curr = diffs.indexOf(this.selectedDifficulty);
966
- this.selectedDifficulty = diffs[(curr + 1) % diffs.length];
967
- this.render();
968
- } else if (key.name === "slash" || key.sequence === "/") {
969
- this.isSearching = true;
970
- this.render();
971
- } else if (key.name === "return" || key.name === "space") {
972
- const game = filtered[this.selectedIndex];
973
- if (game && this.onSelectCallback) {
974
- this.input.stop();
975
- this.onSelectCallback({
976
- action: "play",
977
- gameId: game.id,
978
- difficulty: this.selectedDifficulty
979
- });
980
- }
981
- } else if (key.name === "q") {
982
- this.close();
983
- if (this.onSelectCallback) {
984
- this.onSelectCallback({ action: "quit" });
985
- }
986
- }
987
- } else if (this.currentTab === "settings") {
988
- if (key.name === "t") {
989
- const themes = ["default", "retro-green", "neon", "minimal", "high-contrast"];
990
- const profile = this.storage.getProfile();
991
- const currIdx = themes.indexOf(profile.settings.theme);
992
- const nextTheme = themes[(currIdx + 1) % themes.length];
993
- this.storage.updateSettings({ theme: nextTheme });
994
- this.renderer.setTheme(nextTheme);
995
- this.render();
996
- } else if (key.name === "b") {
997
- const profile = this.storage.getProfile();
998
- this.storage.updateSettings({ soundEnabled: !profile.settings.soundEnabled });
999
- this.render();
1000
- } else if (key.name === "m") {
1001
- const profile = this.storage.getProfile();
1002
- this.storage.updateSettings({ reducedMotion: !profile.settings.reducedMotion });
1003
- this.render();
1004
- } else if (key.name === "escape") {
1005
- this.currentTab = "arcade";
1006
- this.render();
1007
- }
1008
- } else if (this.currentTab === "stats") {
1009
- if (key.name === "escape" || key.name === "return") {
1010
- this.currentTab = "arcade";
1011
- this.render();
1012
- }
1013
- }
1014
- }
1015
- render() {
1016
- const t = this.renderer.getTheme();
1017
- const { width, height } = this.renderer.isWindowAdequate();
1018
- if (width < 80 || height < 24) {
1019
- this.renderer.clear();
1020
- this.renderer.draw(this.renderer.renderSizeWarning());
1021
- return;
1022
- }
1023
- let body = "";
1024
- if (this.currentTab === "arcade") {
1025
- body = this.renderArcadeTab();
1026
- } else if (this.currentTab === "stats") {
1027
- body = this.renderStatsTab();
1028
- } else if (this.currentTab === "settings") {
1029
- body = this.renderSettingsTab();
1030
- }
1031
- this.renderer.clear();
1032
- this.renderer.draw(body);
1033
- }
1034
- renderArcadeTab() {
1035
- const t = this.renderer.getTheme();
1036
- const filtered = this.getFilteredGames();
1037
- const activeGame = filtered[this.selectedIndex];
1038
- const profile = this.storage.getProfile();
1039
- const banner = [
1040
- t.highlight(` \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557 `),
1041
- t.highlight(` \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1042
- t.primary(` \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1043
- t.secondary(` \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1044
- t.muted(` \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557`),
1045
- t.muted(` \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D`),
1046
- ` ${t.accent(APP_TAGLINE)} \u2502 ${t.muted("Tab: Switch Views \u2502 /: Search \u2502 Q: Quit")}`,
1047
- ` ${t.border("\u2500".repeat(74))}`
1048
- ].join("\n");
1049
- const tabs = ` ${t.highlight("[ 1. ARCADE ]")} ${t.muted("[ 2. STATS (Tab) ]")} ${t.muted("[ 3. SETTINGS (Tab) ]")}
1050
- `;
1051
- const searchBar = this.isSearching ? ` ${t.warning("SEARCH >")} ${this.searchQuery}\u2588
1052
- ` : this.searchQuery ? ` ${t.muted("Filtered by:")} "${this.searchQuery}" (Press / to edit)
1053
- ` : "";
1054
- const listLines = [];
1055
- const maxVisible = 10;
1056
- const startIndex = Math.max(0, Math.min(this.selectedIndex - 4, filtered.length - maxVisible));
1057
- const visibleGames = filtered.slice(startIndex, startIndex + maxVisible);
1058
- for (let i = 0; i < visibleGames.length; i++) {
1059
- const g = visibleGames[i];
1060
- const realIndex = startIndex + i;
1061
- const isSelected = realIndex === this.selectedIndex;
1062
- const high = profile.highScores[g.id] || 0;
1063
- const highStr = high > 0 ? t.accent(`\u2605 ${high}`) : t.muted("\u2014");
1064
- if (isSelected) {
1065
- listLines.push(t.primary(` \u25B6 ${t.highlight(g.name.padEnd(16))} ${t.secondary(`[${g.category}]`)} ${highStr}`));
1066
- } else {
1067
- listLines.push(t.muted(` ${g.name.padEnd(16)} [${g.category}] ${highStr}`));
1068
- }
1069
- }
1070
- const detailLines = [];
1071
- if (activeGame) {
1072
- const high = profile.highScores[activeGame.id] || 0;
1073
- const plays = profile.playCounts[activeGame.id] || 0;
1074
- const timeSec = profile.totalTimePlayedSec[activeGame.id] || 0;
1075
- const achs = this.achievements.getAchievementsForGame(activeGame.id);
1076
- const unlockedAchs = achs.filter((a) => a.unlocked).length;
1077
- detailLines.push(t.highlight(activeGame.name.toUpperCase()));
1078
- detailLines.push(t.secondary(activeGame.tagline));
1079
- detailLines.push("");
1080
- detailLines.push(activeGame.description);
1081
- detailLines.push("");
1082
- detailLines.push(`${t.muted("Personal Best:")} ${t.accent(high.toString())} ${t.muted("Runs:")} ${plays} ${t.muted("Time:")} ${formatTime(timeSec)}`);
1083
- detailLines.push(`${t.muted("Difficulty:")} ${t.secondary(this.selectedDifficulty.toUpperCase())} ${t.muted("(Press D to cycle)")}`);
1084
- detailLines.push(`${t.muted("Achievements:")} ${unlockedAchs}/${achs.length} unlocked`);
1085
- detailLines.push("");
1086
- detailLines.push(t.muted("Primary Controls:"));
1087
- for (const ctrl of activeGame.controls.slice(0, 3)) {
1088
- detailLines.push(` ${t.primary(ctrl.key.padEnd(14))} ${ctrl.action}`);
1089
- }
1090
- }
1091
- const detailBox = this.renderer.createBox(detailLines, 46, "TELEMETRY");
1092
- const detailBoxLines = detailBox.split("\n");
1093
- const combinedLines = [];
1094
- const maxRows = Math.max(listLines.length, detailBoxLines.length);
1095
- for (let r = 0; r < maxRows; r++) {
1096
- const left = (listLines[r] || "").padEnd(32);
1097
- const right = detailBoxLines[r] || "";
1098
- combinedLines.push(` ${left} ${right}`);
1099
- }
1100
- const footer = [
1101
- ` ${t.border("\u2500".repeat(74))}`,
1102
- ` ${t.primary("Enter/Space")}: Launch Game \u2502 ${t.secondary("Up/Down")}: Select \u2502 ${t.accent("D")}: Difficulty \u2502 ${t.muted("Q")}: Exit`
1103
- ].join("\n");
1104
- return `
1105
- ${banner}
1106
- ${tabs}
1107
- ${searchBar}
1108
- ${combinedLines.join("\n")}
1109
-
1110
- ${footer}
1111
- `;
1112
- }
1113
- renderStatsTab() {
1114
- const t = this.renderer.getTheme();
1115
- const profile = this.storage.getProfile();
1116
- const { unlockedCount, totalCount, percentage } = this.achievements.getTotalStats();
1117
- let totalScore = 0;
1118
- let totalPlays = 0;
1119
- let totalTime = 0;
1120
- for (const id of Object.keys(ALL_GAMES_METADATA)) {
1121
- totalScore += profile.highScores[id] || 0;
1122
- totalPlays += profile.playCounts[id] || 0;
1123
- totalTime += profile.totalTimePlayedSec[id] || 0;
1124
- }
1125
- const statsLines = [
1126
- "",
1127
- t.highlight("ARCADE PILOT DOSSIER"),
1128
- "",
1129
- `${t.muted("Total High Score Cumulative:")} ${t.accent(totalScore.toLocaleString())}`,
1130
- `${t.muted("Total Play Sessions:")} ${t.primary(totalPlays.toString())}`,
1131
- `${t.muted("Total Time Beyond Prompt:")} ${t.secondary(formatTime(totalTime))}`,
1132
- `${t.muted("Global Achievements:")} ${t.success(`${unlockedCount} / ${totalCount} (${percentage}%)`)}`,
1133
- "",
1134
- t.highlight("PER-GAME ARCHIVE:"),
1135
- ...Object.values(ALL_GAMES_METADATA).map((g) => {
1136
- const score = profile.highScores[g.id] || 0;
1137
- const plays = profile.playCounts[g.id] || 0;
1138
- return ` ${g.name.padEnd(18)} Score: ${score.toString().padEnd(6)} Runs: ${plays.toString().padEnd(4)}`;
1139
- }),
1140
- "",
1141
- 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"),
1142
- t.muted("Press Tab to switch tabs, Esc/Enter to return to Arcade")
1143
- ];
1144
- return `
1145
-
1146
- ${this.renderer.createBox(statsLines, 74, "CAREER TELEMETRY")}
1147
- `;
1148
- }
1149
- renderSettingsTab() {
1150
- const t = this.renderer.getTheme();
1151
- const profile = this.storage.getProfile();
1152
- const lines = [
1153
- "",
1154
- t.highlight("TERMINULL SYSTEM CONFIGURATION"),
1155
- "",
1156
- ` ${t.primary("[T] Theme:")} ${t.highlight(profile.settings.theme.toUpperCase())} ${t.muted("(Default, Retro-Green, Neon, Minimal, High-Contrast)")}`,
1157
- ` ${t.secondary("[B] Bell Sound:")} ${profile.settings.soundEnabled ? t.success("ENABLED") : t.muted("MUTED")}`,
1158
- ` ${t.accent("[M] Reduced Motion:")} ${profile.settings.reducedMotion ? t.warning("ON") : t.muted("OFF")}`,
1159
- "",
1160
- 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"),
1161
- t.muted("Config stored at: ~/.config/terminull/profile.json"),
1162
- t.muted("Press T to cycle theme, B to toggle sound, M for motion, Tab/Esc to exit")
1163
- ];
1164
- return `
1165
-
1166
- ${this.renderer.createBox(lines, 74, "PREFERENCES")}
1167
- `;
1168
- }
1169
- };
1170
-
1171
- // src/core/rng.ts
1172
- var DeterministicRNG = class {
1173
- state;
1174
- initialSeed;
1175
- constructor(seed = Date.now()) {
1176
- this.initialSeed = seed;
1177
- this.state = seed >>> 0;
1178
- }
1179
- getSeed() {
1180
- return this.initialSeed;
1181
- }
1182
- reset() {
1183
- this.state = this.initialSeed >>> 0;
1184
- }
1185
- /**
1186
- * Generates a floating point number in [0, 1).
1187
- */
1188
- next() {
1189
- let t = this.state += 1831565813;
1190
- t = Math.imul(t ^ t >>> 15, t | 1);
1191
- t ^= t + Math.imul(t ^ t >>> 7, t | 61);
1192
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
1193
- }
1194
- /**
1195
- * Returns an integer within [min, max] inclusive.
1196
- */
1197
- nextInt(min, max) {
1198
- if (min > max) [min, max] = [max, min];
1199
- return Math.floor(this.next() * (max - min + 1)) + min;
1200
- }
1201
- /**
1202
- * Returns a random element from an array.
1203
- */
1204
- pick(items) {
1205
- if (items.length === 0) {
1206
- throw new Error("Cannot pick from empty array");
1207
- }
1208
- const index = Math.floor(this.next() * items.length);
1209
- return items[index];
1210
- }
1211
- /**
1212
- * Shuffles an array in place using Fisher-Yates.
1213
- */
1214
- shuffle(array) {
1215
- const copy = [...array];
1216
- for (let i = copy.length - 1; i > 0; i--) {
1217
- const j = Math.floor(this.next() * (i + 1));
1218
- const temp = copy[i];
1219
- copy[i] = copy[j];
1220
- copy[j] = temp;
1221
- }
1222
- return copy;
1223
- }
1224
- /**
1225
- * Generates a deterministic daily seed integer based on YYYY-MM-DD.
1226
- */
1227
- static getDailySeed(date = /* @__PURE__ */ new Date()) {
1228
- const y = date.getUTCFullYear();
1229
- const m = date.getUTCMonth() + 1;
1230
- const d = date.getUTCDate();
1231
- return y * 1e4 + m * 100 + d >>> 0;
1232
- }
1233
- };
1234
-
1235
- // src/games/neon-circuit/index.ts
1236
- var NeonCircuitGame = class {
1237
- id = "neon-circuit";
1238
- metadata = ALL_GAMES_METADATA["neon-circuit"];
1239
- config = null;
1240
- renderer = defaultRenderer;
1241
- input = new TerminalInputHandler();
1242
- rng = new DeterministicRNG();
1243
- state = {
1244
- grid: [],
1245
- width: 5,
1246
- height: 5,
1247
- cursorX: 0,
1248
- cursorY: 0,
1249
- movesRemaining: 25,
1250
- maxMoves: 25,
1251
- score: 0,
1252
- level: 1,
1253
- targetsRemaining: 1,
1254
- totalTargets: 1,
1255
- isWon: false,
1256
- isGameOver: false
1257
- };
1258
- isPaused = false;
1259
- pauseMenuIndex = 0;
1260
- showTutorial = true;
1261
- init(config) {
1262
- this.config = config;
1263
- this.renderer.setTheme(config.theme);
1264
- this.rng = new DeterministicRNG(config.seed || Date.now());
1265
- if (config.skipTutorial !== void 0) {
1266
- this.showTutorial = !config.skipTutorial;
1267
- }
1268
- this.setupLevel(1, config.difficulty);
1269
- }
1270
- start() {
1271
- this.isPaused = false;
1272
- this.render();
1273
- this.input.start(
1274
- (key) => this.handleInput(key),
1275
- () => {
1276
- this.destroy();
1277
- process.exit(0);
1278
- }
1279
- );
1280
- }
1281
- pause() {
1282
- this.isPaused = true;
1283
- }
1284
- resume() {
1285
- this.isPaused = false;
1286
- this.render();
1287
- }
1288
- restart() {
1289
- if (this.config) {
1290
- this.state.score = 0;
1291
- this.setupLevel(1, this.config.difficulty);
1292
- this.render();
1293
- }
1294
- }
1295
- saveState() {
1296
- return {
1297
- state: this.state,
1298
- showTutorial: this.showTutorial
1299
- };
1300
- }
1301
- loadState(saved) {
1302
- if (saved["state"]) {
1303
- this.state = saved["state"];
1304
- }
1305
- if (saved["showTutorial"] !== void 0) {
1306
- this.showTutorial = !!saved["showTutorial"];
1307
- }
1308
- this.updatePowerFlow();
1309
- }
1310
- destroy() {
1311
- this.input.stop();
1312
- }
1313
- setupLevel(level, difficulty) {
1314
- let size = 5;
1315
- let moves = 20;
1316
- switch (difficulty) {
1317
- case "easy":
1318
- size = 4;
1319
- moves = 25;
1320
- break;
1321
- case "normal":
1322
- size = 5;
1323
- moves = 22;
1324
- break;
1325
- case "hard":
1326
- size = 6;
1327
- moves = 20;
1328
- break;
1329
- case "insane":
1330
- size = 7;
1331
- moves = 18;
1332
- break;
1333
- }
1334
- this.state.width = size;
1335
- this.state.height = size;
1336
- this.state.level = level;
1337
- this.state.maxMoves = moves;
1338
- this.state.movesRemaining = moves;
1339
- this.state.cursorX = 0;
1340
- this.state.cursorY = 0;
1341
- this.state.isWon = false;
1342
- this.state.isGameOver = false;
1343
- const grid = [];
1344
- for (let y = 0; y < size; y++) {
1345
- const row = [];
1346
- for (let x = 0; x < size; x++) {
1347
- row.push(this.createRandomTile(x, y, size, difficulty));
1348
- }
1349
- row.push();
1350
- grid.push(row);
1351
- }
1352
- grid[0][0] = {
1353
- type: "source",
1354
- rotation: 0,
1355
- baseConnections: [false, true, true, false],
1356
- currentConnections: [false, true, true, false],
1357
- isPowered: true,
1358
- isFixed: true
1359
- };
1360
- grid[size - 1][size - 1] = {
1361
- type: "target",
1362
- rotation: 0,
1363
- baseConnections: [true, false, false, true],
1364
- currentConnections: [true, false, false, true],
1365
- isPowered: false,
1366
- isFixed: true
1367
- };
1368
- if (difficulty === "insane") {
1369
- grid[0][size - 1] = {
1370
- type: "target",
1371
- rotation: 0,
1372
- baseConnections: [false, false, true, true],
1373
- currentConnections: [false, false, true, true],
1374
- isPowered: false,
1375
- isFixed: true
1376
- };
1377
- this.state.totalTargets = 2;
1378
- this.state.targetsRemaining = 2;
1379
- } else {
1380
- this.state.totalTargets = 1;
1381
- this.state.targetsRemaining = 1;
1382
- }
1383
- this.state.grid = grid;
1384
- this.updatePowerFlow();
1385
- }
1386
- createRandomTile(x, y, size, difficulty) {
1387
- if ((difficulty === "hard" || difficulty === "insane") && this.rng.next() < 0.12 && (x > 0 || y > 0)) {
1388
- return {
1389
- type: "blocked",
1390
- rotation: 0,
1391
- baseConnections: [false, false, false, false],
1392
- currentConnections: [false, false, false, false],
1393
- isPowered: false,
1394
- isFixed: true
1395
- };
1396
- }
1397
- const roll = this.rng.next();
1398
- let type = "corner";
1399
- let base = [true, true, false, false];
1400
- if (roll < 0.4) {
1401
- type = "straight";
1402
- base = [true, false, true, false];
1403
- } else if (roll < 0.75) {
1404
- type = "corner";
1405
- base = [true, true, false, false];
1406
- } else if (roll < 0.92) {
1407
- type = "t-shape";
1408
- base = [true, true, false, true];
1409
- } else {
1410
- type = "cross";
1411
- base = [true, true, true, true];
1412
- }
1413
- const rotation = this.rng.nextInt(0, 3);
1414
- const current = this.rotateMask(base, rotation);
1415
- return {
1416
- type,
1417
- rotation,
1418
- baseConnections: base,
1419
- currentConnections: current,
1420
- isPowered: false,
1421
- isFixed: false
1422
- };
1423
- }
1424
- rotateMask(mask, times) {
1425
- const res = [...mask];
1426
- for (let i = 0; i < times % 4; i++) {
1427
- const [top, right, bottom, left] = res;
1428
- res[0] = left;
1429
- res[1] = top;
1430
- res[2] = right;
1431
- res[3] = bottom;
1432
- }
1433
- return res;
1434
- }
1435
- rotateTileAt(x, y) {
1436
- const tile = this.state.grid[y]?.[x];
1437
- if (!tile || tile.isFixed || this.state.isWon || this.state.isGameOver) return false;
1438
- tile.rotation = (tile.rotation + 1) % 4;
1439
- tile.currentConnections = this.rotateMask(tile.baseConnections, tile.rotation);
1440
- this.state.movesRemaining--;
1441
- this.updatePowerFlow();
1442
- if (this.config?.soundEnabled) {
1443
- playTerminalBell();
1444
- }
1445
- if (this.state.isWon) {
1446
- const bonus = this.state.movesRemaining * 100;
1447
- this.state.score += 500 + bonus;
1448
- this.config?.onScoreUpdate?.(this.state.score);
1449
- this.config?.onAchievementUnlock?.("first_spark");
1450
- if (this.state.movesRemaining >= 5) {
1451
- this.config?.onAchievementUnlock?.("overclocked");
1452
- }
1453
- if (this.config?.difficulty === "insane") {
1454
- this.config?.onAchievementUnlock?.("grid_master");
1455
- }
1456
- } else if (this.state.movesRemaining <= 0) {
1457
- this.state.isGameOver = true;
1458
- this.config?.onGameOver?.(this.state.score);
1459
- }
1460
- return true;
1461
- }
1462
- updatePowerFlow() {
1463
- const { width, height, grid } = this.state;
1464
- for (let y = 0; y < height; y++) {
1465
- for (let x = 0; x < width; x++) {
1466
- if (grid[y][x].type !== "source") {
1467
- grid[y][x].isPowered = false;
1468
- }
1469
- }
1470
- }
1471
- const queue = [[0, 0]];
1472
- const visited = /* @__PURE__ */ new Set();
1473
- visited.add("0,0");
1474
- let targetsLit = 0;
1475
- const dx = [0, 1, 0, -1];
1476
- const dy = [-1, 0, 1, 0];
1477
- const oppositeDir = [2, 3, 0, 1];
1478
- while (queue.length > 0) {
1479
- const [cx, cy] = queue.shift();
1480
- const curr = grid[cy][cx];
1481
- for (let dir = 0; dir < 4; dir++) {
1482
- if (!curr.currentConnections[dir]) continue;
1483
- const nx = cx + dx[dir];
1484
- const ny = cy + dy[dir];
1485
- if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
1486
- const key = `${nx},${ny}`;
1487
- if (visited.has(key)) continue;
1488
- const neighbor = grid[ny][nx];
1489
- if (neighbor.type === "blocked") continue;
1490
- const opp = oppositeDir[dir];
1491
- if (neighbor.currentConnections[opp]) {
1492
- neighbor.isPowered = true;
1493
- visited.add(key);
1494
- queue.push([nx, ny]);
1495
- if (neighbor.type === "target") {
1496
- targetsLit++;
1497
- }
1498
- }
1499
- }
1500
- }
1501
- this.state.targetsRemaining = this.state.totalTargets - targetsLit;
1502
- if (this.state.targetsRemaining === 0) {
1503
- this.state.isWon = true;
1504
- }
1505
- }
1506
- handleInput(key) {
1507
- if (this.showTutorial) {
1508
- if (key.name === "return" || key.name === "space") {
1509
- this.showTutorial = false;
1510
- this.render();
1511
- } else if (key.name === "escape" || key.name === "q") {
1512
- this.destroy();
1513
- this.config?.onExit?.();
1514
- }
1515
- return;
1516
- }
1517
- if (this.isPaused) {
1518
- if (key.name === "up" || key.name === "w") {
1519
- this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
1520
- this.render();
1521
- } else if (key.name === "down" || key.name === "s") {
1522
- this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
1523
- this.render();
1524
- } else if (key.name === "return" || key.name === "space") {
1525
- if (this.pauseMenuIndex === 0) {
1526
- this.isPaused = false;
1527
- this.render();
1528
- } else if (this.pauseMenuIndex === 1) {
1529
- this.isPaused = false;
1530
- this.setupLevel(this.state.level, this.config?.difficulty || "normal");
1531
- this.render();
1532
- } else if (this.pauseMenuIndex === 2) {
1533
- this.destroy();
1534
- this.config?.onExit?.();
1535
- }
1536
- } else if (key.name === "escape" || key.name === "p") {
1537
- this.isPaused = false;
1538
- this.render();
1539
- } else if (key.name === "q") {
1540
- this.destroy();
1541
- this.config?.onExit?.();
1542
- }
1543
- return;
1544
- }
1545
- if (key.name === "escape" || key.name === "p") {
1546
- this.isPaused = true;
1547
- this.pauseMenuIndex = 0;
1548
- this.render();
1549
- return;
1550
- }
1551
- if (key.name === "q") {
1552
- this.destroy();
1553
- this.config?.onExit?.();
1554
- return;
1555
- }
1556
- if (this.state.isWon) {
1557
- if (key.name === "return" || key.name === "space") {
1558
- this.setupLevel(this.state.level + 1, this.config?.difficulty || "normal");
1559
- this.render();
1560
- } else if (key.name === "escape" || key.name === "q") {
1561
- this.destroy();
1562
- this.config?.onExit?.();
1563
- }
1564
- return;
1565
- }
1566
- if (this.state.isGameOver) {
1567
- if (key.name === "r") {
1568
- this.restart();
1569
- } else if (key.name === "escape" || key.name === "q") {
1570
- this.destroy();
1571
- this.config?.onExit?.();
1572
- }
1573
- return;
1574
- }
1575
- if (key.name === "up" || key.name === "w") {
1576
- this.state.cursorY = Math.max(0, this.state.cursorY - 1);
1577
- this.render();
1578
- } else if (key.name === "down" || key.name === "s") {
1579
- this.state.cursorY = Math.min(this.state.height - 1, this.state.cursorY + 1);
1580
- this.render();
1581
- } else if (key.name === "left" || key.name === "a") {
1582
- this.state.cursorX = Math.max(0, this.state.cursorX - 1);
1583
- this.render();
1584
- } else if (key.name === "right" || key.name === "d") {
1585
- this.state.cursorX = Math.min(this.state.width - 1, this.state.cursorX + 1);
1586
- this.render();
1587
- } else if (key.name === "space" || key.name === "return") {
1588
- this.rotateTileAt(this.state.cursorX, this.state.cursorY);
1589
- this.render();
1590
- } else if (key.name === "r") {
1591
- this.setupLevel(this.state.level, this.config?.difficulty || "normal");
1592
- this.render();
1593
- }
1594
- }
1595
- render() {
1596
- const t = this.renderer.getTheme();
1597
- if (this.showTutorial) {
1598
- const tutorialLines = [
1599
- "",
1600
- t.highlight("OBJECTIVE: ROUTE HIGH-VOLTAGE FLUX"),
1601
- "",
1602
- "\u2022 Navigate cursor using Arrow Keys or WASD.",
1603
- "\u2022 Press Space or Enter to rotate circuit tiles clockwise.",
1604
- "\u2022 Connect the glowing [S] Power Source to the [T] Target nodes.",
1605
- "\u2022 Watch your Capacity (Moves Remaining) meter.",
1606
- "\u2022 Obstacles [\u2593] cannot conduct energy or rotate.",
1607
- "",
1608
- 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"),
1609
- t.primary("Press Space or Enter to start \u2502 Esc / Q to Exit")
1610
- ];
1611
- const box = this.renderer.createBox(tutorialLines, 64, "CIRCUIT PROTOCOL MANUAL");
1612
- this.renderer.clear();
1613
- this.renderer.draw(`
1614
-
1615
- ${box}
1616
- `);
1617
- return;
1618
- }
1619
- if (this.isPaused) {
1620
- const pauseItems = ["Resume Circuit (Esc / Enter)", "Restart Level (R)", "Quit to Arcade / Terminal (Q)"];
1621
- const pauseLines = [
1622
- "",
1623
- t.highlight("\u2550\u2550\u2550 CIRCUIT SUBROUTINE PAUSED \u2550\u2550\u2550"),
1624
- "",
1625
- ...pauseItems.map((item, idx) => {
1626
- if (idx === this.pauseMenuIndex) {
1627
- return t.primary(` \u25B6 ${t.highlight(item)}`);
1628
- }
1629
- return t.muted(` ${item}`);
1630
- }),
1631
- "",
1632
- 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"),
1633
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
1634
- ];
1635
- const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
1636
- this.renderer.clear();
1637
- this.renderer.draw(`
1638
-
1639
- ${pauseBox}
1640
- `);
1641
- return;
1642
- }
1643
- const header = this.renderer.renderHeader({
1644
- title: "NEON CIRCUIT",
1645
- category: "PUZZLE",
1646
- difficulty: this.config?.difficulty,
1647
- score: this.state.score,
1648
- level: this.state.level
1649
- });
1650
- const lines = [];
1651
- const { width, height, grid, cursorX, cursorY } = this.state;
1652
- lines.push(` Level: ${t.primary(this.state.level.toString())} Moves: ${this.state.movesRemaining > 5 ? t.success(this.state.movesRemaining.toString()) : t.error(this.state.movesRemaining.toString())} Targets: ${t.accent(`${this.state.totalTargets - this.state.targetsRemaining}/${this.state.totalTargets}`)}`);
1653
- lines.push("");
1654
- for (let y = 0; y < height; y++) {
1655
- let rowStr = " ";
1656
- for (let x = 0; x < width; x++) {
1657
- const tile = grid[y][x];
1658
- const isCursor = x === cursorX && y === cursorY;
1659
- const glyph = this.getTileGlyph(tile);
1660
- let formatted = glyph;
1661
- if (tile.isPowered) {
1662
- formatted = t.highlight(glyph);
1663
- } else {
1664
- formatted = t.muted(glyph);
1665
- }
1666
- if (isCursor) {
1667
- rowStr += `[${t.accent(glyph)}] `;
1668
- } else {
1669
- rowStr += ` ${formatted} `;
1670
- }
1671
- }
1672
- lines.push(rowStr);
1673
- lines.push("");
1674
- }
1675
- if (this.state.isWon) {
1676
- lines.push(` ${t.success("\u26A1 CIRCUIT SYNCHRONIZED! ALL NODES POWERED!")}`);
1677
- lines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
1678
- } else if (this.state.isGameOver) {
1679
- lines.push(` ${t.error("\u274C CAPACITY EXHAUSTED! POWER COLLAPSE.")}`);
1680
- lines.push(` ${t.muted("Press R to Retry Level, or P for Pause Menu.")}`);
1681
- } else {
1682
- lines.push(` ${t.muted("Controls: Arrows/WASD: Move \u2502 Space: Rotate \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
1683
- }
1684
- this.renderer.clear();
1685
- this.renderer.draw(`
1686
- ${header}
1687
- ${lines.join("\n")}
1688
- `);
1689
- }
1690
- getTileGlyph(tile) {
1691
- if (tile.type === "source") return "S";
1692
- if (tile.type === "target") return "T";
1693
- if (tile.type === "blocked") return "\u2593";
1694
- const [top, right, bottom, left] = tile.currentConnections;
1695
- if (top && bottom && !right && !left) return "\u2502";
1696
- if (!top && !bottom && right && left) return "\u2500";
1697
- if (bottom && right && !top && !left) return "\u250C";
1698
- if (bottom && left && !top && !right) return "\u2510";
1699
- if (top && right && !bottom && !left) return "\u2514";
1700
- if (top && left && !bottom && !right) return "\u2518";
1701
- if (top && bottom && right && !left) return "\u251C";
1702
- if (top && bottom && !right && left) return "\u2524";
1703
- if (!top && bottom && right && left) return "\u252C";
1704
- if (top && !bottom && right && left) return "\u2534";
1705
- if (top && bottom && right && left) return "\u253C";
1706
- return "\u2022";
1707
- }
1708
- getState() {
1709
- return this.state;
1710
- }
1711
- };
1712
-
1713
- // src/games/byte-runner/index.ts
1714
- var HIGHWAY_HEIGHT = 16;
1715
- var LANE_COUNT = 3;
1716
- var ByteRunnerGame = class {
1717
- id = "byte-runner";
1718
- metadata = ALL_GAMES_METADATA["byte-runner"];
1719
- config = null;
1720
- renderer = defaultRenderer;
1721
- input = new TerminalInputHandler();
1722
- rng = new DeterministicRNG();
1723
- gameLoopTimer = null;
1724
- entityIdCounter = 0;
1725
- entities = [];
1726
- state = {
1727
- playerLane: 1,
1728
- isJumping: false,
1729
- jumpTicksRemaining: 0,
1730
- score: 0,
1731
- distance: 0,
1732
- cleanBytesCollected: 0,
1733
- activeShield: false,
1734
- slowMotionTicks: 0,
1735
- magnetTicks: 0,
1736
- doubleScoreTicks: 0,
1737
- speedMs: 110,
1738
- isGameOver: false,
1739
- multiplier: 1
1740
- };
1741
- isPaused = false;
1742
- pauseMenuIndex = 0;
1743
- showTutorial = true;
1744
- init(config) {
1745
- this.config = config;
1746
- this.renderer.setTheme(config.theme);
1747
- this.rng = new DeterministicRNG(config.seed || Date.now());
1748
- if (config.skipTutorial !== void 0) {
1749
- this.showTutorial = !config.skipTutorial;
1750
- }
1751
- this.resetState(config.difficulty);
1752
- }
1753
- start() {
1754
- this.isPaused = false;
1755
- this.render();
1756
- this.input.start(
1757
- (key) => this.handleInput(key),
1758
- () => {
1759
- this.destroy();
1760
- process.exit(0);
1761
- }
1762
- );
1763
- this.scheduleNextTick();
1764
- }
1765
- pause() {
1766
- this.isPaused = true;
1767
- if (this.gameLoopTimer) {
1768
- clearTimeout(this.gameLoopTimer);
1769
- this.gameLoopTimer = null;
1770
- }
1771
- }
1772
- resume() {
1773
- this.isPaused = false;
1774
- this.scheduleNextTick();
1775
- this.render();
1776
- }
1777
- restart() {
1778
- if (this.config) {
1779
- this.resetState(this.config.difficulty);
1780
- this.scheduleNextTick();
1781
- this.render();
1782
- }
1783
- }
1784
- saveState() {
1785
- return {
1786
- state: this.state,
1787
- entities: this.entities,
1788
- showTutorial: this.showTutorial
1789
- };
1790
- }
1791
- loadState(saved) {
1792
- if (saved["state"]) {
1793
- this.state = saved["state"];
1794
- }
1795
- if (saved["entities"]) {
1796
- this.entities = saved["entities"];
1797
- }
1798
- if (saved["showTutorial"] !== void 0) {
1799
- this.showTutorial = !!saved["showTutorial"];
1800
- }
1801
- }
1802
- destroy() {
1803
- if (this.gameLoopTimer) {
1804
- clearTimeout(this.gameLoopTimer);
1805
- this.gameLoopTimer = null;
1806
- }
1807
- this.input.stop();
1808
- }
1809
- resetState(difficulty) {
1810
- let baseSpeed = 110;
1811
- switch (difficulty) {
1812
- case "easy":
1813
- baseSpeed = 140;
1814
- break;
1815
- case "normal":
1816
- baseSpeed = 110;
1817
- break;
1818
- case "hard":
1819
- baseSpeed = 85;
1820
- break;
1821
- case "insane":
1822
- baseSpeed = 65;
1823
- break;
1824
- }
1825
- this.state = {
1826
- playerLane: 1,
1827
- isJumping: false,
1828
- jumpTicksRemaining: 0,
1829
- score: 0,
1830
- distance: 0,
1831
- cleanBytesCollected: 0,
1832
- activeShield: false,
1833
- slowMotionTicks: 0,
1834
- magnetTicks: 0,
1835
- doubleScoreTicks: 0,
1836
- speedMs: baseSpeed,
1837
- isGameOver: false,
1838
- multiplier: 1
1839
- };
1840
- this.entities = [];
1841
- }
1842
- scheduleNextTick() {
1843
- if (this.gameLoopTimer) {
1844
- clearTimeout(this.gameLoopTimer);
1845
- }
1846
- if (this.isPaused || this.state.isGameOver || this.showTutorial) return;
1847
- let delay = this.state.speedMs;
1848
- if (this.state.slowMotionTicks > 0) {
1849
- delay = Math.round(delay * 1.6);
1850
- }
1851
- this.gameLoopTimer = setTimeout(() => {
1852
- this.tick();
1853
- this.scheduleNextTick();
1854
- }, delay);
1855
- }
1856
- tick() {
1857
- if (this.state.isGameOver || this.isPaused || this.showTutorial) return;
1858
- this.state.distance += 1;
1859
- const pointGain = 1 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
1860
- this.state.score += pointGain;
1861
- if (this.state.jumpTicksRemaining > 0) {
1862
- this.state.jumpTicksRemaining--;
1863
- if (this.state.jumpTicksRemaining === 0) {
1864
- this.state.isJumping = false;
1865
- }
1866
- }
1867
- if (this.state.slowMotionTicks > 0) this.state.slowMotionTicks--;
1868
- if (this.state.magnetTicks > 0) this.state.magnetTicks--;
1869
- if (this.state.doubleScoreTicks > 0) this.state.doubleScoreTicks--;
1870
- for (const ent of this.entities) {
1871
- ent.y += 1;
1872
- if (this.state.magnetTicks > 0 && ent.type === "clean" && ent.y >= HIGHWAY_HEIGHT - 6) {
1873
- ent.lane = this.state.playerLane;
1874
- }
1875
- }
1876
- const playerY = HIGHWAY_HEIGHT - 2;
1877
- const remainingEntities = [];
1878
- for (const ent of this.entities) {
1879
- if (ent.y === playerY && ent.lane === this.state.playerLane) {
1880
- if (ent.type === "corrupt") {
1881
- if (this.state.isJumping) {
1882
- remainingEntities.push(ent);
1883
- continue;
1884
- }
1885
- if (this.state.activeShield) {
1886
- this.state.activeShield = false;
1887
- this.config?.onAchievementUnlock?.("shield_matrix");
1888
- if (this.config?.soundEnabled) playTerminalBell();
1889
- continue;
1890
- }
1891
- this.state.isGameOver = true;
1892
- this.config?.onGameOver?.(this.state.score);
1893
- if (this.config?.soundEnabled) playTerminalBell();
1894
- break;
1895
- } else if (ent.type === "clean") {
1896
- this.state.cleanBytesCollected++;
1897
- this.state.score += 100 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
1898
- this.config?.onScoreUpdate?.(this.state.score);
1899
- if (this.state.cleanBytesCollected >= 50) {
1900
- this.config?.onAchievementUnlock?.("packet_chaser");
1901
- }
1902
- if (this.config?.soundEnabled) playTerminalBell();
1903
- continue;
1904
- } else if (ent.type === "powerup") {
1905
- this.activatePowerUp(ent.subType);
1906
- if (this.config?.soundEnabled) playTerminalBell();
1907
- continue;
1908
- }
1909
- }
1910
- if (ent.y < HIGHWAY_HEIGHT) {
1911
- remainingEntities.push(ent);
1912
- }
1913
- }
1914
- this.entities = remainingEntities;
1915
- if (this.state.distance >= 5e3) {
1916
- this.config?.onAchievementUnlock?.("hyperspeed");
1917
- }
1918
- if (this.state.distance % 2 === 0) {
1919
- this.spawnHighwayWave();
1920
- }
1921
- if (this.state.distance % 200 === 0 && this.state.speedMs > 45) {
1922
- this.state.speedMs -= 2;
1923
- }
1924
- this.render();
1925
- }
1926
- activatePowerUp(type) {
1927
- switch (type) {
1928
- case "shield":
1929
- this.state.activeShield = true;
1930
- break;
1931
- case "slow":
1932
- this.state.slowMotionTicks = 60;
1933
- break;
1934
- case "magnet":
1935
- this.state.magnetTicks = 70;
1936
- break;
1937
- case "double":
1938
- this.state.doubleScoreTicks = 80;
1939
- break;
1940
- }
1941
- }
1942
- spawnHighwayWave() {
1943
- const roll = this.rng.next();
1944
- const lane = this.rng.nextInt(0, LANE_COUNT - 1);
1945
- if (roll < 0.45) {
1946
- const labels = ["[CORRUPT]", "[BAD_MEM]", "[NULL_PTR]", "[SEG_FLT]"];
1947
- this.entities.push({
1948
- id: ++this.entityIdCounter,
1949
- lane,
1950
- y: 0,
1951
- type: "corrupt",
1952
- label: this.rng.pick(labels)
1953
- });
1954
- } else if (roll < 0.8) {
1955
- const labels = ["0x7F", "0xFF", "[CLEAN]", "[PACKET]"];
1956
- this.entities.push({
1957
- id: ++this.entityIdCounter,
1958
- lane,
1959
- y: 0,
1960
- type: "clean",
1961
- label: this.rng.pick(labels)
1962
- });
1963
- } else if (roll < 0.95) {
1964
- const powerups = ["shield", "slow", "magnet", "double"];
1965
- const chosen = this.rng.pick(powerups);
1966
- const labels = {
1967
- shield: "\u{1F6E1}\uFE0F [SHLD]",
1968
- slow: "\u23F1\uFE0F [SLOW]",
1969
- magnet: "\u{1F9F2} [MAG]",
1970
- double: "\u26A1 [2X]"
1971
- };
1972
- this.entities.push({
1973
- id: ++this.entityIdCounter,
1974
- lane,
1975
- y: 0,
1976
- type: "powerup",
1977
- subType: chosen,
1978
- label: labels[chosen]
1979
- });
1980
- }
1981
- }
1982
- handleInput(key) {
1983
- if (this.showTutorial) {
1984
- if (key.name === "return" || key.name === "space") {
1985
- this.showTutorial = false;
1986
- this.scheduleNextTick();
1987
- this.render();
1988
- } else if (key.name === "escape" || key.name === "q") {
1989
- this.destroy();
1990
- this.config?.onExit?.();
1991
- }
1992
- return;
1993
- }
1994
- if (this.isPaused) {
1995
- if (key.name === "up" || key.name === "w") {
1996
- this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
1997
- this.render();
1998
- } else if (key.name === "down" || key.name === "s") {
1999
- this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
2000
- this.render();
2001
- } else if (key.name === "return" || key.name === "space") {
2002
- if (this.pauseMenuIndex === 0) {
2003
- this.isPaused = false;
2004
- this.scheduleNextTick();
2005
- this.render();
2006
- } else if (this.pauseMenuIndex === 1) {
2007
- this.isPaused = false;
2008
- this.restart();
2009
- } else if (this.pauseMenuIndex === 2) {
2010
- this.destroy();
2011
- this.config?.onExit?.();
2012
- }
2013
- } else if (key.name === "escape" || key.name === "p") {
2014
- this.isPaused = false;
2015
- this.scheduleNextTick();
2016
- this.render();
2017
- } else if (key.name === "q") {
2018
- this.destroy();
2019
- this.config?.onExit?.();
2020
- }
2021
- return;
2022
- }
2023
- if (key.name === "escape" || key.name === "p") {
2024
- this.isPaused = true;
2025
- this.pauseMenuIndex = 0;
2026
- if (this.gameLoopTimer) {
2027
- clearTimeout(this.gameLoopTimer);
2028
- this.gameLoopTimer = null;
2029
- }
2030
- this.render();
2031
- return;
2032
- }
2033
- if (key.name === "q") {
2034
- this.destroy();
2035
- this.config?.onExit?.();
2036
- return;
2037
- }
2038
- if (this.state.isGameOver) {
2039
- if (key.name === "r") {
2040
- this.restart();
2041
- } else if (key.name === "escape" || key.name === "q") {
2042
- this.destroy();
2043
- this.config?.onExit?.();
2044
- }
2045
- return;
2046
- }
2047
- if (key.name === "left" || key.name === "a") {
2048
- if (this.state.playerLane > 0) {
2049
- this.state.playerLane--;
2050
- this.render();
2051
- }
2052
- } else if (key.name === "right" || key.name === "d") {
2053
- if (this.state.playerLane < LANE_COUNT - 1) {
2054
- this.state.playerLane++;
2055
- this.render();
2056
- }
2057
- } else if (key.name === "up" || key.name === "w" || key.name === "space") {
2058
- if (!this.state.isJumping) {
2059
- this.state.isJumping = true;
2060
- this.state.jumpTicksRemaining = 3;
2061
- this.render();
2062
- }
2063
- } else if (key.name === "down" || key.name === "s") {
2064
- this.state.isJumping = false;
2065
- this.state.jumpTicksRemaining = 0;
2066
- this.render();
2067
- }
2068
- }
2069
- render() {
2070
- const t = this.renderer.getTheme();
2071
- if (this.showTutorial) {
2072
- const lines = [
2073
- "",
2074
- t.highlight("OBJECTIVE: SPRINT THE FIBER HIGHWAY"),
2075
- "",
2076
- "\u2022 Use Left/Right (or A/D) to switch between 3 data lanes.",
2077
- "\u2022 Press Up / Space to Phase Jump over low corrupted blocks.",
2078
- "\u2022 Collect Clean Byte packets to boost your score.",
2079
- "\u2022 Grab Power-ups: [SHLD] Shield, [SLOW] Buffer, [MAG] Magnet, [2X] Double.",
2080
- "\u2022 Speed escalates continuously with distance.",
2081
- "",
2082
- 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"),
2083
- t.primary("Press Space or Enter to launch \u2502 Esc / Q to Exit")
2084
- ];
2085
- const box = this.renderer.createBox(lines, 64, "BYTE RUNNER MANUAL");
2086
- this.renderer.clear();
2087
- this.renderer.draw(`
2088
-
2089
- ${box}
2090
- `);
2091
- return;
2092
- }
2093
- if (this.isPaused) {
2094
- const pauseItems = ["Resume Runner (Esc / Enter)", "Restart Run (R)", "Quit to Arcade / Terminal (Q)"];
2095
- const pauseLines = [
2096
- "",
2097
- t.highlight("\u2550\u2550\u2550 HIGHWAY PACKET STREAM PAUSED \u2550\u2550\u2550"),
2098
- "",
2099
- ...pauseItems.map((item, idx) => {
2100
- if (idx === this.pauseMenuIndex) {
2101
- return t.primary(` \u25B6 ${t.highlight(item)}`);
2102
- }
2103
- return t.muted(` ${item}`);
2104
- }),
2105
- "",
2106
- 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"),
2107
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
2108
- ];
2109
- const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
2110
- this.renderer.clear();
2111
- this.renderer.draw(`
2112
-
2113
- ${pauseBox}
2114
- `);
2115
- return;
2116
- }
2117
- const header = this.renderer.renderHeader({
2118
- title: "BYTE RUNNER",
2119
- category: "ARCADE",
2120
- difficulty: this.config?.difficulty,
2121
- score: this.state.score
2122
- });
2123
- const hudLines = [];
2124
- const distStr = `${t.muted("Distance:")} ${t.primary(`${this.state.distance}m`)}`;
2125
- const bytesStr = `${t.muted("Clean Bytes:")} ${t.accent(this.state.cleanBytesCollected.toString())}`;
2126
- const buffs = [];
2127
- if (this.state.activeShield) buffs.push(t.success("[SHIELD ACTIVE]"));
2128
- if (this.state.slowMotionTicks > 0) buffs.push(t.warning(`[SLOW-MO ${Math.ceil(this.state.slowMotionTicks / 10)}s]`));
2129
- if (this.state.magnetTicks > 0) buffs.push(t.secondary(`[MAGNET ${Math.ceil(this.state.magnetTicks / 10)}s]`));
2130
- if (this.state.doubleScoreTicks > 0) buffs.push(t.highlight(`[2X SCORE ${Math.ceil(this.state.doubleScoreTicks / 10)}s]`));
2131
- hudLines.push(` ${distStr} ${bytesStr} ${buffs.join(" ")}`);
2132
- hudLines.push("");
2133
- const trackWidth = 54;
2134
- const laneWidth = 18;
2135
- const trackLines = [];
2136
- trackLines.push(` ${t.border("\u250C" + "\u2500".repeat(trackWidth) + "\u2510")}`);
2137
- for (let y = 0; y < HIGHWAY_HEIGHT; y++) {
2138
- let rowContent = "";
2139
- for (let lane = 0; lane < LANE_COUNT; lane++) {
2140
- const ent = this.entities.find((e) => e.lane === lane && e.y === y);
2141
- let cellText = " ".repeat(laneWidth);
2142
- if (ent) {
2143
- let formattedLabel = ent.label;
2144
- if (ent.type === "corrupt") {
2145
- formattedLabel = t.error(ent.label);
2146
- } else if (ent.type === "clean") {
2147
- formattedLabel = t.success(ent.label);
2148
- } else if (ent.type === "powerup") {
2149
- formattedLabel = t.highlight(ent.label);
2150
- }
2151
- const cleanLen = ent.label.length;
2152
- const leftPad = Math.floor((laneWidth - cleanLen) / 2);
2153
- const rightPad = laneWidth - cleanLen - leftPad;
2154
- cellText = " ".repeat(Math.max(0, leftPad)) + formattedLabel + " ".repeat(Math.max(0, rightPad));
2155
- }
2156
- if (y === HIGHWAY_HEIGHT - 2 && lane === this.state.playerLane) {
2157
- const avatar = this.state.isJumping ? "\u25B2 [AIRBORNE] \u25B2" : "\u25B2\u2550\u2550[RUNNER]\u2550\u2550\u25B2";
2158
- const colored = this.state.activeShield ? t.highlight(avatar) : t.primary(avatar);
2159
- const pad = Math.max(0, Math.floor((laneWidth - 14) / 2));
2160
- cellText = " ".repeat(pad) + colored + " ".repeat(Math.max(0, laneWidth - 14 - pad));
2161
- }
2162
- rowContent += cellText + (lane < LANE_COUNT - 1 ? t.border("\u2506") : "");
2163
- }
2164
- trackLines.push(` ${t.border("\u2502")}${rowContent}${t.border("\u2502")}`);
2165
- }
2166
- trackLines.push(` ${t.border("\u2514" + "\u2500".repeat(trackWidth) + "\u2518")}`);
2167
- if (this.state.isGameOver) {
2168
- trackLines.push(`
2169
- ${t.error("\u{1F4A5} SYSTEM FAULT: PACKET CORRUPTED!")}`);
2170
- trackLines.push(` ${t.accent(`Final Distance: ${this.state.distance}m \u2502 Final Score: ${this.state.score}`)}`);
2171
- trackLines.push(` ${t.muted("Press R to Re-engage Runner, or Esc / Q to Exit.")}`);
2172
- } else {
2173
- trackLines.push(` ${t.muted("Controls: Left/Right: Lane \u2502 Up/Space: Jump \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
2174
- }
2175
- this.renderer.clear();
2176
- this.renderer.draw(`
2177
- ${header}
2178
- ${hudLines.join("\n")}
2179
- ${trackLines.join("\n")}
2180
- `);
2181
- }
2182
- getState() {
2183
- return this.state;
2184
- }
2185
- };
2186
-
2187
- // src/games/packet-man/index.ts
2188
- var MAZE_TEMPLATE = [
2189
- "###########################",
2190
- "#............#............#",
2191
- "#.####.#####.#.#####.####.#",
2192
- "#O####.#####.#.#####.####O#",
2193
- "#.####.#####.#.#####.####.#",
2194
- "#.........................#",
2195
- "#.####.##.#######.##.####.#",
2196
- "#......##....#....##......#",
2197
- "######.##### # #####.######",
2198
- " #.# #.# ",
2199
- "######.# ###---### #.######",
2200
- "#......# # # #......#",
2201
- "#.####.# ######### #.####.#",
2202
- "#O..##...............##..O#",
2203
- "###.##.##.#######.##.##.###",
2204
- "#......##....#....##......#",
2205
- "#.##########.#.##########.#",
2206
- "#.........................#",
2207
- "###########################"
2208
- ];
2209
- var MAZE_WIDTH = 27;
2210
- var MAZE_HEIGHT = 19;
2211
- var PacketManGame = class {
2212
- id = "packet-man";
2213
- metadata = ALL_GAMES_METADATA["packet-man"];
2214
- config = null;
2215
- renderer = defaultRenderer;
2216
- input = new TerminalInputHandler();
2217
- rng = new DeterministicRNG();
2218
- gameLoopTimer = null;
2219
- grid = [];
2220
- daemons = [];
2221
- daemonsChompedInSurge = 0;
2222
- pelletsEatenCount = 0;
2223
- state = {
2224
- playerX: 13,
2225
- playerY: 13,
2226
- playerDx: 0,
2227
- playerDy: 0,
2228
- desiredDx: 0,
2229
- desiredDy: 0,
2230
- mouthOpen: true,
2231
- lives: 3,
2232
- score: 0,
2233
- level: 1,
2234
- pelletsRemaining: 0,
2235
- totalPellets: 0,
2236
- frightenedTicksRemaining: 0,
2237
- frightenedCombo: 0,
2238
- isWon: false,
2239
- isGameOver: false
2240
- };
2241
- isPaused = false;
2242
- pauseMenuIndex = 0;
2243
- showTutorial = true;
2244
- tickIntervalMs = 150;
2245
- init(config) {
2246
- this.config = config;
2247
- this.renderer.setTheme(config.theme);
2248
- this.rng = new DeterministicRNG(config.seed || Date.now());
2249
- if (config.skipTutorial !== void 0) {
2250
- this.showTutorial = !config.skipTutorial;
2251
- }
2252
- this.resetGame(1, config.difficulty);
2253
- }
2254
- start() {
2255
- this.isPaused = false;
2256
- this.render();
2257
- this.input.start(
2258
- (key) => this.handleInput(key),
2259
- () => {
2260
- this.destroy();
2261
- process.exit(0);
2262
- }
2263
- );
2264
- this.scheduleNextTick();
2265
- }
2266
- pause() {
2267
- this.isPaused = true;
2268
- if (this.gameLoopTimer) {
2269
- clearTimeout(this.gameLoopTimer);
2270
- this.gameLoopTimer = null;
2271
- }
2272
- }
2273
- resume() {
2274
- this.isPaused = false;
2275
- this.scheduleNextTick();
2276
- this.render();
2277
- }
2278
- restart() {
2279
- if (this.config) {
2280
- this.resetGame(1, this.config.difficulty);
2281
- this.scheduleNextTick();
2282
- this.render();
2283
- }
2284
- }
2285
- saveState() {
2286
- return {
2287
- state: this.state,
2288
- grid: this.grid,
2289
- daemons: this.daemons,
2290
- showTutorial: this.showTutorial
2291
- };
2292
- }
2293
- loadState(saved) {
2294
- if (saved["state"]) this.state = saved["state"];
2295
- if (saved["grid"]) this.grid = saved["grid"];
2296
- if (saved["daemons"]) this.daemons = saved["daemons"];
2297
- if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
2298
- }
2299
- destroy() {
2300
- if (this.gameLoopTimer) {
2301
- clearTimeout(this.gameLoopTimer);
2302
- this.gameLoopTimer = null;
2303
- }
2304
- this.input.stop();
2305
- }
2306
- resetGame(level, difficulty) {
2307
- switch (difficulty) {
2308
- case "easy":
2309
- this.tickIntervalMs = 175;
2310
- break;
2311
- case "normal":
2312
- this.tickIntervalMs = 145;
2313
- break;
2314
- case "hard":
2315
- this.tickIntervalMs = 120;
2316
- break;
2317
- case "insane":
2318
- this.tickIntervalMs = 95;
2319
- break;
2320
- }
2321
- this.state = {
2322
- playerX: 13,
2323
- playerY: 13,
2324
- playerDx: -1,
2325
- playerDy: 0,
2326
- desiredDx: -1,
2327
- desiredDy: 0,
2328
- mouthOpen: true,
2329
- lives: 3,
2330
- score: this.state.score,
2331
- level,
2332
- pelletsRemaining: 0,
2333
- totalPellets: 0,
2334
- frightenedTicksRemaining: 0,
2335
- frightenedCombo: 0,
2336
- isWon: false,
2337
- isGameOver: false
2338
- };
2339
- this.daemonsChompedInSurge = 0;
2340
- this.loadMaze();
2341
- this.resetDaemons();
2342
- }
2343
- loadMaze() {
2344
- this.grid = [];
2345
- let pellets = 0;
2346
- for (let y = 0; y < MAZE_HEIGHT; y++) {
2347
- const row = [];
2348
- const line = MAZE_TEMPLATE[y] || "";
2349
- for (let x = 0; x < MAZE_WIDTH; x++) {
2350
- const char = line[x] || " ";
2351
- if (char === "#") {
2352
- row.push("wall");
2353
- } else if (char === ".") {
2354
- row.push("pellet");
2355
- pellets++;
2356
- } else if (char === "O") {
2357
- row.push("power");
2358
- pellets++;
2359
- } else if (char === "-") {
2360
- row.push("gate");
2361
- } else {
2362
- row.push("empty");
2363
- }
2364
- }
2365
- this.grid.push(row);
2366
- }
2367
- this.state.pelletsRemaining = pellets;
2368
- this.state.totalPellets = pellets;
2369
- }
2370
- resetDaemons() {
2371
- this.daemons = [
2372
- {
2373
- id: "blinky",
2374
- name: "Blinky",
2375
- x: 13,
2376
- y: 7,
2377
- dx: 1,
2378
- dy: 0,
2379
- baseX: 25,
2380
- baseY: 1,
2381
- state: "chase",
2382
- frightenedTicks: 0,
2383
- colorName: "red"
2384
- },
2385
- {
2386
- id: "pinky",
2387
- name: "Pinky",
2388
- x: 12,
2389
- y: 11,
2390
- dx: 0,
2391
- dy: -1,
2392
- baseX: 1,
2393
- baseY: 1,
2394
- state: "chase",
2395
- frightenedTicks: 0,
2396
- colorName: "pink"
2397
- },
2398
- {
2399
- id: "inky",
2400
- name: "Inky",
2401
- x: 13,
2402
- y: 11,
2403
- dx: 0,
2404
- dy: -1,
2405
- baseX: 25,
2406
- baseY: 17,
2407
- state: "chase",
2408
- frightenedTicks: 0,
2409
- colorName: "cyan"
2410
- },
2411
- {
2412
- id: "clyde",
2413
- name: "Clyde",
2414
- x: 14,
2415
- y: 11,
2416
- dx: 0,
2417
- dy: -1,
2418
- baseX: 1,
2419
- baseY: 17,
2420
- state: "chase",
2421
- frightenedTicks: 0,
2422
- colorName: "yellow"
2423
- }
2424
- ];
2425
- }
2426
- scheduleNextTick() {
2427
- if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
2428
- if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
2429
- this.gameLoopTimer = setTimeout(() => {
2430
- this.tick();
2431
- this.scheduleNextTick();
2432
- }, this.tickIntervalMs);
2433
- }
2434
- tick() {
2435
- if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
2436
- this.state.mouthOpen = !this.state.mouthOpen;
2437
- if (this.state.frightenedTicksRemaining > 0) {
2438
- this.state.frightenedTicksRemaining--;
2439
- if (this.state.frightenedTicksRemaining === 0) {
2440
- for (const d of this.daemons) {
2441
- if (d.state === "frightened") d.state = "chase";
2442
- }
2443
- }
2444
- }
2445
- if (this.canMove(this.state.playerX, this.state.playerY, this.state.desiredDx, this.state.desiredDy)) {
2446
- this.state.playerDx = this.state.desiredDx;
2447
- this.state.playerDy = this.state.desiredDy;
2448
- }
2449
- if (this.canMove(this.state.playerX, this.state.playerY, this.state.playerDx, this.state.playerDy)) {
2450
- this.state.playerX += this.state.playerDx;
2451
- this.state.playerY += this.state.playerDy;
2452
- if (this.state.playerX < 0) this.state.playerX = MAZE_WIDTH - 1;
2453
- else if (this.state.playerX >= MAZE_WIDTH) this.state.playerX = 0;
2454
- this.chompCurrentTile();
2455
- }
2456
- this.moveDaemons();
2457
- this.checkCollisions();
2458
- this.render();
2459
- }
2460
- canMove(x, y, dx, dy, isDaemon = false) {
2461
- let nx = x + dx;
2462
- let ny = y + dy;
2463
- if (nx < 0) nx = MAZE_WIDTH - 1;
2464
- else if (nx >= MAZE_WIDTH) nx = 0;
2465
- if (ny < 0 || ny >= MAZE_HEIGHT) return false;
2466
- const tile = this.grid[ny]?.[nx];
2467
- if (!tile || tile === "wall") return false;
2468
- if (tile === "gate" && !isDaemon) return false;
2469
- return true;
2470
- }
2471
- chompCurrentTile() {
2472
- const tile = this.grid[this.state.playerY]?.[this.state.playerX];
2473
- if (tile === "pellet") {
2474
- this.grid[this.state.playerY][this.state.playerX] = "empty";
2475
- this.state.score += 10;
2476
- this.state.pelletsRemaining--;
2477
- this.pelletsEatenCount++;
2478
- this.config?.onScoreUpdate?.(this.state.score);
2479
- if (this.pelletsEatenCount >= 50) {
2480
- this.config?.onAchievementUnlock?.("first_chomp");
2481
- }
2482
- if (this.state.pelletsRemaining === 0) {
2483
- this.state.isWon = true;
2484
- this.config?.onAchievementUnlock?.("maze_sweeper");
2485
- return;
2486
- }
2487
- } else if (tile === "power") {
2488
- this.grid[this.state.playerY][this.state.playerX] = "empty";
2489
- this.state.score += 50;
2490
- this.state.pelletsRemaining--;
2491
- this.daemonsChompedInSurge = 0;
2492
- let surgeTicks = 45;
2493
- if (this.config?.difficulty === "easy") surgeTicks = 65;
2494
- else if (this.config?.difficulty === "hard") surgeTicks = 30;
2495
- else if (this.config?.difficulty === "insane") surgeTicks = 18;
2496
- this.state.frightenedTicksRemaining = surgeTicks;
2497
- this.state.frightenedCombo = 0;
2498
- for (const d of this.daemons) {
2499
- if (d.state !== "eaten") {
2500
- d.state = "frightened";
2501
- d.dx = -d.dx;
2502
- d.dy = -d.dy;
2503
- }
2504
- }
2505
- if (this.config?.soundEnabled) playTerminalBell();
2506
- }
2507
- }
2508
- moveDaemons() {
2509
- const directions = [
2510
- [0, -1],
2511
- // Up
2512
- [-1, 0],
2513
- // Left
2514
- [0, 1],
2515
- // Down
2516
- [1, 0]
2517
- // Right
2518
- ];
2519
- for (const d of this.daemons) {
2520
- if (d.state === "eaten") {
2521
- if (d.x === 13 && d.y === 9) {
2522
- d.state = "chase";
2523
- }
2524
- }
2525
- const validDirs = [];
2526
- for (const [dx, dy] of directions) {
2527
- if (dx === -d.dx && dy === -d.dy) continue;
2528
- if (this.canMove(d.x, d.y, dx, dy, true)) {
2529
- validDirs.push([dx, dy]);
2530
- }
2531
- }
2532
- if (validDirs.length === 0) {
2533
- if (this.canMove(d.x, d.y, -d.dx, -d.dy, true)) {
2534
- validDirs.push([-d.dx, -d.dy]);
2535
- }
2536
- }
2537
- if (validDirs.length > 0) {
2538
- let chosenDir;
2539
- if (d.state === "frightened") {
2540
- chosenDir = this.rng.pick(validDirs);
2541
- } else {
2542
- let targetX = this.state.playerX;
2543
- let targetY = this.state.playerY;
2544
- if (d.id === "pinky") {
2545
- targetX += this.state.playerDx * 4;
2546
- targetY += this.state.playerDy * 4;
2547
- } else if (d.id === "clyde") {
2548
- const dist = Math.hypot(d.x - this.state.playerX, d.y - this.state.playerY);
2549
- if (dist < 6) {
2550
- targetX = d.baseX;
2551
- targetY = d.baseY;
2552
- }
2553
- }
2554
- chosenDir = validDirs[0];
2555
- let minDist = Infinity;
2556
- for (const [vx, vy] of validDirs) {
2557
- const nx = d.x + vx;
2558
- const ny = d.y + vy;
2559
- const dist = Math.hypot(nx - targetX, ny - targetY);
2560
- if (dist < minDist) {
2561
- minDist = dist;
2562
- chosenDir = [vx, vy];
2563
- }
2564
- }
2565
- }
2566
- d.dx = chosenDir[0];
2567
- d.dy = chosenDir[1];
2568
- d.x += d.dx;
2569
- d.y += d.dy;
2570
- if (d.x < 0) d.x = MAZE_WIDTH - 1;
2571
- else if (d.x >= MAZE_WIDTH) d.x = 0;
2572
- }
2573
- }
2574
- }
2575
- checkCollisions() {
2576
- for (const d of this.daemons) {
2577
- if (d.x === this.state.playerX && d.y === this.state.playerY) {
2578
- if (d.state === "frightened") {
2579
- d.state = "eaten";
2580
- d.x = 13;
2581
- d.y = 9;
2582
- this.state.frightenedCombo++;
2583
- const points = 200 * Math.pow(2, this.state.frightenedCombo - 1);
2584
- this.state.score += points;
2585
- this.daemonsChompedInSurge++;
2586
- if (this.daemonsChompedInSurge >= 4) {
2587
- this.config?.onAchievementUnlock?.("daemon_slayer");
2588
- }
2589
- if (this.config?.soundEnabled) playTerminalBell();
2590
- } else if (d.state === "chase") {
2591
- this.state.lives--;
2592
- if (this.config?.soundEnabled) playTerminalBell();
2593
- if (this.state.lives <= 0) {
2594
- this.state.isGameOver = true;
2595
- this.config?.onGameOver?.(this.state.score);
2596
- } else {
2597
- this.state.playerX = 13;
2598
- this.state.playerY = 13;
2599
- this.state.playerDx = -1;
2600
- this.state.playerDy = 0;
2601
- this.state.desiredDx = -1;
2602
- this.state.desiredDy = 0;
2603
- this.resetDaemons();
2604
- }
2605
- break;
2606
- }
2607
- }
2608
- }
2609
- }
2610
- handleInput(key) {
2611
- if (this.showTutorial) {
2612
- if (key.name === "return" || key.name === "space") {
2613
- this.showTutorial = false;
2614
- this.scheduleNextTick();
2615
- this.render();
2616
- } else if (key.name === "escape" || key.name === "q") {
2617
- this.destroy();
2618
- this.config?.onExit?.();
2619
- }
2620
- return;
2621
- }
2622
- if (this.isPaused) {
2623
- if (key.name === "up" || key.name === "w") {
2624
- this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
2625
- this.render();
2626
- } else if (key.name === "down" || key.name === "s") {
2627
- this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
2628
- this.render();
2629
- } else if (key.name === "return" || key.name === "space") {
2630
- if (this.pauseMenuIndex === 0) {
2631
- this.isPaused = false;
2632
- this.scheduleNextTick();
2633
- this.render();
2634
- } else if (this.pauseMenuIndex === 1) {
2635
- this.isPaused = false;
2636
- this.resetGame(this.state.level, this.config?.difficulty || "normal");
2637
- this.scheduleNextTick();
2638
- this.render();
2639
- } else if (this.pauseMenuIndex === 2) {
2640
- this.destroy();
2641
- this.config?.onExit?.();
2642
- }
2643
- } else if (key.name === "escape" || key.name === "p") {
2644
- this.isPaused = false;
2645
- this.scheduleNextTick();
2646
- this.render();
2647
- } else if (key.name === "q") {
2648
- this.destroy();
2649
- this.config?.onExit?.();
2650
- }
2651
- return;
2652
- }
2653
- if (key.name === "escape" || key.name === "p") {
2654
- this.isPaused = true;
2655
- this.pauseMenuIndex = 0;
2656
- if (this.gameLoopTimer) {
2657
- clearTimeout(this.gameLoopTimer);
2658
- this.gameLoopTimer = null;
2659
- }
2660
- this.render();
2661
- return;
2662
- }
2663
- if (key.name === "q") {
2664
- this.destroy();
2665
- this.config?.onExit?.();
2666
- return;
2667
- }
2668
- if (this.state.isWon) {
2669
- if (key.name === "return" || key.name === "space") {
2670
- this.resetGame(this.state.level + 1, this.config?.difficulty || "normal");
2671
- this.scheduleNextTick();
2672
- this.render();
2673
- } else if (key.name === "escape" || key.name === "q") {
2674
- this.destroy();
2675
- this.config?.onExit?.();
2676
- }
2677
- return;
2678
- }
2679
- if (this.state.isGameOver) {
2680
- if (key.name === "r") {
2681
- this.restart();
2682
- } else if (key.name === "escape" || key.name === "q") {
2683
- this.destroy();
2684
- this.config?.onExit?.();
2685
- }
2686
- return;
2687
- }
2688
- if (key.name === "up" || key.name === "w") {
2689
- this.state.desiredDx = 0;
2690
- this.state.desiredDy = -1;
2691
- } else if (key.name === "down" || key.name === "s") {
2692
- this.state.desiredDx = 0;
2693
- this.state.desiredDy = 1;
2694
- } else if (key.name === "left" || key.name === "a") {
2695
- this.state.desiredDx = -1;
2696
- this.state.desiredDy = 0;
2697
- } else if (key.name === "right" || key.name === "d") {
2698
- this.state.desiredDx = 1;
2699
- this.state.desiredDy = 0;
2700
- }
2701
- }
2702
- render() {
2703
- const t = this.renderer.getTheme();
2704
- if (this.showTutorial) {
2705
- const lines = [
2706
- "",
2707
- t.highlight("OBJECTIVE: CHOMP BYTE PELLETS & PURGE DAEMONS"),
2708
- "",
2709
- "\u2022 Use Arrow Keys or WASD to navigate memory corridors.",
2710
- "\u2022 Chomp all data pellets [ \xB7 ] to clear the sector.",
2711
- "\u2022 Ingest Super Capacitors [ \u25CF ] to trigger Power Surge state.",
2712
- "\u2022 During Power Surge, hunt vulnerable memory daemons for huge multipliers!",
2713
- "\u2022 Wrap through the side tunnels to evade ambushes.",
2714
- "",
2715
- 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"),
2716
- t.primary("Press Space or Enter to start \u2502 Esc / Q to Exit")
2717
- ];
2718
- const box = this.renderer.createBox(lines, 64, "PACKET MAN PROTOCOL MANUAL");
2719
- this.renderer.clear();
2720
- this.renderer.draw(`
2721
-
2722
- ${box}
2723
- `);
2724
- return;
2725
- }
2726
- if (this.isPaused) {
2727
- const pauseItems = ["Resume Arcade (Esc / Enter)", "Restart Round (R)", "Quit to Arcade / Terminal (Q)"];
2728
- const pauseLines = [
2729
- "",
2730
- t.highlight("\u2550\u2550\u2550 MEMORY MAZE PAUSED \u2550\u2550\u2550"),
2731
- "",
2732
- ...pauseItems.map((item, idx) => {
2733
- if (idx === this.pauseMenuIndex) {
2734
- return t.primary(` \u25B6 ${t.highlight(item)}`);
2735
- }
2736
- return t.muted(` ${item}`);
2737
- }),
2738
- "",
2739
- 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"),
2740
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
2741
- ];
2742
- const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
2743
- this.renderer.clear();
2744
- this.renderer.draw(`
2745
-
2746
- ${pauseBox}
2747
- `);
2748
- return;
2749
- }
2750
- const header = this.renderer.renderHeader({
2751
- title: "PACKET MAN",
2752
- category: "ARCADE",
2753
- difficulty: this.config?.difficulty,
2754
- score: this.state.score,
2755
- level: this.state.level
2756
- });
2757
- const hudLines = [];
2758
- const livesStr = `${t.muted("Buffer Lives:")} ${t.highlight("\u25BA ".repeat(Math.max(0, this.state.lives)))}`;
2759
- const surgeStr = this.state.frightenedTicksRemaining > 0 ? t.warning(`\u26A1 OVERCLOCK SURGE [${Math.ceil(this.state.frightenedTicksRemaining / 5)}s]`) : t.muted("NORMAL FLUX");
2760
- hudLines.push(` ${livesStr} ${surgeStr} ${t.muted("Pellets:")} ${t.primary(this.state.pelletsRemaining.toString())}`);
2761
- const boardLines = [];
2762
- for (let y = 0; y < MAZE_HEIGHT; y++) {
2763
- let row = " ";
2764
- for (let x = 0; x < MAZE_WIDTH; x++) {
2765
- if (x === this.state.playerX && y === this.state.playerY) {
2766
- const char = this.getPlayerGlyph();
2767
- row += t.highlight(char);
2768
- continue;
2769
- }
2770
- const daemon = this.daemons.find((d) => d.x === x && d.y === y);
2771
- if (daemon) {
2772
- row += this.getDaemonGlyph(daemon);
2773
- continue;
2774
- }
2775
- const tile = this.grid[y][x];
2776
- if (tile === "wall") {
2777
- row += t.border("\u2588\u2588");
2778
- } else if (tile === "pellet") {
2779
- row += t.primary(" \xB7");
2780
- } else if (tile === "power") {
2781
- row += t.accent(" \u25CF");
2782
- } else if (tile === "gate") {
2783
- row += t.secondary("\u2550\u2550");
2784
- } else {
2785
- row += " ";
2786
- }
2787
- }
2788
- boardLines.push(row);
2789
- }
2790
- if (this.state.isWon) {
2791
- boardLines.push(`
2792
- ${t.success("\u{1F389} MEMORY SECTOR COMPLETELY PURGED! EXCELLENT OPERATOR.")}`);
2793
- boardLines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
2794
- } else if (this.state.isGameOver) {
2795
- boardLines.push(`
2796
- ${t.error("\u{1F4A5} SYSTEM FAULT: LIVES DEPLETED. KERNEL DUMP.")}`);
2797
- boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Exit.")}`);
2798
- } else {
2799
- boardLines.push(`
2800
- ${t.muted("Controls: Arrows/WASD: Move \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
2801
- }
2802
- this.renderer.clear();
2803
- this.renderer.draw(`
2804
- ${header}
2805
- ${hudLines.join("\n")}
2806
- ${boardLines.join("\n")}
2807
- `);
2808
- }
2809
- getPlayerGlyph() {
2810
- if (!this.state.mouthOpen) return "\u25CB ";
2811
- if (this.state.playerDx === 1) return "\u25BA ";
2812
- if (this.state.playerDx === -1) return "\u25C4 ";
2813
- if (this.state.playerDy === -1) return "\u25B2 ";
2814
- if (this.state.playerDy === 1) return "\u25BC ";
2815
- return "\u25BA ";
2816
- }
2817
- getDaemonGlyph(d) {
2818
- const t = this.renderer.getTheme();
2819
- if (d.state === "frightened") {
2820
- if (this.state.frightenedTicksRemaining < 10 && this.state.frightenedTicksRemaining % 2 === 0) {
2821
- return t.accent("\xA7 ");
2822
- }
2823
- return t.secondary("\xA7 ");
2824
- }
2825
- if (d.state === "eaten") {
2826
- return t.muted('""');
2827
- }
2828
- if (d.colorName === "red") return t.error("M ");
2829
- if (d.colorName === "pink") return t.secondary("M ");
2830
- if (d.colorName === "cyan") return t.primary("M ");
2831
- return t.accent("M ");
2832
- }
2833
- getState() {
2834
- return this.state;
2835
- }
2836
- };
2837
-
2838
- // src/games/cyber-viper/index.ts
2839
- var GRID_WIDTH = 30;
2840
- var GRID_HEIGHT = 16;
2841
- var CyberViperGame = class {
2842
- id = "cyber-viper";
2843
- metadata = ALL_GAMES_METADATA["cyber-viper"];
2844
- config = null;
2845
- renderer = defaultRenderer;
2846
- input = new TerminalInputHandler();
2847
- rng = new DeterministicRNG();
2848
- gameLoopTimer = null;
2849
- state = {
2850
- snake: [
2851
- { x: 15, y: 8 },
2852
- { x: 14, y: 8 },
2853
- { x: 13, y: 8 }
2854
- ],
2855
- dx: 1,
2856
- dy: 0,
2857
- desiredDx: 1,
2858
- desiredDy: 0,
2859
- food: { x: 22, y: 8 },
2860
- goldenFood: null,
2861
- goldenFoodTicks: 0,
2862
- score: 0,
2863
- highScore: 0,
2864
- applesEaten: 0,
2865
- isGameOver: false,
2866
- isWon: false
2867
- };
2868
- isPaused = false;
2869
- pauseMenuIndex = 0;
2870
- showTutorial = true;
2871
- tickIntervalMs = 120;
2872
- init(config) {
2873
- this.config = config;
2874
- this.renderer.setTheme(config.theme);
2875
- this.rng = new DeterministicRNG(config.seed || Date.now());
2876
- if (config.skipTutorial !== void 0) {
2877
- this.showTutorial = !config.skipTutorial;
2878
- }
2879
- this.resetState(config.difficulty);
2880
- }
2881
- start() {
2882
- this.isPaused = false;
2883
- this.render();
2884
- this.input.start(
2885
- (key) => this.handleInput(key),
2886
- () => {
2887
- this.destroy();
2888
- process.exit(0);
2889
- }
2890
- );
2891
- this.scheduleNextTick();
2892
- }
2893
- pause() {
2894
- this.isPaused = true;
2895
- if (this.gameLoopTimer) {
2896
- clearTimeout(this.gameLoopTimer);
2897
- this.gameLoopTimer = null;
2898
- }
2899
- }
2900
- resume() {
2901
- this.isPaused = false;
2902
- this.scheduleNextTick();
2903
- this.render();
2904
- }
2905
- restart() {
2906
- if (this.config) {
2907
- this.resetState(this.config.difficulty);
2908
- this.scheduleNextTick();
2909
- this.render();
2910
- }
2911
- }
2912
- saveState() {
2913
- return {
2914
- state: this.state,
2915
- showTutorial: this.showTutorial
2916
- };
2917
- }
2918
- loadState(saved) {
2919
- if (saved["state"]) this.state = saved["state"];
2920
- if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
2921
- }
2922
- destroy() {
2923
- if (this.gameLoopTimer) {
2924
- clearTimeout(this.gameLoopTimer);
2925
- this.gameLoopTimer = null;
2926
- }
2927
- this.input.stop();
2928
- }
2929
- resetState(difficulty) {
2930
- switch (difficulty) {
2931
- case "easy":
2932
- this.tickIntervalMs = 160;
2933
- break;
2934
- case "normal":
2935
- this.tickIntervalMs = 120;
2936
- break;
2937
- case "hard":
2938
- this.tickIntervalMs = 85;
2939
- break;
2940
- case "insane":
2941
- this.tickIntervalMs = 55;
2942
- break;
2943
- }
2944
- this.state = {
2945
- snake: [
2946
- { x: 15, y: 8 },
2947
- { x: 14, y: 8 },
2948
- { x: 13, y: 8 }
2949
- ],
2950
- dx: 1,
2951
- dy: 0,
2952
- desiredDx: 1,
2953
- desiredDy: 0,
2954
- food: { x: 22, y: 8 },
2955
- goldenFood: null,
2956
- goldenFoodTicks: 0,
2957
- score: 0,
2958
- highScore: this.state.highScore,
2959
- applesEaten: 0,
2960
- isGameOver: false,
2961
- isWon: false
2962
- };
2963
- this.spawnFood();
2964
- }
2965
- scheduleNextTick() {
2966
- if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
2967
- if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
2968
- this.gameLoopTimer = setTimeout(() => {
2969
- this.tick();
2970
- this.scheduleNextTick();
2971
- }, this.tickIntervalMs);
2972
- }
2973
- tick() {
2974
- if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
2975
- if (this.state.desiredDx !== -this.state.dx || this.state.desiredDy !== -this.state.dy) {
2976
- this.state.dx = this.state.desiredDx;
2977
- this.state.dy = this.state.desiredDy;
2978
- }
2979
- const head = this.state.snake[0];
2980
- const newHead = {
2981
- x: head.x + this.state.dx,
2982
- y: head.y + this.state.dy
2983
- };
2984
- if (newHead.x < 0 || newHead.x >= GRID_WIDTH || newHead.y < 0 || newHead.y >= GRID_HEIGHT) {
2985
- this.state.isGameOver = true;
2986
- this.config?.onGameOver?.(this.state.score);
2987
- if (this.config?.soundEnabled) playTerminalBell();
2988
- this.render();
2989
- return;
2990
- }
2991
- for (let i = 0; i < this.state.snake.length - 1; i++) {
2992
- const seg = this.state.snake[i];
2993
- if (seg.x === newHead.x && seg.y === newHead.y) {
2994
- this.state.isGameOver = true;
2995
- this.config?.onGameOver?.(this.state.score);
2996
- if (this.config?.soundEnabled) playTerminalBell();
2997
- this.render();
2998
- return;
2999
- }
3000
- }
3001
- this.state.snake.unshift(newHead);
3002
- if (this.state.goldenFoodTicks > 0) {
3003
- this.state.goldenFoodTicks--;
3004
- if (this.state.goldenFoodTicks === 0) {
3005
- this.state.goldenFood = null;
3006
- }
3007
- }
3008
- let grew = false;
3009
- if (newHead.x === this.state.food.x && newHead.y === this.state.food.y) {
3010
- grew = true;
3011
- this.state.score += 100;
3012
- this.state.applesEaten++;
3013
- this.config?.onScoreUpdate?.(this.state.score);
3014
- this.config?.onAchievementUnlock?.("first_bite");
3015
- if (this.state.snake.length >= 25) {
3016
- this.config?.onAchievementUnlock?.("long_viper");
3017
- }
3018
- if (this.config?.soundEnabled) playTerminalBell();
3019
- this.spawnFood();
3020
- if (this.rng.next() < 0.25 && !this.state.goldenFood) {
3021
- this.spawnGoldenFood();
3022
- }
3023
- } else if (this.state.goldenFood && newHead.x === this.state.goldenFood.x && newHead.y === this.state.goldenFood.y) {
3024
- grew = true;
3025
- this.state.score += 500;
3026
- this.state.goldenFood = null;
3027
- this.state.goldenFoodTicks = 0;
3028
- this.config?.onScoreUpdate?.(this.state.score);
3029
- this.config?.onAchievementUnlock?.("golden_feast");
3030
- if (this.config?.soundEnabled) playTerminalBell();
3031
- }
3032
- if (!grew) {
3033
- this.state.snake.pop();
3034
- }
3035
- this.render();
3036
- }
3037
- spawnFood() {
3038
- const emptyCells = [];
3039
- for (let y = 0; y < GRID_HEIGHT; y++) {
3040
- for (let x = 0; x < GRID_WIDTH; x++) {
3041
- if (!this.state.snake.some((s) => s.x === x && s.y === y)) {
3042
- emptyCells.push({ x, y });
3043
- }
3044
- }
3045
- }
3046
- if (emptyCells.length > 0) {
3047
- this.state.food = this.rng.pick(emptyCells);
3048
- } else {
3049
- this.state.isWon = true;
3050
- }
3051
- }
3052
- spawnGoldenFood() {
3053
- const emptyCells = [];
3054
- for (let y = 0; y < GRID_HEIGHT; y++) {
3055
- for (let x = 0; x < GRID_WIDTH; x++) {
3056
- if (!this.state.snake.some((s) => s.x === x && s.y === y) && (x !== this.state.food.x || y !== this.state.food.y)) {
3057
- emptyCells.push({ x, y });
3058
- }
3059
- }
3060
- }
3061
- if (emptyCells.length > 0) {
3062
- this.state.goldenFood = this.rng.pick(emptyCells);
3063
- this.state.goldenFoodTicks = 70;
3064
- }
3065
- }
3066
- handleInput(key) {
3067
- if (this.showTutorial) {
3068
- if (key.name === "return" || key.name === "space") {
3069
- this.showTutorial = false;
3070
- this.scheduleNextTick();
3071
- this.render();
3072
- } else if (key.name === "escape" || key.name === "q") {
3073
- this.destroy();
3074
- this.config?.onExit?.();
3075
- }
3076
- return;
3077
- }
3078
- if (this.isPaused) {
3079
- if (key.name === "up" || key.name === "w") {
3080
- this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
3081
- this.render();
3082
- } else if (key.name === "down" || key.name === "s") {
3083
- this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
3084
- this.render();
3085
- } else if (key.name === "return" || key.name === "space") {
3086
- if (this.pauseMenuIndex === 0) {
3087
- this.isPaused = false;
3088
- this.scheduleNextTick();
3089
- this.render();
3090
- } else if (this.pauseMenuIndex === 1) {
3091
- this.isPaused = false;
3092
- this.resetState(this.config?.difficulty || "normal");
3093
- this.scheduleNextTick();
3094
- this.render();
3095
- } else if (this.pauseMenuIndex === 2) {
3096
- this.destroy();
3097
- this.config?.onExit?.();
3098
- }
3099
- } else if (key.name === "escape" || key.name === "p") {
3100
- this.isPaused = false;
3101
- this.scheduleNextTick();
3102
- this.render();
3103
- } else if (key.name === "q") {
3104
- this.destroy();
3105
- this.config?.onExit?.();
3106
- }
3107
- return;
3108
- }
3109
- if (key.name === "escape" || key.name === "p") {
3110
- this.isPaused = true;
3111
- this.pauseMenuIndex = 0;
3112
- if (this.gameLoopTimer) {
3113
- clearTimeout(this.gameLoopTimer);
3114
- this.gameLoopTimer = null;
3115
- }
3116
- this.render();
3117
- return;
3118
- }
3119
- if (key.name === "q") {
3120
- this.destroy();
3121
- this.config?.onExit?.();
3122
- return;
3123
- }
3124
- if (this.state.isGameOver) {
3125
- if (key.name === "r") {
3126
- this.restart();
3127
- } else if (key.name === "escape" || key.name === "q") {
3128
- this.destroy();
3129
- this.config?.onExit?.();
3130
- }
3131
- return;
3132
- }
3133
- if (key.name === "up" || key.name === "w") {
3134
- if (this.state.dy !== 1) {
3135
- this.state.desiredDx = 0;
3136
- this.state.desiredDy = -1;
3137
- }
3138
- } else if (key.name === "down" || key.name === "s") {
3139
- if (this.state.dy !== -1) {
3140
- this.state.desiredDx = 0;
3141
- this.state.desiredDy = 1;
3142
- }
3143
- } else if (key.name === "left" || key.name === "a") {
3144
- if (this.state.dx !== 1) {
3145
- this.state.desiredDx = -1;
3146
- this.state.desiredDy = 0;
3147
- }
3148
- } else if (key.name === "right" || key.name === "d") {
3149
- if (this.state.dx !== -1) {
3150
- this.state.desiredDx = 1;
3151
- this.state.desiredDy = 0;
3152
- }
3153
- }
3154
- }
3155
- render() {
3156
- const t = this.renderer.getTheme();
3157
- if (this.showTutorial) {
3158
- const lines = [
3159
- "",
3160
- t.highlight("OBJECTIVE: FEAST AND GROW THE CYBER VIPER"),
3161
- "",
3162
- "\u2022 Use Arrow Keys or WASD to steer the viper.",
3163
- "\u2022 Eat glowing Energy Apples [ \u25C6 ] to grow longer and gain +100 score.",
3164
- "\u2022 Snag rare Golden Orbs [ \u2605 ] before they vanish for +500 points!",
3165
- "\u2022 Do NOT crash into the grid borders or your own tail.",
3166
- "",
3167
- 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"),
3168
- t.primary("Press Space or Enter to launch \u2502 Esc / Q to Exit")
3169
- ];
3170
- const box = this.renderer.createBox(lines, 64, "CYBER VIPER MANUAL");
3171
- this.renderer.clear();
3172
- this.renderer.draw(`
3173
-
3174
- ${box}
3175
- `);
3176
- return;
3177
- }
3178
- if (this.isPaused) {
3179
- const pauseItems = ["Resume Viper (Esc / Enter)", "Restart Round (R)", "Quit to Arcade / Terminal (Q)"];
3180
- const pauseLines = [
3181
- "",
3182
- t.highlight("\u2550\u2550\u2550 VIPER RUN PAUSED \u2550\u2550\u2550"),
3183
- "",
3184
- ...pauseItems.map((item, idx) => {
3185
- if (idx === this.pauseMenuIndex) {
3186
- return t.primary(` \u25B6 ${t.highlight(item)}`);
3187
- }
3188
- return t.muted(` ${item}`);
3189
- }),
3190
- "",
3191
- 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"),
3192
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
3193
- ];
3194
- const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
3195
- this.renderer.clear();
3196
- this.renderer.draw(`
3197
-
3198
- ${pauseBox}
3199
- `);
3200
- return;
3201
- }
3202
- const header = this.renderer.renderHeader({
3203
- title: "CYBER VIPER",
3204
- category: "ARCADE",
3205
- difficulty: this.config?.difficulty,
3206
- score: this.state.score
3207
- });
3208
- const hudLines = [];
3209
- const lenStr = `${t.muted("Length:")} ${t.primary(this.state.snake.length.toString())}`;
3210
- const applesStr = `${t.muted("Apples:")} ${t.accent(this.state.applesEaten.toString())}`;
3211
- const goldStr = this.state.goldenFoodTicks > 0 ? t.warning(`\u2605 GOLDEN ORB ACTIVE [${Math.ceil(this.state.goldenFoodTicks / 10)}s]`) : "";
3212
- hudLines.push(` ${lenStr} ${applesStr} ${goldStr}`);
3213
- const boardLines = [];
3214
- boardLines.push(` ${t.border("\u2554" + "\u2550\u2550".repeat(GRID_WIDTH) + "\u2557")}`);
3215
- for (let y = 0; y < GRID_HEIGHT; y++) {
3216
- let row = ` ${t.border("\u2551")}`;
3217
- for (let x = 0; x < GRID_WIDTH; x++) {
3218
- if (x === this.state.snake[0].x && y === this.state.snake[0].y) {
3219
- row += t.highlight("\u25C6 ");
3220
- continue;
3221
- }
3222
- const isBody = this.state.snake.some((s, idx) => idx > 0 && s.x === x && s.y === y);
3223
- if (isBody) {
3224
- row += t.success("\u25A0 ");
3225
- continue;
3226
- }
3227
- if (x === this.state.food.x && y === this.state.food.y) {
3228
- row += t.error("\u25C6 ");
3229
- continue;
3230
- }
3231
- if (this.state.goldenFood && x === this.state.goldenFood.x && y === this.state.goldenFood.y) {
3232
- row += t.accent("\u2605 ");
3233
- continue;
3234
- }
3235
- row += " ";
3236
- }
3237
- row += t.border("\u2551");
3238
- boardLines.push(row);
3239
- }
3240
- boardLines.push(` ${t.border("\u255A" + "\u2550\u2550".repeat(GRID_WIDTH) + "\u255D")}`);
3241
- if (this.state.isGameOver) {
3242
- boardLines.push(`
3243
- ${t.error("\u{1F4A5} COLLISION! VIPER TERMINATED.")}`);
3244
- boardLines.push(` ${t.accent(`Final Length: ${this.state.snake.length} segments \u2502 Final Score: ${this.state.score}`)}`);
3245
- boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Exit.")}`);
3246
- } else {
3247
- boardLines.push(`
3248
- ${t.muted("Controls: Arrows/WASD: Steer \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
3249
- }
3250
- this.renderer.clear();
3251
- this.renderer.draw(`
3252
- ${header}
3253
- ${hudLines.join("\n")}
3254
- ${boardLines.join("\n")}
3255
- `);
3256
- }
3257
- getState() {
3258
- return this.state;
3259
- }
3260
- };
3261
-
3262
- export {
3263
- APP_NAME,
3264
- APP_TAGLINE,
3265
- APP_VERSION,
3266
- MIN_TERMINAL_COLUMNS,
3267
- MIN_TERMINAL_ROWS,
3268
- ALL_GAMES_METADATA,
3269
- UserSettingsSchema,
3270
- UserProfileSchema,
3271
- StorageManager,
3272
- defaultStorage,
3273
- AchievementManager,
3274
- defaultAchievements,
3275
- THEMES,
3276
- getTheme,
3277
- TerminalRenderer,
3278
- defaultRenderer,
3279
- TerminalInputHandler,
3280
- TerminullEngine,
3281
- defaultEngine,
3282
- checkTerminalDimensions,
3283
- playTerminalBell,
3284
- formatTime,
3285
- clamp,
3286
- padCenter,
3287
- ArcadeMenu,
3288
- DeterministicRNG,
3289
- NeonCircuitGame,
3290
- ByteRunnerGame,
3291
- PacketManGame,
3292
- CyberViperGame
3293
- };
3294
- //# sourceMappingURL=chunk-WCZVPTEK.js.map