terminull-arcade 0.0.0-stage → 1.0.0
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.
- package/LICENSE +9 -0
- package/README.md +82 -2
- package/dist/chunk-5CMAXV4B.js +2856 -0
- package/dist/chunk-5CMAXV4B.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +115 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +467 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -4
|
@@ -0,0 +1,2856 @@
|
|
|
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 memory labyrinths, chomp clean data bits, grab Super Capacitors, and hunt vulnerable daemons.",
|
|
15
|
+
category: "arcade",
|
|
16
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
17
|
+
controls: [
|
|
18
|
+
{ key: "Arrow Keys / WASD", action: "Direct Packet Man", description: "Navigate through memory grid" },
|
|
19
|
+
{ key: "Esc / P", action: "Pause Menu", description: "Open pause / exit dialog" },
|
|
20
|
+
{ key: "R", action: "Restart Game", description: "Restart from level 1" },
|
|
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
|
+
"neon-circuit": {
|
|
30
|
+
id: "neon-circuit",
|
|
31
|
+
name: "Neon Circuit",
|
|
32
|
+
tagline: "Route pure energy through cybernetic node grids",
|
|
33
|
+
description: "Grid puzzle: rotate circuit conduits to bridge power cores before capacity depletes.",
|
|
34
|
+
category: "puzzle",
|
|
35
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
36
|
+
controls: [
|
|
37
|
+
{ key: "Arrow Keys / WASD", action: "Navigate Grid", description: "Move circuit cursor" },
|
|
38
|
+
{ key: "Space / Enter", action: "Rotate Tile", description: "Rotate wire 90 degrees clockwise" },
|
|
39
|
+
{ key: "R", action: "Reset Grid", description: "Reset puzzle to initial state" },
|
|
40
|
+
{ key: "P / Esc", action: "Pause Menu", description: "Open pause dialog" }
|
|
41
|
+
],
|
|
42
|
+
achievements: [
|
|
43
|
+
{ id: "first_spark", title: "First Spark", description: "Complete your first circuit" },
|
|
44
|
+
{ id: "overclocked", title: "Overclocked Flow", description: "Complete a level with 5+ moves remaining" },
|
|
45
|
+
{ id: "grid_master", title: "Grid Overlord", description: "Solve an insane circuit puzzle" }
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"byte-runner": {
|
|
49
|
+
id: "byte-runner",
|
|
50
|
+
name: "Byte Runner",
|
|
51
|
+
tagline: "Sprint down the endless packet highway",
|
|
52
|
+
description: "Arcade runner: dodge fragmented corruptions, vacuum clean packets, and engage subroutines.",
|
|
53
|
+
category: "arcade",
|
|
54
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
55
|
+
controls: [
|
|
56
|
+
{ key: "Left / Right / A / D", action: "Change Lane", description: "Shift between data lanes" },
|
|
57
|
+
{ key: "Up / W / Space", action: "Phase Jump", description: "Hop over low corruptions" },
|
|
58
|
+
{ key: "Down / S", action: "Downlink Boost", description: "Dive fast or slide" },
|
|
59
|
+
{ key: "P / Esc", action: "Pause Menu", description: "Open pause dialog" }
|
|
60
|
+
],
|
|
61
|
+
achievements: [
|
|
62
|
+
{ id: "packet_chaser", title: "Packet Chaser", description: "Collect 50 clean byte clusters" },
|
|
63
|
+
{ id: "shield_matrix", title: "Hardened Buffer", description: "Absorb a collision with an active shield" },
|
|
64
|
+
{ id: "hyperspeed", title: "Fiber Velocity", description: "Reach a distance score over 5,000" }
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"terminal-typer": {
|
|
68
|
+
id: "terminal-typer",
|
|
69
|
+
name: "Terminal Typer",
|
|
70
|
+
tagline: "Type command scripts under time compression",
|
|
71
|
+
description: "Speed typing gauntlet featuring bash pipelines, system calls, and code syntaxes.",
|
|
72
|
+
category: "educational",
|
|
73
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
74
|
+
controls: [
|
|
75
|
+
{ key: "Keyboard", action: "Type Characters", description: "Input matching terminal tokens" },
|
|
76
|
+
{ key: "Backspace", action: "Erase Token", description: "Fix typographical mistakes" },
|
|
77
|
+
{ key: "Esc", action: "Abort Session", description: "Exit or pause typing trial" }
|
|
78
|
+
],
|
|
79
|
+
achievements: [
|
|
80
|
+
{ id: "prompt_novice", title: "Prompt Novice", description: "Achieve 40+ WPM with 95% accuracy" },
|
|
81
|
+
{ id: "bash_wizard", title: "Shell Maestro", description: "Type 100+ tokens without a typo" },
|
|
82
|
+
{ id: "laser_fingers", title: "Ghost Typist", description: "Break 90 WPM in survival mode" }
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"stack-overflow": {
|
|
86
|
+
id: "stack-overflow",
|
|
87
|
+
name: "Stack Overflow",
|
|
88
|
+
tagline: "Gravity-driven memory buffer management",
|
|
89
|
+
description: "Dynamic block sorting puzzle where volatile stack frames cascade with chain reactions.",
|
|
90
|
+
category: "puzzle",
|
|
91
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
92
|
+
controls: [
|
|
93
|
+
{ key: "Left / Right", action: "Move Frame", description: "Shift stack block horizontally" },
|
|
94
|
+
{ key: "Down", action: "Soft Drop", description: "Accelerate memory fall" },
|
|
95
|
+
{ key: "Space", action: "Hard Commit", description: "Instantly drop frame" },
|
|
96
|
+
{ key: "P / Esc", action: "Pause Menu", description: "Open pause dialog" }
|
|
97
|
+
],
|
|
98
|
+
achievements: [
|
|
99
|
+
{ id: "clean_stack", title: "Clean Stack", description: "Clear 4 memory lines simultaneously" },
|
|
100
|
+
{ id: "patch_master", title: "Hotfixer", description: "Neutralize 3 bug blocks" },
|
|
101
|
+
{ id: "buffer_hero", title: "Buffer Sovereign", description: "Score 10,000 in stack clearance" }
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"cipher-hunt": {
|
|
105
|
+
id: "cipher-hunt",
|
|
106
|
+
name: "Cipher Hunt",
|
|
107
|
+
tagline: "Cryptographic sleuth investigation cases",
|
|
108
|
+
description: "Decrypt encoded transcripts, Caesar shifts, and hex forensics across 20 dossier archives.",
|
|
109
|
+
category: "puzzle",
|
|
110
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
111
|
+
controls: [
|
|
112
|
+
{ key: "Tab / Arrows", action: "Select Glyph", description: "Navigate encrypted strings" },
|
|
113
|
+
{ key: "A-Z / 0-9", action: "Substitute", description: "Set plaintext hypothesis" },
|
|
114
|
+
{ key: "H", action: "Decrypt Hint", description: "Reveal partial key" },
|
|
115
|
+
{ key: "Esc", action: "Case File", description: "Return to dossiers" }
|
|
116
|
+
],
|
|
117
|
+
achievements: [
|
|
118
|
+
{ id: "first_clue", title: "Cipher Initiate", description: "Solve Case 01" },
|
|
119
|
+
{ id: "master_decoder", title: "Cryptanalyst", description: "Decode a message with 0 hints" },
|
|
120
|
+
{ id: "cold_case", title: "Archivist Prime", description: "Complete all 20 dossiers" }
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
"pixel-farm": {
|
|
124
|
+
id: "pixel-farm",
|
|
125
|
+
name: "Pixel Farm",
|
|
126
|
+
tagline: "Cultivate algorithmic soil and seasonal yields",
|
|
127
|
+
description: "Turn-based agricultural economy: balance moisture, harvest cyber-flora, and trade commodities.",
|
|
128
|
+
category: "strategy",
|
|
129
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
130
|
+
controls: [
|
|
131
|
+
{ key: "Arrow Keys", action: "Inspect Plot", description: "Move across farm coordinates" },
|
|
132
|
+
{ key: "P", action: "Plant Seed", description: "Sow current selected crop" },
|
|
133
|
+
{ key: "W", action: "Irrigate", description: "Water target soil parcel" },
|
|
134
|
+
{ key: "H", action: "Harvest", description: "Reap ripe crop" }
|
|
135
|
+
],
|
|
136
|
+
achievements: [
|
|
137
|
+
{ id: "green_byte", title: "Green Byte", description: "Harvest your first algorithmic crop" },
|
|
138
|
+
{ id: "market_mogul", title: "Market Mogul", description: "Accumulate 1,000 digital credits" },
|
|
139
|
+
{ id: "four_seasons", title: "Solstice Keeper", description: "Survive four complete seasonal cycles" }
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
"ghost-protocol": {
|
|
143
|
+
id: "ghost-protocol",
|
|
144
|
+
name: "Ghost Protocol",
|
|
145
|
+
tagline: "Infiltrate surveillance networks in silence",
|
|
146
|
+
description: "ASCII stealth labyrinth: navigate patrolling guard sensory cones, extract secrets, and vanish.",
|
|
147
|
+
category: "action",
|
|
148
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
149
|
+
controls: [
|
|
150
|
+
{ key: "WASD / Arrows", action: "Sneak Step", description: "Move agent in grid" },
|
|
151
|
+
{ key: "Shift + Move", action: "Sprint (Noisy)", description: "Move double distance with audio footprint" },
|
|
152
|
+
{ key: "E", action: "Extract Node", description: "Extract data drive from terminal" },
|
|
153
|
+
{ key: "P / Esc", action: "Tactical Pause", description: "Survey grid telemetry" }
|
|
154
|
+
],
|
|
155
|
+
achievements: [
|
|
156
|
+
{ id: "unseen_whisper", title: "Zero Trace", description: "Extract all data without detection" },
|
|
157
|
+
{ id: "phantom_agent", title: "Phantom Operative", description: "Complete floor in under 60 seconds" },
|
|
158
|
+
{ id: "black_ops", title: "Black Hat Ghost", description: "Survive on insane security protocols" }
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
"quantum-chess": {
|
|
162
|
+
id: "quantum-chess",
|
|
163
|
+
name: "Quantum Chess",
|
|
164
|
+
tagline: "Superposition tactics on a dual-state board",
|
|
165
|
+
description: "Chess variant where pieces inhabit multiple squares until observation collapses reality.",
|
|
166
|
+
category: "strategy",
|
|
167
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
168
|
+
controls: [
|
|
169
|
+
{ key: "Arrows / WASD", action: "Target Tile", description: "Hover board positions" },
|
|
170
|
+
{ key: "Enter / Space", action: "Select / Move", description: "Designate quantum split or standard step" },
|
|
171
|
+
{ key: "C", action: "Collapse State", description: "Force measurement on entangled pieces" },
|
|
172
|
+
{ key: "M", action: "Toggle Mode", description: "Toggle between Single and 2-Player" }
|
|
173
|
+
],
|
|
174
|
+
achievements: [
|
|
175
|
+
{ id: "schrodinger_gambit", title: "Schr\xF6dinger Gambit", description: "Split a piece into twin superpositions" },
|
|
176
|
+
{ id: "wave_collapse", title: "Decoherence", description: "Win a match via observation capture" },
|
|
177
|
+
{ id: "grandmaster_q", title: "Quantum Maestro", description: "Defeat the Deep State quantum engine" }
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
"bug-squash": {
|
|
181
|
+
id: "bug-squash",
|
|
182
|
+
name: "Bug Squash",
|
|
183
|
+
tagline: "Defend source trees from recursive infestation",
|
|
184
|
+
description: "Arcade exterminator: track bugs crawling over code files, deploy patches, and crush boss defects.",
|
|
185
|
+
category: "arcade",
|
|
186
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
187
|
+
controls: [
|
|
188
|
+
{ key: "Arrow Keys", action: "Target Reticle", description: "Move debugger pointer" },
|
|
189
|
+
{ key: "Space", action: "Deploy Patch", description: "Squash insect at crosshair" },
|
|
190
|
+
{ key: "B", action: "Breakpoint Bomb", description: "Clear all bugs in current scope" },
|
|
191
|
+
{ key: "P / Esc", action: "Pause Menu", description: "Pause debug session" }
|
|
192
|
+
],
|
|
193
|
+
achievements: [
|
|
194
|
+
{ id: "debugger_prime", title: "Zero Warnings", description: "Squash 50 runtime anomalies" },
|
|
195
|
+
{ id: "combo_streak", title: "Hex Striker", description: "Maintain a 10x elimination streak" },
|
|
196
|
+
{ id: "boss_squashed", title: "Null Pointer Slayer", description: "Defeat the Memory Leak Boss" }
|
|
197
|
+
]
|
|
198
|
+
},
|
|
199
|
+
"memory-matrix": {
|
|
200
|
+
id: "memory-matrix",
|
|
201
|
+
name: "Memory Matrix",
|
|
202
|
+
tagline: "Recall sensory sequences in cybernetic resonance",
|
|
203
|
+
description: "Choreographed recall challenge: echo complex terminal sound-and-symbol telemetry patterns.",
|
|
204
|
+
category: "puzzle",
|
|
205
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
206
|
+
controls: [
|
|
207
|
+
{ key: "1, 2, 3, 4 / Arrows", action: "Input Sector", description: "Replicate pulse quadrant" },
|
|
208
|
+
{ key: "Space", action: "Commit Sequence", description: "Finalize answer" },
|
|
209
|
+
{ key: "D", action: "Daily Seed", description: "Toggle Daily Challenge pattern" },
|
|
210
|
+
{ key: "P / Esc", action: "Pause Menu", description: "Open pause dialog" }
|
|
211
|
+
],
|
|
212
|
+
achievements: [
|
|
213
|
+
{ id: "perfect_recall", title: "Synaptic Link", description: "Reach sequence level 10" },
|
|
214
|
+
{ id: "daily_champ", title: "Daily Chronicler", description: "Conquer the daily matrix seed" },
|
|
215
|
+
{ id: "coop_harmony", title: "Twin Processors", description: "Complete a round in co-op mode" }
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
"space-salvage": {
|
|
219
|
+
id: "space-salvage",
|
|
220
|
+
name: "Space Salvage",
|
|
221
|
+
tagline: "Command derelict recovery in orbital graveyards",
|
|
222
|
+
description: "Strategic roguelite: balance crew oxygen, thermal levels, salvage weight, and rogue defense drones.",
|
|
223
|
+
category: "strategy",
|
|
224
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
225
|
+
controls: [
|
|
226
|
+
{ key: "1-5", action: "Order Crew", description: "Dispatch scavengers to bulkheads" },
|
|
227
|
+
{ key: "Space", action: "Next Turn", description: "Advance exploration tick" },
|
|
228
|
+
{ key: "J", action: "Jettison Cargo", description: "Lighten load for emergency thrusters" },
|
|
229
|
+
{ key: "Esc", action: "Status HUD", description: "Inspect ship schematics" }
|
|
230
|
+
],
|
|
231
|
+
achievements: [
|
|
232
|
+
{ id: "first_haul", title: "Scrap Scavenger", description: "Extract 500 tons of alloy" },
|
|
233
|
+
{ id: "full_crew_home", title: "No Drone Left Behind", description: "Reach station without casualties" },
|
|
234
|
+
{ id: "derelict_titan", title: "Ghost Fleet Sovereign", description: "Salvage a Class-5 flagship" }
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
"shell-quest": {
|
|
238
|
+
id: "shell-quest",
|
|
239
|
+
name: "Shell Quest",
|
|
240
|
+
tagline: "Master unix arcana across the command realm",
|
|
241
|
+
description: "Terminal RPG: wield grep, awk, git, and pipelines to overcome daemon bosses in simulated root.",
|
|
242
|
+
category: "educational",
|
|
243
|
+
difficultyLevels: ["easy", "normal", "hard", "insane"],
|
|
244
|
+
controls: [
|
|
245
|
+
{ key: "Input Line", action: "Type Shell Cmd", description: "Issue commands to bash interface" },
|
|
246
|
+
{ key: "Tab", action: "Autocomplete", description: "Complete paths and binaries" },
|
|
247
|
+
{ key: "Ctrl+L", action: "Clear Screen", description: "Clear adventure log output" },
|
|
248
|
+
{ key: "Esc / :q", action: "Exit Quest", description: "Return to portal" }
|
|
249
|
+
],
|
|
250
|
+
achievements: [
|
|
251
|
+
{ id: "sudo_apprentice", title: "UID Zero", description: "Attain root privileges in Area 1" },
|
|
252
|
+
{ id: "pipe_master", title: "Pipe Virtuoso", description: "Chasm puzzle cleared with 3+ pipes" },
|
|
253
|
+
{ id: "git_guru", title: "Rebase Conqueror", description: "Resolve the detached HEAD calamity" }
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/shared/types.ts
|
|
259
|
+
import { z } from "zod";
|
|
260
|
+
var UserSettingsSchema = z.object({
|
|
261
|
+
theme: z.enum(["default", "retro-green", "neon", "minimal", "high-contrast"]).default("default"),
|
|
262
|
+
soundEnabled: z.boolean().default(true),
|
|
263
|
+
reducedMotion: z.boolean().default(false),
|
|
264
|
+
colorblindMode: z.boolean().default(false)
|
|
265
|
+
});
|
|
266
|
+
var UserProfileSchema = z.object({
|
|
267
|
+
version: z.number().default(1),
|
|
268
|
+
createdAt: z.string(),
|
|
269
|
+
lastPlayedAt: z.string(),
|
|
270
|
+
settings: UserSettingsSchema,
|
|
271
|
+
highScores: z.record(z.string(), z.number()).default({}),
|
|
272
|
+
playCounts: z.record(z.string(), z.number()).default({}),
|
|
273
|
+
totalTimePlayedSec: z.record(z.string(), z.number()).default({}),
|
|
274
|
+
unlockedAchievements: z.record(z.string(), z.array(z.string())).default({}),
|
|
275
|
+
savedStates: z.record(z.string(), z.record(z.string(), z.unknown())).default({})
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// src/core/storage.ts
|
|
279
|
+
import fs from "fs";
|
|
280
|
+
import path from "path";
|
|
281
|
+
import os from "os";
|
|
282
|
+
var StorageManager = class {
|
|
283
|
+
configDir;
|
|
284
|
+
filePath;
|
|
285
|
+
cachedProfile = null;
|
|
286
|
+
constructor(customDir) {
|
|
287
|
+
this.configDir = customDir || path.join(os.homedir(), ".config", "terminull");
|
|
288
|
+
this.filePath = path.join(this.configDir, "profile.json");
|
|
289
|
+
}
|
|
290
|
+
getProfilePath() {
|
|
291
|
+
return this.filePath;
|
|
292
|
+
}
|
|
293
|
+
ensureDirectory() {
|
|
294
|
+
if (!fs.existsSync(this.configDir)) {
|
|
295
|
+
fs.mkdirSync(this.configDir, { recursive: true });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
getProfile() {
|
|
299
|
+
if (this.cachedProfile) {
|
|
300
|
+
return this.cachedProfile;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
this.ensureDirectory();
|
|
304
|
+
if (fs.existsSync(this.filePath)) {
|
|
305
|
+
const raw = fs.readFileSync(this.filePath, "utf-8");
|
|
306
|
+
const parsed = JSON.parse(raw);
|
|
307
|
+
const result = UserProfileSchema.safeParse(parsed);
|
|
308
|
+
if (result.success) {
|
|
309
|
+
this.cachedProfile = result.data;
|
|
310
|
+
return this.cachedProfile;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
const defaultProfile = {
|
|
316
|
+
version: 1,
|
|
317
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
318
|
+
lastPlayedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
319
|
+
settings: {
|
|
320
|
+
theme: "default",
|
|
321
|
+
soundEnabled: true,
|
|
322
|
+
reducedMotion: false,
|
|
323
|
+
colorblindMode: false
|
|
324
|
+
},
|
|
325
|
+
highScores: {},
|
|
326
|
+
playCounts: {},
|
|
327
|
+
totalTimePlayedSec: {},
|
|
328
|
+
unlockedAchievements: {},
|
|
329
|
+
savedStates: {}
|
|
330
|
+
};
|
|
331
|
+
this.saveProfile(defaultProfile);
|
|
332
|
+
this.cachedProfile = defaultProfile;
|
|
333
|
+
return defaultProfile;
|
|
334
|
+
}
|
|
335
|
+
saveProfile(profile) {
|
|
336
|
+
try {
|
|
337
|
+
this.ensureDirectory();
|
|
338
|
+
profile.lastPlayedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
339
|
+
fs.writeFileSync(this.filePath, JSON.stringify(profile, null, 2), "utf-8");
|
|
340
|
+
this.cachedProfile = profile;
|
|
341
|
+
} catch (err) {
|
|
342
|
+
console.error("Warning: Unable to save profile to disk:", err);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
recordScore(gameId, score) {
|
|
346
|
+
const profile = this.getProfile();
|
|
347
|
+
const currentHigh = profile.highScores[gameId] || 0;
|
|
348
|
+
const isNewHigh = score > currentHigh;
|
|
349
|
+
if (isNewHigh) {
|
|
350
|
+
profile.highScores[gameId] = score;
|
|
351
|
+
}
|
|
352
|
+
profile.playCounts[gameId] = (profile.playCounts[gameId] || 0) + 1;
|
|
353
|
+
this.saveProfile(profile);
|
|
354
|
+
return isNewHigh;
|
|
355
|
+
}
|
|
356
|
+
getHighScore(gameId) {
|
|
357
|
+
const profile = this.getProfile();
|
|
358
|
+
return profile.highScores[gameId] || 0;
|
|
359
|
+
}
|
|
360
|
+
addPlayTime(gameId, seconds) {
|
|
361
|
+
const profile = this.getProfile();
|
|
362
|
+
profile.totalTimePlayedSec[gameId] = (profile.totalTimePlayedSec[gameId] || 0) + seconds;
|
|
363
|
+
this.saveProfile(profile);
|
|
364
|
+
}
|
|
365
|
+
unlockAchievement(gameId, achievementId) {
|
|
366
|
+
const profile = this.getProfile();
|
|
367
|
+
const list = profile.unlockedAchievements[gameId] || [];
|
|
368
|
+
if (!list.includes(achievementId)) {
|
|
369
|
+
list.push(achievementId);
|
|
370
|
+
profile.unlockedAchievements[gameId] = list;
|
|
371
|
+
this.saveProfile(profile);
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
updateSettings(partialSettings) {
|
|
377
|
+
const profile = this.getProfile();
|
|
378
|
+
profile.settings = {
|
|
379
|
+
...profile.settings,
|
|
380
|
+
...partialSettings
|
|
381
|
+
};
|
|
382
|
+
this.saveProfile(profile);
|
|
383
|
+
return profile;
|
|
384
|
+
}
|
|
385
|
+
saveGameState(gameId, state) {
|
|
386
|
+
const profile = this.getProfile();
|
|
387
|
+
profile.savedStates[gameId] = state;
|
|
388
|
+
this.saveProfile(profile);
|
|
389
|
+
}
|
|
390
|
+
loadGameState(gameId) {
|
|
391
|
+
const profile = this.getProfile();
|
|
392
|
+
return profile.savedStates[gameId] || null;
|
|
393
|
+
}
|
|
394
|
+
resetProfile() {
|
|
395
|
+
const cleanProfile = {
|
|
396
|
+
version: 1,
|
|
397
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
398
|
+
lastPlayedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
399
|
+
settings: {
|
|
400
|
+
theme: "default",
|
|
401
|
+
soundEnabled: true,
|
|
402
|
+
reducedMotion: false,
|
|
403
|
+
colorblindMode: false
|
|
404
|
+
},
|
|
405
|
+
highScores: {},
|
|
406
|
+
playCounts: {},
|
|
407
|
+
totalTimePlayedSec: {},
|
|
408
|
+
unlockedAchievements: {},
|
|
409
|
+
savedStates: {}
|
|
410
|
+
};
|
|
411
|
+
this.saveProfile(cleanProfile);
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
var defaultStorage = new StorageManager();
|
|
415
|
+
|
|
416
|
+
// src/core/achievements.ts
|
|
417
|
+
var AchievementManager = class {
|
|
418
|
+
storage;
|
|
419
|
+
pendingNotifications = [];
|
|
420
|
+
constructor(storage = defaultStorage) {
|
|
421
|
+
this.storage = storage;
|
|
422
|
+
}
|
|
423
|
+
getAchievementsForGame(gameId) {
|
|
424
|
+
const meta = ALL_GAMES_METADATA[gameId];
|
|
425
|
+
if (!meta) return [];
|
|
426
|
+
const profile = this.storage.getProfile();
|
|
427
|
+
const unlockedIds = profile.unlockedAchievements[gameId] || [];
|
|
428
|
+
return meta.achievements.map((ach) => ({
|
|
429
|
+
achievement: ach,
|
|
430
|
+
unlocked: unlockedIds.includes(ach.id)
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
unlock(gameId, achievementId) {
|
|
434
|
+
const meta = ALL_GAMES_METADATA[gameId];
|
|
435
|
+
if (!meta) return false;
|
|
436
|
+
const ach = meta.achievements.find((a) => a.id === achievementId);
|
|
437
|
+
if (!ach) return false;
|
|
438
|
+
const newlyUnlocked = this.storage.unlockAchievement(gameId, achievementId);
|
|
439
|
+
if (newlyUnlocked) {
|
|
440
|
+
this.pendingNotifications.push({
|
|
441
|
+
gameId,
|
|
442
|
+
achievement: ach,
|
|
443
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
444
|
+
});
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
popNotifications() {
|
|
450
|
+
const list = [...this.pendingNotifications];
|
|
451
|
+
this.pendingNotifications = [];
|
|
452
|
+
return list;
|
|
453
|
+
}
|
|
454
|
+
getTotalStats() {
|
|
455
|
+
let totalCount = 0;
|
|
456
|
+
let unlockedCount = 0;
|
|
457
|
+
const profile = this.storage.getProfile();
|
|
458
|
+
for (const [gameId, meta] of Object.entries(ALL_GAMES_METADATA)) {
|
|
459
|
+
totalCount += meta.achievements.length;
|
|
460
|
+
const unlocked = profile.unlockedAchievements[gameId] || [];
|
|
461
|
+
unlockedCount += unlocked.length;
|
|
462
|
+
}
|
|
463
|
+
const percentage = totalCount > 0 ? Math.round(unlockedCount / totalCount * 100) : 0;
|
|
464
|
+
return { unlockedCount, totalCount, percentage };
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
var defaultAchievements = new AchievementManager();
|
|
468
|
+
|
|
469
|
+
// src/core/theme.ts
|
|
470
|
+
import chalk from "chalk";
|
|
471
|
+
var THEMES = {
|
|
472
|
+
default: {
|
|
473
|
+
name: "default",
|
|
474
|
+
displayName: "Cyberpunk Cyan/Magenta",
|
|
475
|
+
primary: (t) => chalk.cyanBright(t),
|
|
476
|
+
secondary: (t) => chalk.magentaBright(t),
|
|
477
|
+
accent: (t) => chalk.yellowBright(t),
|
|
478
|
+
muted: (t) => chalk.gray(t),
|
|
479
|
+
success: (t) => chalk.greenBright(t),
|
|
480
|
+
warning: (t) => chalk.yellow(t),
|
|
481
|
+
error: (t) => chalk.redBright(t),
|
|
482
|
+
highlight: (t) => chalk.bold.cyan(t),
|
|
483
|
+
border: (t) => chalk.cyan(t)
|
|
484
|
+
},
|
|
485
|
+
"retro-green": {
|
|
486
|
+
name: "retro-green",
|
|
487
|
+
displayName: "CRT Phosphor Green",
|
|
488
|
+
primary: (t) => chalk.greenBright(t),
|
|
489
|
+
secondary: (t) => chalk.green(t),
|
|
490
|
+
accent: (t) => chalk.whiteBright(t),
|
|
491
|
+
muted: (t) => chalk.hex("#1f5f1f")(t),
|
|
492
|
+
success: (t) => chalk.greenBright(t),
|
|
493
|
+
warning: (t) => chalk.hex("#7fff00")(t),
|
|
494
|
+
error: (t) => chalk.hex("#33ff33").underline(t),
|
|
495
|
+
highlight: (t) => chalk.bold.greenBright(t),
|
|
496
|
+
border: (t) => chalk.green(t)
|
|
497
|
+
},
|
|
498
|
+
neon: {
|
|
499
|
+
name: "neon",
|
|
500
|
+
displayName: "Electric Neon Violet",
|
|
501
|
+
primary: (t) => chalk.hex("#b829ea")(t),
|
|
502
|
+
secondary: (t) => chalk.hex("#00ffff")(t),
|
|
503
|
+
accent: (t) => chalk.hex("#ff007f")(t),
|
|
504
|
+
muted: (t) => chalk.hex("#555577")(t),
|
|
505
|
+
success: (t) => chalk.hex("#39ff14")(t),
|
|
506
|
+
warning: (t) => chalk.hex("#ffe600")(t),
|
|
507
|
+
error: (t) => chalk.hex("#ff073a")(t),
|
|
508
|
+
highlight: (t) => chalk.bold.hex("#00ffff")(t),
|
|
509
|
+
border: (t) => chalk.hex("#b829ea")(t)
|
|
510
|
+
},
|
|
511
|
+
minimal: {
|
|
512
|
+
name: "minimal",
|
|
513
|
+
displayName: "Monochrome Minimalist",
|
|
514
|
+
primary: (t) => chalk.whiteBright(t),
|
|
515
|
+
secondary: (t) => chalk.gray(t),
|
|
516
|
+
accent: (t) => chalk.white(t),
|
|
517
|
+
muted: (t) => chalk.hex("#444444")(t),
|
|
518
|
+
success: (t) => chalk.whiteBright(t),
|
|
519
|
+
warning: (t) => chalk.italic(t),
|
|
520
|
+
error: (t) => chalk.underline(t),
|
|
521
|
+
highlight: (t) => chalk.bold.white(t),
|
|
522
|
+
border: (t) => chalk.gray(t)
|
|
523
|
+
},
|
|
524
|
+
"high-contrast": {
|
|
525
|
+
name: "high-contrast",
|
|
526
|
+
displayName: "Accessibility High Contrast",
|
|
527
|
+
primary: (t) => chalk.yellowBright(t),
|
|
528
|
+
secondary: (t) => chalk.cyanBright(t),
|
|
529
|
+
accent: (t) => chalk.whiteBright(t),
|
|
530
|
+
muted: (t) => chalk.white(t),
|
|
531
|
+
success: (t) => chalk.bold.greenBright(t),
|
|
532
|
+
warning: (t) => chalk.bold.yellowBright(t),
|
|
533
|
+
error: (t) => chalk.bold.redBright(t),
|
|
534
|
+
highlight: (t) => chalk.bold.underline.yellowBright(t),
|
|
535
|
+
border: (t) => chalk.yellowBright(t)
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
function getTheme(themeName = "default") {
|
|
539
|
+
return THEMES[themeName] || THEMES.default;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/core/renderer.ts
|
|
543
|
+
var TerminalRenderer = class {
|
|
544
|
+
inAltBuffer = false;
|
|
545
|
+
currentTheme = getTheme("default");
|
|
546
|
+
setTheme(themeName) {
|
|
547
|
+
this.currentTheme = getTheme(themeName);
|
|
548
|
+
}
|
|
549
|
+
getTheme() {
|
|
550
|
+
return this.currentTheme;
|
|
551
|
+
}
|
|
552
|
+
enterScreen() {
|
|
553
|
+
if (!this.inAltBuffer && process.stdout.isTTY) {
|
|
554
|
+
process.stdout.write("\x1B[?1049h\x1B[?25l\x1B[2J\x1B[H");
|
|
555
|
+
this.inAltBuffer = true;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
exitScreen() {
|
|
559
|
+
if (this.inAltBuffer && process.stdout.isTTY) {
|
|
560
|
+
process.stdout.write("\x1B[?25h\x1B[?1049l");
|
|
561
|
+
this.inAltBuffer = false;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
clear() {
|
|
565
|
+
if (process.stdout.isTTY) {
|
|
566
|
+
process.stdout.write("\x1B[2J\x1B[H");
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
draw(content) {
|
|
570
|
+
process.stdout.write(`\x1B[H${content}`);
|
|
571
|
+
}
|
|
572
|
+
isWindowAdequate() {
|
|
573
|
+
const width = process.stdout.columns || 80;
|
|
574
|
+
const height = process.stdout.rows || 24;
|
|
575
|
+
return {
|
|
576
|
+
adequate: width >= MIN_TERMINAL_COLUMNS && height >= MIN_TERMINAL_ROWS,
|
|
577
|
+
width,
|
|
578
|
+
height
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
renderSizeWarning() {
|
|
582
|
+
const { width, height } = this.isWindowAdequate();
|
|
583
|
+
const t = this.currentTheme;
|
|
584
|
+
return `
|
|
585
|
+
${t.warning("\u26A0\uFE0F TERMINAL WINDOW TOO COMPACT")}
|
|
586
|
+
|
|
587
|
+
Current: ${t.error(`${width} x ${height}`)}
|
|
588
|
+
Required: ${t.success(`${MIN_TERMINAL_COLUMNS} x ${MIN_TERMINAL_ROWS}`)}
|
|
589
|
+
|
|
590
|
+
${t.muted("Please enlarge your terminal window or reduce zoom.")}
|
|
591
|
+
`;
|
|
592
|
+
}
|
|
593
|
+
createBox(lines, width = 76, title = "") {
|
|
594
|
+
const t = this.currentTheme;
|
|
595
|
+
const topBarLen = Math.max(0, width - 4 - (title ? title.length + 2 : 0));
|
|
596
|
+
const titleSection = title ? ` ${t.primary(title)} ` : "";
|
|
597
|
+
const top = t.border(`\u250C\u2500${titleSection}${"\u2500".repeat(topBarLen)}\u2510`);
|
|
598
|
+
const bottom = t.border(`\u2514${"\u2500".repeat(width - 2)}\u2518`);
|
|
599
|
+
const middle = lines.map((line) => {
|
|
600
|
+
const cleanLen = line.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
601
|
+
const padLen = Math.max(0, width - 4 - cleanLen);
|
|
602
|
+
return `${t.border("\u2502")} ${line}${" ".repeat(padLen)}${t.border("\u2502")}`;
|
|
603
|
+
});
|
|
604
|
+
return [top, ...middle, bottom].join("\n");
|
|
605
|
+
}
|
|
606
|
+
renderHeader(options) {
|
|
607
|
+
const t = this.currentTheme;
|
|
608
|
+
const cols = Math.min(process.stdout.columns || 80, 80);
|
|
609
|
+
const leftPart = `${t.highlight(options.title)} ${options.category ? t.muted(`[${options.category.toUpperCase()}]`) : ""}`;
|
|
610
|
+
const diffPart = options.difficulty ? t.secondary(`DIFF: ${options.difficulty.toUpperCase()}`) : "";
|
|
611
|
+
const scorePart = options.score !== void 0 ? t.primary(`SCORE: ${options.score}`) : "";
|
|
612
|
+
const highPart = options.highScore !== void 0 ? t.accent(`BEST: ${options.highScore}`) : "";
|
|
613
|
+
const stats = [diffPart, scorePart, highPart].filter(Boolean).join(" \u2502 ");
|
|
614
|
+
const cleanLeft = leftPart.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
615
|
+
const cleanRight = stats.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
616
|
+
const spaceCount = Math.max(2, cols - cleanLeft - cleanRight - 2);
|
|
617
|
+
return `
|
|
618
|
+
${leftPart}${" ".repeat(spaceCount)}${stats}
|
|
619
|
+
${t.border("\u2500".repeat(cols - 4))}
|
|
620
|
+
`;
|
|
621
|
+
}
|
|
622
|
+
renderFooter(instructions) {
|
|
623
|
+
const t = this.currentTheme;
|
|
624
|
+
const cols = Math.min(process.stdout.columns || 80, 80);
|
|
625
|
+
return `
|
|
626
|
+
${t.border("\u2500".repeat(cols - 4))}
|
|
627
|
+
${t.muted(instructions)}
|
|
628
|
+
`;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
var defaultRenderer = new TerminalRenderer();
|
|
632
|
+
|
|
633
|
+
// src/core/input.ts
|
|
634
|
+
import readline from "readline";
|
|
635
|
+
var TerminalInputHandler = class {
|
|
636
|
+
isListening = false;
|
|
637
|
+
keyPressCallback = null;
|
|
638
|
+
onExitCallback = null;
|
|
639
|
+
constructor() {
|
|
640
|
+
this.handleKeypress = this.handleKeypress.bind(this);
|
|
641
|
+
}
|
|
642
|
+
start(onKey, onExit) {
|
|
643
|
+
if (this.isListening) return;
|
|
644
|
+
this.keyPressCallback = onKey;
|
|
645
|
+
this.onExitCallback = onExit || null;
|
|
646
|
+
if (process.stdin.isTTY) {
|
|
647
|
+
process.stdin.setRawMode(true);
|
|
648
|
+
process.stdin.resume();
|
|
649
|
+
readline.emitKeypressEvents(process.stdin);
|
|
650
|
+
process.stdin.on("keypress", this.handleKeypress);
|
|
651
|
+
this.isListening = true;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
stop() {
|
|
655
|
+
if (!this.isListening) return;
|
|
656
|
+
if (process.stdin.isTTY) {
|
|
657
|
+
process.stdin.removeListener("keypress", this.handleKeypress);
|
|
658
|
+
process.stdin.setRawMode(false);
|
|
659
|
+
process.stdin.pause();
|
|
660
|
+
}
|
|
661
|
+
this.isListening = false;
|
|
662
|
+
this.keyPressCallback = null;
|
|
663
|
+
this.onExitCallback = null;
|
|
664
|
+
}
|
|
665
|
+
handleKeypress(_ch, key) {
|
|
666
|
+
if (!key) return;
|
|
667
|
+
if (key.ctrl && key.name === "c") {
|
|
668
|
+
this.stop();
|
|
669
|
+
if (this.onExitCallback) {
|
|
670
|
+
this.onExitCallback();
|
|
671
|
+
} else {
|
|
672
|
+
process.stdout.write("\x1B[?25h\x1B[0m\n");
|
|
673
|
+
process.exit(0);
|
|
674
|
+
}
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
if (this.keyPressCallback) {
|
|
678
|
+
this.keyPressCallback({
|
|
679
|
+
name: key.name || "",
|
|
680
|
+
ctrl: !!key.ctrl,
|
|
681
|
+
shift: !!key.shift,
|
|
682
|
+
meta: !!key.meta,
|
|
683
|
+
sequence: key.sequence || ""
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/core/engine.ts
|
|
690
|
+
var TerminullEngine = class {
|
|
691
|
+
gamesRegistry = /* @__PURE__ */ new Map();
|
|
692
|
+
activeGame = null;
|
|
693
|
+
storage;
|
|
694
|
+
achievements;
|
|
695
|
+
renderer;
|
|
696
|
+
input;
|
|
697
|
+
isPaused = false;
|
|
698
|
+
pauseMenuIndex = 0;
|
|
699
|
+
currentDifficulty = "normal";
|
|
700
|
+
sessionStartTime = 0;
|
|
701
|
+
onQuitToMenuCallback;
|
|
702
|
+
constructor(storage = defaultStorage, achievements = defaultAchievements, renderer = defaultRenderer) {
|
|
703
|
+
this.storage = storage;
|
|
704
|
+
this.achievements = achievements;
|
|
705
|
+
this.renderer = renderer;
|
|
706
|
+
this.input = new TerminalInputHandler();
|
|
707
|
+
if (process.stdout.on) {
|
|
708
|
+
process.stdout.on("resize", () => {
|
|
709
|
+
if (this.activeGame && !this.isPaused) {
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
registerGame(id, factory) {
|
|
715
|
+
this.gamesRegistry.set(id, factory);
|
|
716
|
+
}
|
|
717
|
+
getRegisteredGames() {
|
|
718
|
+
return Array.from(this.gamesRegistry.keys());
|
|
719
|
+
}
|
|
720
|
+
launchGame(id, difficulty = "normal", events) {
|
|
721
|
+
const factory = this.gamesRegistry.get(id);
|
|
722
|
+
if (!factory) {
|
|
723
|
+
console.error(`Error: Game '${id}' is not yet installed or registered.`);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
this.onQuitToMenuCallback = events?.onQuitToMenu;
|
|
727
|
+
this.currentDifficulty = difficulty;
|
|
728
|
+
this.activeGame = factory();
|
|
729
|
+
const profile = this.storage.getProfile();
|
|
730
|
+
const themeName = profile.settings.theme;
|
|
731
|
+
this.renderer.setTheme(themeName);
|
|
732
|
+
this.renderer.enterScreen();
|
|
733
|
+
this.isPaused = false;
|
|
734
|
+
this.sessionStartTime = Date.now();
|
|
735
|
+
this.activeGame.init({
|
|
736
|
+
difficulty,
|
|
737
|
+
theme: themeName,
|
|
738
|
+
soundEnabled: profile.settings.soundEnabled,
|
|
739
|
+
reducedMotion: profile.settings.reducedMotion,
|
|
740
|
+
onExit: () => {
|
|
741
|
+
this.quitGame();
|
|
742
|
+
},
|
|
743
|
+
onScoreUpdate: (score) => {
|
|
744
|
+
this.storage.recordScore(id, score);
|
|
745
|
+
},
|
|
746
|
+
onGameOver: (finalScore) => {
|
|
747
|
+
this.storage.recordScore(id, finalScore);
|
|
748
|
+
const elapsedSec = Math.round((Date.now() - this.sessionStartTime) / 1e3);
|
|
749
|
+
this.storage.addPlayTime(id, elapsedSec);
|
|
750
|
+
},
|
|
751
|
+
onAchievementUnlock: (achId) => {
|
|
752
|
+
this.achievements.unlock(id, achId);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
this.activeGame.start();
|
|
756
|
+
}
|
|
757
|
+
togglePause() {
|
|
758
|
+
if (!this.activeGame) return;
|
|
759
|
+
if (!this.isPaused) {
|
|
760
|
+
this.isPaused = true;
|
|
761
|
+
this.activeGame.pause();
|
|
762
|
+
this.pauseMenuIndex = 0;
|
|
763
|
+
this.renderPauseMenu();
|
|
764
|
+
} else {
|
|
765
|
+
this.isPaused = false;
|
|
766
|
+
this.activeGame.resume();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
renderPauseMenu() {
|
|
770
|
+
const t = this.renderer.getTheme();
|
|
771
|
+
const items = [
|
|
772
|
+
"Resume Game",
|
|
773
|
+
"Restart Round",
|
|
774
|
+
`Difficulty: [ ${this.currentDifficulty.toUpperCase()} ]`,
|
|
775
|
+
"Quit to Arcade Menu"
|
|
776
|
+
];
|
|
777
|
+
const lines = [
|
|
778
|
+
"",
|
|
779
|
+
t.highlight("\u2550\u2550\u2550 PAUSE SUBROUTINE \u2550\u2550\u2550"),
|
|
780
|
+
"",
|
|
781
|
+
...items.map((item, idx) => {
|
|
782
|
+
if (idx === this.pauseMenuIndex) {
|
|
783
|
+
return t.primary(` \u25B6 ${t.highlight(item)}`);
|
|
784
|
+
}
|
|
785
|
+
return t.muted(` ${item}`);
|
|
786
|
+
}),
|
|
787
|
+
"",
|
|
788
|
+
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"),
|
|
789
|
+
t.muted("Use Up/Down to navigate, Enter to select, P to resume")
|
|
790
|
+
];
|
|
791
|
+
const box = this.renderer.createBox(lines, 60, "SYSTEM HALT");
|
|
792
|
+
this.renderer.draw(`
|
|
793
|
+
|
|
794
|
+
${box}`);
|
|
795
|
+
}
|
|
796
|
+
handlePauseInput(keyName) {
|
|
797
|
+
if (keyName === "up" || keyName === "w") {
|
|
798
|
+
this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 4) % 4;
|
|
799
|
+
this.renderPauseMenu();
|
|
800
|
+
} else if (keyName === "down" || keyName === "s") {
|
|
801
|
+
this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 4;
|
|
802
|
+
this.renderPauseMenu();
|
|
803
|
+
} else if (keyName === "return" || keyName === "space") {
|
|
804
|
+
if (this.pauseMenuIndex === 0) {
|
|
805
|
+
this.togglePause();
|
|
806
|
+
} else if (this.pauseMenuIndex === 1) {
|
|
807
|
+
this.isPaused = false;
|
|
808
|
+
this.activeGame?.restart();
|
|
809
|
+
} else if (this.pauseMenuIndex === 2) {
|
|
810
|
+
const diffs = ["easy", "normal", "hard", "insane"];
|
|
811
|
+
const currIdx = diffs.indexOf(this.currentDifficulty);
|
|
812
|
+
this.currentDifficulty = diffs[(currIdx + 1) % diffs.length];
|
|
813
|
+
this.renderPauseMenu();
|
|
814
|
+
} else if (this.pauseMenuIndex === 3) {
|
|
815
|
+
this.quitGame();
|
|
816
|
+
}
|
|
817
|
+
} else if (keyName === "p" || keyName === "escape") {
|
|
818
|
+
this.togglePause();
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
quitGame() {
|
|
822
|
+
if (this.activeGame) {
|
|
823
|
+
const elapsedSec = Math.round((Date.now() - this.sessionStartTime) / 1e3);
|
|
824
|
+
this.storage.addPlayTime(this.activeGame.id, elapsedSec);
|
|
825
|
+
this.activeGame.destroy();
|
|
826
|
+
this.activeGame = null;
|
|
827
|
+
}
|
|
828
|
+
this.isPaused = false;
|
|
829
|
+
this.renderer.exitScreen();
|
|
830
|
+
if (this.onQuitToMenuCallback) {
|
|
831
|
+
this.onQuitToMenuCallback();
|
|
832
|
+
} else {
|
|
833
|
+
process.exit(0);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
getActiveGame() {
|
|
837
|
+
return this.activeGame;
|
|
838
|
+
}
|
|
839
|
+
isGamePaused() {
|
|
840
|
+
return this.isPaused;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
var defaultEngine = new TerminullEngine();
|
|
844
|
+
|
|
845
|
+
// src/shared/utils.ts
|
|
846
|
+
function checkTerminalDimensions() {
|
|
847
|
+
const cols = process.stdout.columns || 80;
|
|
848
|
+
const rows = process.stdout.rows || 24;
|
|
849
|
+
return {
|
|
850
|
+
adequate: cols >= MIN_TERMINAL_COLUMNS && rows >= MIN_TERMINAL_ROWS,
|
|
851
|
+
cols,
|
|
852
|
+
rows,
|
|
853
|
+
minCols: MIN_TERMINAL_COLUMNS,
|
|
854
|
+
minRows: MIN_TERMINAL_ROWS
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
function playTerminalBell(enabled = true) {
|
|
858
|
+
if (enabled && process.stdout.isTTY) {
|
|
859
|
+
process.stdout.write("\x07");
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function formatTime(seconds) {
|
|
863
|
+
const mins = Math.floor(seconds / 60);
|
|
864
|
+
const secs = Math.floor(seconds % 60);
|
|
865
|
+
return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
|
|
866
|
+
}
|
|
867
|
+
function clamp(val, min, max) {
|
|
868
|
+
return Math.max(min, Math.min(max, val));
|
|
869
|
+
}
|
|
870
|
+
function padCenter(str, width) {
|
|
871
|
+
if (str.length >= width) return str.slice(0, width);
|
|
872
|
+
const left = Math.floor((width - str.length) / 2);
|
|
873
|
+
const right = width - str.length - left;
|
|
874
|
+
return " ".repeat(left) + str + " ".repeat(right);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/core/menu.ts
|
|
878
|
+
var ArcadeMenu = class {
|
|
879
|
+
storage;
|
|
880
|
+
achievements;
|
|
881
|
+
renderer;
|
|
882
|
+
input;
|
|
883
|
+
selectedIndex = 0;
|
|
884
|
+
searchQuery = "";
|
|
885
|
+
isSearching = false;
|
|
886
|
+
currentTab = "arcade";
|
|
887
|
+
selectedDifficulty = "normal";
|
|
888
|
+
onSelectCallback = null;
|
|
889
|
+
constructor(storage = defaultStorage, achievements = defaultAchievements, renderer = defaultRenderer) {
|
|
890
|
+
this.storage = storage;
|
|
891
|
+
this.achievements = achievements;
|
|
892
|
+
this.renderer = renderer;
|
|
893
|
+
this.input = new TerminalInputHandler();
|
|
894
|
+
}
|
|
895
|
+
open(onSelect) {
|
|
896
|
+
this.onSelectCallback = onSelect;
|
|
897
|
+
const profile = this.storage.getProfile();
|
|
898
|
+
this.renderer.setTheme(profile.settings.theme);
|
|
899
|
+
this.renderer.enterScreen();
|
|
900
|
+
this.render();
|
|
901
|
+
this.input.start(
|
|
902
|
+
(key) => this.handleInput(key),
|
|
903
|
+
() => {
|
|
904
|
+
this.renderer.exitScreen();
|
|
905
|
+
process.exit(0);
|
|
906
|
+
}
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
close() {
|
|
910
|
+
this.input.stop();
|
|
911
|
+
this.renderer.exitScreen();
|
|
912
|
+
}
|
|
913
|
+
getFilteredGames() {
|
|
914
|
+
const all = Object.values(ALL_GAMES_METADATA);
|
|
915
|
+
if (!this.searchQuery.trim()) return all;
|
|
916
|
+
const q = this.searchQuery.toLowerCase();
|
|
917
|
+
return all.filter(
|
|
918
|
+
(g) => g.name.toLowerCase().includes(q) || g.category.toLowerCase().includes(q) || g.id.toLowerCase().includes(q) || g.description.toLowerCase().includes(q)
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
handleInput(key) {
|
|
922
|
+
const filtered = this.getFilteredGames();
|
|
923
|
+
if (this.isSearching) {
|
|
924
|
+
if (key.name === "return" || key.name === "escape") {
|
|
925
|
+
this.isSearching = false;
|
|
926
|
+
} else if (key.name === "backspace") {
|
|
927
|
+
this.searchQuery = this.searchQuery.slice(0, -1);
|
|
928
|
+
this.selectedIndex = 0;
|
|
929
|
+
} else if (key.sequence && key.sequence.length === 1 && !key.name) {
|
|
930
|
+
this.searchQuery += key.sequence;
|
|
931
|
+
this.selectedIndex = 0;
|
|
932
|
+
}
|
|
933
|
+
this.render();
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (key.name === "tab") {
|
|
937
|
+
const tabs = ["arcade", "stats", "settings"];
|
|
938
|
+
const nextIdx = (tabs.indexOf(this.currentTab) + 1) % tabs.length;
|
|
939
|
+
this.currentTab = tabs[nextIdx];
|
|
940
|
+
this.render();
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
if (this.currentTab === "arcade") {
|
|
944
|
+
if (key.name === "up" || key.name === "k") {
|
|
945
|
+
this.selectedIndex = (this.selectedIndex - 1 + filtered.length) % Math.max(1, filtered.length);
|
|
946
|
+
this.render();
|
|
947
|
+
} else if (key.name === "down" || key.name === "j") {
|
|
948
|
+
this.selectedIndex = (this.selectedIndex + 1) % Math.max(1, filtered.length);
|
|
949
|
+
this.render();
|
|
950
|
+
} else if (key.name === "d") {
|
|
951
|
+
const diffs = ["easy", "normal", "hard", "insane"];
|
|
952
|
+
const curr = diffs.indexOf(this.selectedDifficulty);
|
|
953
|
+
this.selectedDifficulty = diffs[(curr + 1) % diffs.length];
|
|
954
|
+
this.render();
|
|
955
|
+
} else if (key.name === "slash" || key.sequence === "/") {
|
|
956
|
+
this.isSearching = true;
|
|
957
|
+
this.render();
|
|
958
|
+
} else if (key.name === "return" || key.name === "space") {
|
|
959
|
+
const game = filtered[this.selectedIndex];
|
|
960
|
+
if (game && this.onSelectCallback) {
|
|
961
|
+
this.input.stop();
|
|
962
|
+
this.onSelectCallback({
|
|
963
|
+
action: "play",
|
|
964
|
+
gameId: game.id,
|
|
965
|
+
difficulty: this.selectedDifficulty
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
} else if (key.name === "q") {
|
|
969
|
+
this.close();
|
|
970
|
+
if (this.onSelectCallback) {
|
|
971
|
+
this.onSelectCallback({ action: "quit" });
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
} else if (this.currentTab === "settings") {
|
|
975
|
+
if (key.name === "t") {
|
|
976
|
+
const themes = ["default", "retro-green", "neon", "minimal", "high-contrast"];
|
|
977
|
+
const profile = this.storage.getProfile();
|
|
978
|
+
const currIdx = themes.indexOf(profile.settings.theme);
|
|
979
|
+
const nextTheme = themes[(currIdx + 1) % themes.length];
|
|
980
|
+
this.storage.updateSettings({ theme: nextTheme });
|
|
981
|
+
this.renderer.setTheme(nextTheme);
|
|
982
|
+
this.render();
|
|
983
|
+
} else if (key.name === "b") {
|
|
984
|
+
const profile = this.storage.getProfile();
|
|
985
|
+
this.storage.updateSettings({ soundEnabled: !profile.settings.soundEnabled });
|
|
986
|
+
this.render();
|
|
987
|
+
} else if (key.name === "m") {
|
|
988
|
+
const profile = this.storage.getProfile();
|
|
989
|
+
this.storage.updateSettings({ reducedMotion: !profile.settings.reducedMotion });
|
|
990
|
+
this.render();
|
|
991
|
+
} else if (key.name === "escape") {
|
|
992
|
+
this.currentTab = "arcade";
|
|
993
|
+
this.render();
|
|
994
|
+
}
|
|
995
|
+
} else if (this.currentTab === "stats") {
|
|
996
|
+
if (key.name === "escape" || key.name === "return") {
|
|
997
|
+
this.currentTab = "arcade";
|
|
998
|
+
this.render();
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
render() {
|
|
1003
|
+
const t = this.renderer.getTheme();
|
|
1004
|
+
const { width, height } = this.renderer.isWindowAdequate();
|
|
1005
|
+
if (width < 80 || height < 24) {
|
|
1006
|
+
this.renderer.clear();
|
|
1007
|
+
this.renderer.draw(this.renderer.renderSizeWarning());
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
let body = "";
|
|
1011
|
+
if (this.currentTab === "arcade") {
|
|
1012
|
+
body = this.renderArcadeTab();
|
|
1013
|
+
} else if (this.currentTab === "stats") {
|
|
1014
|
+
body = this.renderStatsTab();
|
|
1015
|
+
} else if (this.currentTab === "settings") {
|
|
1016
|
+
body = this.renderSettingsTab();
|
|
1017
|
+
}
|
|
1018
|
+
this.renderer.clear();
|
|
1019
|
+
this.renderer.draw(body);
|
|
1020
|
+
}
|
|
1021
|
+
renderArcadeTab() {
|
|
1022
|
+
const t = this.renderer.getTheme();
|
|
1023
|
+
const filtered = this.getFilteredGames();
|
|
1024
|
+
const activeGame = filtered[this.selectedIndex];
|
|
1025
|
+
const profile = this.storage.getProfile();
|
|
1026
|
+
const banner = [
|
|
1027
|
+
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 `),
|
|
1028
|
+
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 `),
|
|
1029
|
+
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 `),
|
|
1030
|
+
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 `),
|
|
1031
|
+
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`),
|
|
1032
|
+
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`),
|
|
1033
|
+
` ${t.accent(APP_TAGLINE)} \u2502 ${t.muted("Tab: Switch Views \u2502 /: Search \u2502 Q: Quit")}`,
|
|
1034
|
+
` ${t.border("\u2500".repeat(74))}`
|
|
1035
|
+
].join("\n");
|
|
1036
|
+
const tabs = ` ${t.highlight("[ 1. ARCADE ]")} ${t.muted("[ 2. STATS (Tab) ]")} ${t.muted("[ 3. SETTINGS (Tab) ]")}
|
|
1037
|
+
`;
|
|
1038
|
+
const searchBar = this.isSearching ? ` ${t.warning("SEARCH >")} ${this.searchQuery}\u2588
|
|
1039
|
+
` : this.searchQuery ? ` ${t.muted("Filtered by:")} "${this.searchQuery}" (Press / to edit)
|
|
1040
|
+
` : "";
|
|
1041
|
+
const listLines = [];
|
|
1042
|
+
const maxVisible = 10;
|
|
1043
|
+
const startIndex = Math.max(0, Math.min(this.selectedIndex - 4, filtered.length - maxVisible));
|
|
1044
|
+
const visibleGames = filtered.slice(startIndex, startIndex + maxVisible);
|
|
1045
|
+
for (let i = 0; i < visibleGames.length; i++) {
|
|
1046
|
+
const g = visibleGames[i];
|
|
1047
|
+
const realIndex = startIndex + i;
|
|
1048
|
+
const isSelected = realIndex === this.selectedIndex;
|
|
1049
|
+
const high = profile.highScores[g.id] || 0;
|
|
1050
|
+
const highStr = high > 0 ? t.accent(`\u2605 ${high}`) : t.muted("\u2014");
|
|
1051
|
+
if (isSelected) {
|
|
1052
|
+
listLines.push(t.primary(` \u25B6 ${t.highlight(g.name.padEnd(16))} ${t.secondary(`[${g.category}]`)} ${highStr}`));
|
|
1053
|
+
} else {
|
|
1054
|
+
listLines.push(t.muted(` ${g.name.padEnd(16)} [${g.category}] ${highStr}`));
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
const detailLines = [];
|
|
1058
|
+
if (activeGame) {
|
|
1059
|
+
const high = profile.highScores[activeGame.id] || 0;
|
|
1060
|
+
const plays = profile.playCounts[activeGame.id] || 0;
|
|
1061
|
+
const timeSec = profile.totalTimePlayedSec[activeGame.id] || 0;
|
|
1062
|
+
const achs = this.achievements.getAchievementsForGame(activeGame.id);
|
|
1063
|
+
const unlockedAchs = achs.filter((a) => a.unlocked).length;
|
|
1064
|
+
detailLines.push(t.highlight(activeGame.name.toUpperCase()));
|
|
1065
|
+
detailLines.push(t.secondary(activeGame.tagline));
|
|
1066
|
+
detailLines.push("");
|
|
1067
|
+
detailLines.push(activeGame.description);
|
|
1068
|
+
detailLines.push("");
|
|
1069
|
+
detailLines.push(`${t.muted("Personal Best:")} ${t.accent(high.toString())} ${t.muted("Runs:")} ${plays} ${t.muted("Time:")} ${formatTime(timeSec)}`);
|
|
1070
|
+
detailLines.push(`${t.muted("Difficulty:")} ${t.secondary(this.selectedDifficulty.toUpperCase())} ${t.muted("(Press D to cycle)")}`);
|
|
1071
|
+
detailLines.push(`${t.muted("Achievements:")} ${unlockedAchs}/${achs.length} unlocked`);
|
|
1072
|
+
detailLines.push("");
|
|
1073
|
+
detailLines.push(t.muted("Primary Controls:"));
|
|
1074
|
+
for (const ctrl of activeGame.controls.slice(0, 3)) {
|
|
1075
|
+
detailLines.push(` ${t.primary(ctrl.key.padEnd(14))} ${ctrl.action}`);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
const detailBox = this.renderer.createBox(detailLines, 46, "TELEMETRY");
|
|
1079
|
+
const detailBoxLines = detailBox.split("\n");
|
|
1080
|
+
const combinedLines = [];
|
|
1081
|
+
const maxRows = Math.max(listLines.length, detailBoxLines.length);
|
|
1082
|
+
for (let r = 0; r < maxRows; r++) {
|
|
1083
|
+
const left = (listLines[r] || "").padEnd(32);
|
|
1084
|
+
const right = detailBoxLines[r] || "";
|
|
1085
|
+
combinedLines.push(` ${left} ${right}`);
|
|
1086
|
+
}
|
|
1087
|
+
const footer = [
|
|
1088
|
+
` ${t.border("\u2500".repeat(74))}`,
|
|
1089
|
+
` ${t.primary("Enter/Space")}: Launch Game \u2502 ${t.secondary("Up/Down")}: Select \u2502 ${t.accent("D")}: Difficulty \u2502 ${t.muted("Q")}: Exit`
|
|
1090
|
+
].join("\n");
|
|
1091
|
+
return `
|
|
1092
|
+
${banner}
|
|
1093
|
+
${tabs}
|
|
1094
|
+
${searchBar}
|
|
1095
|
+
${combinedLines.join("\n")}
|
|
1096
|
+
|
|
1097
|
+
${footer}
|
|
1098
|
+
`;
|
|
1099
|
+
}
|
|
1100
|
+
renderStatsTab() {
|
|
1101
|
+
const t = this.renderer.getTheme();
|
|
1102
|
+
const profile = this.storage.getProfile();
|
|
1103
|
+
const { unlockedCount, totalCount, percentage } = this.achievements.getTotalStats();
|
|
1104
|
+
let totalScore = 0;
|
|
1105
|
+
let totalPlays = 0;
|
|
1106
|
+
let totalTime = 0;
|
|
1107
|
+
for (const id of Object.keys(ALL_GAMES_METADATA)) {
|
|
1108
|
+
totalScore += profile.highScores[id] || 0;
|
|
1109
|
+
totalPlays += profile.playCounts[id] || 0;
|
|
1110
|
+
totalTime += profile.totalTimePlayedSec[id] || 0;
|
|
1111
|
+
}
|
|
1112
|
+
const statsLines = [
|
|
1113
|
+
"",
|
|
1114
|
+
t.highlight("ARCADE PILOT DOSSIER"),
|
|
1115
|
+
"",
|
|
1116
|
+
`${t.muted("Total High Score Cumulative:")} ${t.accent(totalScore.toLocaleString())}`,
|
|
1117
|
+
`${t.muted("Total Play Sessions:")} ${t.primary(totalPlays.toString())}`,
|
|
1118
|
+
`${t.muted("Total Time Beyond Prompt:")} ${t.secondary(formatTime(totalTime))}`,
|
|
1119
|
+
`${t.muted("Global Achievements:")} ${t.success(`${unlockedCount} / ${totalCount} (${percentage}%)`)}`,
|
|
1120
|
+
"",
|
|
1121
|
+
t.highlight("PER-GAME ARCHIVE:"),
|
|
1122
|
+
...Object.values(ALL_GAMES_METADATA).map((g) => {
|
|
1123
|
+
const score = profile.highScores[g.id] || 0;
|
|
1124
|
+
const plays = profile.playCounts[g.id] || 0;
|
|
1125
|
+
return ` ${g.name.padEnd(18)} Score: ${score.toString().padEnd(6)} Runs: ${plays.toString().padEnd(4)}`;
|
|
1126
|
+
}),
|
|
1127
|
+
"",
|
|
1128
|
+
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"),
|
|
1129
|
+
t.muted("Press Tab to switch tabs, Esc/Enter to return to Arcade")
|
|
1130
|
+
];
|
|
1131
|
+
return `
|
|
1132
|
+
|
|
1133
|
+
${this.renderer.createBox(statsLines, 74, "CAREER TELEMETRY")}
|
|
1134
|
+
`;
|
|
1135
|
+
}
|
|
1136
|
+
renderSettingsTab() {
|
|
1137
|
+
const t = this.renderer.getTheme();
|
|
1138
|
+
const profile = this.storage.getProfile();
|
|
1139
|
+
const lines = [
|
|
1140
|
+
"",
|
|
1141
|
+
t.highlight("TERMINULL SYSTEM CONFIGURATION"),
|
|
1142
|
+
"",
|
|
1143
|
+
` ${t.primary("[T] Theme:")} ${t.highlight(profile.settings.theme.toUpperCase())} ${t.muted("(Default, Retro-Green, Neon, Minimal, High-Contrast)")}`,
|
|
1144
|
+
` ${t.secondary("[B] Bell Sound:")} ${profile.settings.soundEnabled ? t.success("ENABLED") : t.muted("MUTED")}`,
|
|
1145
|
+
` ${t.accent("[M] Reduced Motion:")} ${profile.settings.reducedMotion ? t.warning("ON") : t.muted("OFF")}`,
|
|
1146
|
+
"",
|
|
1147
|
+
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"),
|
|
1148
|
+
t.muted("Config stored at: ~/.config/terminull/profile.json"),
|
|
1149
|
+
t.muted("Press T to cycle theme, B to toggle sound, M for motion, Tab/Esc to exit")
|
|
1150
|
+
];
|
|
1151
|
+
return `
|
|
1152
|
+
|
|
1153
|
+
${this.renderer.createBox(lines, 74, "PREFERENCES")}
|
|
1154
|
+
`;
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
// src/core/rng.ts
|
|
1159
|
+
var DeterministicRNG = class {
|
|
1160
|
+
state;
|
|
1161
|
+
initialSeed;
|
|
1162
|
+
constructor(seed = Date.now()) {
|
|
1163
|
+
this.initialSeed = seed;
|
|
1164
|
+
this.state = seed >>> 0;
|
|
1165
|
+
}
|
|
1166
|
+
getSeed() {
|
|
1167
|
+
return this.initialSeed;
|
|
1168
|
+
}
|
|
1169
|
+
reset() {
|
|
1170
|
+
this.state = this.initialSeed >>> 0;
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Generates a floating point number in [0, 1).
|
|
1174
|
+
*/
|
|
1175
|
+
next() {
|
|
1176
|
+
let t = this.state += 1831565813;
|
|
1177
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
1178
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
1179
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Returns an integer within [min, max] inclusive.
|
|
1183
|
+
*/
|
|
1184
|
+
nextInt(min, max) {
|
|
1185
|
+
if (min > max) [min, max] = [max, min];
|
|
1186
|
+
return Math.floor(this.next() * (max - min + 1)) + min;
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Returns a random element from an array.
|
|
1190
|
+
*/
|
|
1191
|
+
pick(items) {
|
|
1192
|
+
if (items.length === 0) {
|
|
1193
|
+
throw new Error("Cannot pick from empty array");
|
|
1194
|
+
}
|
|
1195
|
+
const index = Math.floor(this.next() * items.length);
|
|
1196
|
+
return items[index];
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Shuffles an array in place using Fisher-Yates.
|
|
1200
|
+
*/
|
|
1201
|
+
shuffle(array) {
|
|
1202
|
+
const copy = [...array];
|
|
1203
|
+
for (let i = copy.length - 1; i > 0; i--) {
|
|
1204
|
+
const j = Math.floor(this.next() * (i + 1));
|
|
1205
|
+
const temp = copy[i];
|
|
1206
|
+
copy[i] = copy[j];
|
|
1207
|
+
copy[j] = temp;
|
|
1208
|
+
}
|
|
1209
|
+
return copy;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Generates a deterministic daily seed integer based on YYYY-MM-DD.
|
|
1213
|
+
*/
|
|
1214
|
+
static getDailySeed(date = /* @__PURE__ */ new Date()) {
|
|
1215
|
+
const y = date.getUTCFullYear();
|
|
1216
|
+
const m = date.getUTCMonth() + 1;
|
|
1217
|
+
const d = date.getUTCDate();
|
|
1218
|
+
return y * 1e4 + m * 100 + d >>> 0;
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
// src/games/neon-circuit/index.ts
|
|
1223
|
+
var NeonCircuitGame = class {
|
|
1224
|
+
id = "neon-circuit";
|
|
1225
|
+
metadata = ALL_GAMES_METADATA["neon-circuit"];
|
|
1226
|
+
config = null;
|
|
1227
|
+
renderer = defaultRenderer;
|
|
1228
|
+
input = new TerminalInputHandler();
|
|
1229
|
+
rng = new DeterministicRNG();
|
|
1230
|
+
state = {
|
|
1231
|
+
grid: [],
|
|
1232
|
+
width: 5,
|
|
1233
|
+
height: 5,
|
|
1234
|
+
cursorX: 0,
|
|
1235
|
+
cursorY: 0,
|
|
1236
|
+
movesRemaining: 25,
|
|
1237
|
+
maxMoves: 25,
|
|
1238
|
+
score: 0,
|
|
1239
|
+
level: 1,
|
|
1240
|
+
targetsRemaining: 1,
|
|
1241
|
+
totalTargets: 1,
|
|
1242
|
+
isWon: false,
|
|
1243
|
+
isGameOver: false
|
|
1244
|
+
};
|
|
1245
|
+
isPaused = false;
|
|
1246
|
+
pauseMenuIndex = 0;
|
|
1247
|
+
showTutorial = true;
|
|
1248
|
+
init(config) {
|
|
1249
|
+
this.config = config;
|
|
1250
|
+
this.renderer.setTheme(config.theme);
|
|
1251
|
+
this.rng = new DeterministicRNG(config.seed || Date.now());
|
|
1252
|
+
if (config.skipTutorial !== void 0) {
|
|
1253
|
+
this.showTutorial = !config.skipTutorial;
|
|
1254
|
+
}
|
|
1255
|
+
this.setupLevel(1, config.difficulty);
|
|
1256
|
+
}
|
|
1257
|
+
start() {
|
|
1258
|
+
this.isPaused = false;
|
|
1259
|
+
this.render();
|
|
1260
|
+
this.input.start(
|
|
1261
|
+
(key) => this.handleInput(key),
|
|
1262
|
+
() => {
|
|
1263
|
+
this.destroy();
|
|
1264
|
+
process.exit(0);
|
|
1265
|
+
}
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
pause() {
|
|
1269
|
+
this.isPaused = true;
|
|
1270
|
+
}
|
|
1271
|
+
resume() {
|
|
1272
|
+
this.isPaused = false;
|
|
1273
|
+
this.render();
|
|
1274
|
+
}
|
|
1275
|
+
restart() {
|
|
1276
|
+
if (this.config) {
|
|
1277
|
+
this.state.score = 0;
|
|
1278
|
+
this.setupLevel(1, this.config.difficulty);
|
|
1279
|
+
this.render();
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
saveState() {
|
|
1283
|
+
return {
|
|
1284
|
+
state: this.state,
|
|
1285
|
+
showTutorial: this.showTutorial
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
loadState(saved) {
|
|
1289
|
+
if (saved["state"]) {
|
|
1290
|
+
this.state = saved["state"];
|
|
1291
|
+
}
|
|
1292
|
+
if (saved["showTutorial"] !== void 0) {
|
|
1293
|
+
this.showTutorial = !!saved["showTutorial"];
|
|
1294
|
+
}
|
|
1295
|
+
this.updatePowerFlow();
|
|
1296
|
+
}
|
|
1297
|
+
destroy() {
|
|
1298
|
+
this.input.stop();
|
|
1299
|
+
}
|
|
1300
|
+
setupLevel(level, difficulty) {
|
|
1301
|
+
let size = 5;
|
|
1302
|
+
let moves = 20;
|
|
1303
|
+
switch (difficulty) {
|
|
1304
|
+
case "easy":
|
|
1305
|
+
size = 4;
|
|
1306
|
+
moves = 25;
|
|
1307
|
+
break;
|
|
1308
|
+
case "normal":
|
|
1309
|
+
size = 5;
|
|
1310
|
+
moves = 22;
|
|
1311
|
+
break;
|
|
1312
|
+
case "hard":
|
|
1313
|
+
size = 6;
|
|
1314
|
+
moves = 20;
|
|
1315
|
+
break;
|
|
1316
|
+
case "insane":
|
|
1317
|
+
size = 7;
|
|
1318
|
+
moves = 18;
|
|
1319
|
+
break;
|
|
1320
|
+
}
|
|
1321
|
+
this.state.width = size;
|
|
1322
|
+
this.state.height = size;
|
|
1323
|
+
this.state.level = level;
|
|
1324
|
+
this.state.maxMoves = moves;
|
|
1325
|
+
this.state.movesRemaining = moves;
|
|
1326
|
+
this.state.cursorX = 0;
|
|
1327
|
+
this.state.cursorY = 0;
|
|
1328
|
+
this.state.isWon = false;
|
|
1329
|
+
this.state.isGameOver = false;
|
|
1330
|
+
const grid = [];
|
|
1331
|
+
for (let y = 0; y < size; y++) {
|
|
1332
|
+
const row = [];
|
|
1333
|
+
for (let x = 0; x < size; x++) {
|
|
1334
|
+
row.push(this.createRandomTile(x, y, size, difficulty));
|
|
1335
|
+
}
|
|
1336
|
+
row.push();
|
|
1337
|
+
grid.push(row);
|
|
1338
|
+
}
|
|
1339
|
+
grid[0][0] = {
|
|
1340
|
+
type: "source",
|
|
1341
|
+
rotation: 0,
|
|
1342
|
+
baseConnections: [false, true, true, false],
|
|
1343
|
+
currentConnections: [false, true, true, false],
|
|
1344
|
+
isPowered: true,
|
|
1345
|
+
isFixed: true
|
|
1346
|
+
};
|
|
1347
|
+
grid[size - 1][size - 1] = {
|
|
1348
|
+
type: "target",
|
|
1349
|
+
rotation: 0,
|
|
1350
|
+
baseConnections: [true, false, false, true],
|
|
1351
|
+
currentConnections: [true, false, false, true],
|
|
1352
|
+
isPowered: false,
|
|
1353
|
+
isFixed: true
|
|
1354
|
+
};
|
|
1355
|
+
if (difficulty === "insane") {
|
|
1356
|
+
grid[0][size - 1] = {
|
|
1357
|
+
type: "target",
|
|
1358
|
+
rotation: 0,
|
|
1359
|
+
baseConnections: [false, false, true, true],
|
|
1360
|
+
currentConnections: [false, false, true, true],
|
|
1361
|
+
isPowered: false,
|
|
1362
|
+
isFixed: true
|
|
1363
|
+
};
|
|
1364
|
+
this.state.totalTargets = 2;
|
|
1365
|
+
this.state.targetsRemaining = 2;
|
|
1366
|
+
} else {
|
|
1367
|
+
this.state.totalTargets = 1;
|
|
1368
|
+
this.state.targetsRemaining = 1;
|
|
1369
|
+
}
|
|
1370
|
+
this.state.grid = grid;
|
|
1371
|
+
this.updatePowerFlow();
|
|
1372
|
+
}
|
|
1373
|
+
createRandomTile(x, y, size, difficulty) {
|
|
1374
|
+
if ((difficulty === "hard" || difficulty === "insane") && this.rng.next() < 0.12 && (x > 0 || y > 0)) {
|
|
1375
|
+
return {
|
|
1376
|
+
type: "blocked",
|
|
1377
|
+
rotation: 0,
|
|
1378
|
+
baseConnections: [false, false, false, false],
|
|
1379
|
+
currentConnections: [false, false, false, false],
|
|
1380
|
+
isPowered: false,
|
|
1381
|
+
isFixed: true
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
const roll = this.rng.next();
|
|
1385
|
+
let type = "corner";
|
|
1386
|
+
let base = [true, true, false, false];
|
|
1387
|
+
if (roll < 0.4) {
|
|
1388
|
+
type = "straight";
|
|
1389
|
+
base = [true, false, true, false];
|
|
1390
|
+
} else if (roll < 0.75) {
|
|
1391
|
+
type = "corner";
|
|
1392
|
+
base = [true, true, false, false];
|
|
1393
|
+
} else if (roll < 0.92) {
|
|
1394
|
+
type = "t-shape";
|
|
1395
|
+
base = [true, true, false, true];
|
|
1396
|
+
} else {
|
|
1397
|
+
type = "cross";
|
|
1398
|
+
base = [true, true, true, true];
|
|
1399
|
+
}
|
|
1400
|
+
const rotation = this.rng.nextInt(0, 3);
|
|
1401
|
+
const current = this.rotateMask(base, rotation);
|
|
1402
|
+
return {
|
|
1403
|
+
type,
|
|
1404
|
+
rotation,
|
|
1405
|
+
baseConnections: base,
|
|
1406
|
+
currentConnections: current,
|
|
1407
|
+
isPowered: false,
|
|
1408
|
+
isFixed: false
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
rotateMask(mask, times) {
|
|
1412
|
+
const res = [...mask];
|
|
1413
|
+
for (let i = 0; i < times % 4; i++) {
|
|
1414
|
+
const [top, right, bottom, left] = res;
|
|
1415
|
+
res[0] = left;
|
|
1416
|
+
res[1] = top;
|
|
1417
|
+
res[2] = right;
|
|
1418
|
+
res[3] = bottom;
|
|
1419
|
+
}
|
|
1420
|
+
return res;
|
|
1421
|
+
}
|
|
1422
|
+
rotateTileAt(x, y) {
|
|
1423
|
+
const tile = this.state.grid[y]?.[x];
|
|
1424
|
+
if (!tile || tile.isFixed || this.state.isWon || this.state.isGameOver) return false;
|
|
1425
|
+
tile.rotation = (tile.rotation + 1) % 4;
|
|
1426
|
+
tile.currentConnections = this.rotateMask(tile.baseConnections, tile.rotation);
|
|
1427
|
+
this.state.movesRemaining--;
|
|
1428
|
+
this.updatePowerFlow();
|
|
1429
|
+
if (this.config?.soundEnabled) {
|
|
1430
|
+
playTerminalBell();
|
|
1431
|
+
}
|
|
1432
|
+
if (this.state.isWon) {
|
|
1433
|
+
const bonus = this.state.movesRemaining * 100;
|
|
1434
|
+
this.state.score += 500 + bonus;
|
|
1435
|
+
this.config?.onScoreUpdate?.(this.state.score);
|
|
1436
|
+
this.config?.onAchievementUnlock?.("first_spark");
|
|
1437
|
+
if (this.state.movesRemaining >= 5) {
|
|
1438
|
+
this.config?.onAchievementUnlock?.("overclocked");
|
|
1439
|
+
}
|
|
1440
|
+
if (this.config?.difficulty === "insane") {
|
|
1441
|
+
this.config?.onAchievementUnlock?.("grid_master");
|
|
1442
|
+
}
|
|
1443
|
+
} else if (this.state.movesRemaining <= 0) {
|
|
1444
|
+
this.state.isGameOver = true;
|
|
1445
|
+
this.config?.onGameOver?.(this.state.score);
|
|
1446
|
+
}
|
|
1447
|
+
return true;
|
|
1448
|
+
}
|
|
1449
|
+
updatePowerFlow() {
|
|
1450
|
+
const { width, height, grid } = this.state;
|
|
1451
|
+
for (let y = 0; y < height; y++) {
|
|
1452
|
+
for (let x = 0; x < width; x++) {
|
|
1453
|
+
if (grid[y][x].type !== "source") {
|
|
1454
|
+
grid[y][x].isPowered = false;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
const queue = [[0, 0]];
|
|
1459
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1460
|
+
visited.add("0,0");
|
|
1461
|
+
let targetsLit = 0;
|
|
1462
|
+
const dx = [0, 1, 0, -1];
|
|
1463
|
+
const dy = [-1, 0, 1, 0];
|
|
1464
|
+
const oppositeDir = [2, 3, 0, 1];
|
|
1465
|
+
while (queue.length > 0) {
|
|
1466
|
+
const [cx, cy] = queue.shift();
|
|
1467
|
+
const curr = grid[cy][cx];
|
|
1468
|
+
for (let dir = 0; dir < 4; dir++) {
|
|
1469
|
+
if (!curr.currentConnections[dir]) continue;
|
|
1470
|
+
const nx = cx + dx[dir];
|
|
1471
|
+
const ny = cy + dy[dir];
|
|
1472
|
+
if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
|
|
1473
|
+
const key = `${nx},${ny}`;
|
|
1474
|
+
if (visited.has(key)) continue;
|
|
1475
|
+
const neighbor = grid[ny][nx];
|
|
1476
|
+
if (neighbor.type === "blocked") continue;
|
|
1477
|
+
const opp = oppositeDir[dir];
|
|
1478
|
+
if (neighbor.currentConnections[opp]) {
|
|
1479
|
+
neighbor.isPowered = true;
|
|
1480
|
+
visited.add(key);
|
|
1481
|
+
queue.push([nx, ny]);
|
|
1482
|
+
if (neighbor.type === "target") {
|
|
1483
|
+
targetsLit++;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
this.state.targetsRemaining = this.state.totalTargets - targetsLit;
|
|
1489
|
+
if (this.state.targetsRemaining === 0) {
|
|
1490
|
+
this.state.isWon = true;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
handleInput(key) {
|
|
1494
|
+
if (this.showTutorial) {
|
|
1495
|
+
if (key.name === "return" || key.name === "space") {
|
|
1496
|
+
this.showTutorial = false;
|
|
1497
|
+
this.render();
|
|
1498
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
1499
|
+
this.destroy();
|
|
1500
|
+
this.config?.onExit?.();
|
|
1501
|
+
}
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
if (this.isPaused) {
|
|
1505
|
+
if (key.name === "up" || key.name === "w") {
|
|
1506
|
+
this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
|
|
1507
|
+
this.render();
|
|
1508
|
+
} else if (key.name === "down" || key.name === "s") {
|
|
1509
|
+
this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
|
|
1510
|
+
this.render();
|
|
1511
|
+
} else if (key.name === "return" || key.name === "space") {
|
|
1512
|
+
if (this.pauseMenuIndex === 0) {
|
|
1513
|
+
this.isPaused = false;
|
|
1514
|
+
this.render();
|
|
1515
|
+
} else if (this.pauseMenuIndex === 1) {
|
|
1516
|
+
this.isPaused = false;
|
|
1517
|
+
this.setupLevel(this.state.level, this.config?.difficulty || "normal");
|
|
1518
|
+
this.render();
|
|
1519
|
+
} else if (this.pauseMenuIndex === 2) {
|
|
1520
|
+
this.destroy();
|
|
1521
|
+
this.config?.onExit?.();
|
|
1522
|
+
}
|
|
1523
|
+
} else if (key.name === "escape" || key.name === "p") {
|
|
1524
|
+
this.isPaused = false;
|
|
1525
|
+
this.render();
|
|
1526
|
+
} else if (key.name === "q") {
|
|
1527
|
+
this.destroy();
|
|
1528
|
+
this.config?.onExit?.();
|
|
1529
|
+
}
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
if (key.name === "escape" || key.name === "p") {
|
|
1533
|
+
this.isPaused = true;
|
|
1534
|
+
this.pauseMenuIndex = 0;
|
|
1535
|
+
this.render();
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
if (key.name === "q") {
|
|
1539
|
+
this.destroy();
|
|
1540
|
+
this.config?.onExit?.();
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
if (this.state.isWon) {
|
|
1544
|
+
if (key.name === "return" || key.name === "space") {
|
|
1545
|
+
this.setupLevel(this.state.level + 1, this.config?.difficulty || "normal");
|
|
1546
|
+
this.render();
|
|
1547
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
1548
|
+
this.destroy();
|
|
1549
|
+
this.config?.onExit?.();
|
|
1550
|
+
}
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
if (this.state.isGameOver) {
|
|
1554
|
+
if (key.name === "r") {
|
|
1555
|
+
this.restart();
|
|
1556
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
1557
|
+
this.destroy();
|
|
1558
|
+
this.config?.onExit?.();
|
|
1559
|
+
}
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (key.name === "up" || key.name === "w") {
|
|
1563
|
+
this.state.cursorY = Math.max(0, this.state.cursorY - 1);
|
|
1564
|
+
this.render();
|
|
1565
|
+
} else if (key.name === "down" || key.name === "s") {
|
|
1566
|
+
this.state.cursorY = Math.min(this.state.height - 1, this.state.cursorY + 1);
|
|
1567
|
+
this.render();
|
|
1568
|
+
} else if (key.name === "left" || key.name === "a") {
|
|
1569
|
+
this.state.cursorX = Math.max(0, this.state.cursorX - 1);
|
|
1570
|
+
this.render();
|
|
1571
|
+
} else if (key.name === "right" || key.name === "d") {
|
|
1572
|
+
this.state.cursorX = Math.min(this.state.width - 1, this.state.cursorX + 1);
|
|
1573
|
+
this.render();
|
|
1574
|
+
} else if (key.name === "space" || key.name === "return") {
|
|
1575
|
+
this.rotateTileAt(this.state.cursorX, this.state.cursorY);
|
|
1576
|
+
this.render();
|
|
1577
|
+
} else if (key.name === "r") {
|
|
1578
|
+
this.setupLevel(this.state.level, this.config?.difficulty || "normal");
|
|
1579
|
+
this.render();
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
render() {
|
|
1583
|
+
const t = this.renderer.getTheme();
|
|
1584
|
+
if (this.showTutorial) {
|
|
1585
|
+
const tutorialLines = [
|
|
1586
|
+
"",
|
|
1587
|
+
t.highlight("OBJECTIVE: ROUTE HIGH-VOLTAGE FLUX"),
|
|
1588
|
+
"",
|
|
1589
|
+
"\u2022 Navigate cursor using Arrow Keys or WASD.",
|
|
1590
|
+
"\u2022 Press Space or Enter to rotate circuit tiles clockwise.",
|
|
1591
|
+
"\u2022 Connect the glowing [S] Power Source to the [T] Target nodes.",
|
|
1592
|
+
"\u2022 Watch your Capacity (Moves Remaining) meter.",
|
|
1593
|
+
"\u2022 Obstacles [\u2593] cannot conduct energy or rotate.",
|
|
1594
|
+
"",
|
|
1595
|
+
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"),
|
|
1596
|
+
t.primary("Press Space or Enter to start \u2502 Esc / Q to Exit")
|
|
1597
|
+
];
|
|
1598
|
+
const box = this.renderer.createBox(tutorialLines, 64, "CIRCUIT PROTOCOL MANUAL");
|
|
1599
|
+
this.renderer.clear();
|
|
1600
|
+
this.renderer.draw(`
|
|
1601
|
+
|
|
1602
|
+
${box}
|
|
1603
|
+
`);
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
if (this.isPaused) {
|
|
1607
|
+
const pauseItems = ["Resume Circuit (Esc / Enter)", "Restart Level (R)", "Quit to Arcade / Terminal (Q)"];
|
|
1608
|
+
const pauseLines = [
|
|
1609
|
+
"",
|
|
1610
|
+
t.highlight("\u2550\u2550\u2550 CIRCUIT SUBROUTINE PAUSED \u2550\u2550\u2550"),
|
|
1611
|
+
"",
|
|
1612
|
+
...pauseItems.map((item, idx) => {
|
|
1613
|
+
if (idx === this.pauseMenuIndex) {
|
|
1614
|
+
return t.primary(` \u25B6 ${t.highlight(item)}`);
|
|
1615
|
+
}
|
|
1616
|
+
return t.muted(` ${item}`);
|
|
1617
|
+
}),
|
|
1618
|
+
"",
|
|
1619
|
+
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"),
|
|
1620
|
+
t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
|
|
1621
|
+
];
|
|
1622
|
+
const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
|
|
1623
|
+
this.renderer.clear();
|
|
1624
|
+
this.renderer.draw(`
|
|
1625
|
+
|
|
1626
|
+
${pauseBox}
|
|
1627
|
+
`);
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
const header = this.renderer.renderHeader({
|
|
1631
|
+
title: "NEON CIRCUIT",
|
|
1632
|
+
category: "PUZZLE",
|
|
1633
|
+
difficulty: this.config?.difficulty,
|
|
1634
|
+
score: this.state.score,
|
|
1635
|
+
level: this.state.level
|
|
1636
|
+
});
|
|
1637
|
+
const lines = [];
|
|
1638
|
+
const { width, height, grid, cursorX, cursorY } = this.state;
|
|
1639
|
+
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}`)}`);
|
|
1640
|
+
lines.push("");
|
|
1641
|
+
for (let y = 0; y < height; y++) {
|
|
1642
|
+
let rowStr = " ";
|
|
1643
|
+
for (let x = 0; x < width; x++) {
|
|
1644
|
+
const tile = grid[y][x];
|
|
1645
|
+
const isCursor = x === cursorX && y === cursorY;
|
|
1646
|
+
const glyph = this.getTileGlyph(tile);
|
|
1647
|
+
let formatted = glyph;
|
|
1648
|
+
if (tile.isPowered) {
|
|
1649
|
+
formatted = t.highlight(glyph);
|
|
1650
|
+
} else {
|
|
1651
|
+
formatted = t.muted(glyph);
|
|
1652
|
+
}
|
|
1653
|
+
if (isCursor) {
|
|
1654
|
+
rowStr += `[${t.accent(glyph)}] `;
|
|
1655
|
+
} else {
|
|
1656
|
+
rowStr += ` ${formatted} `;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
lines.push(rowStr);
|
|
1660
|
+
lines.push("");
|
|
1661
|
+
}
|
|
1662
|
+
if (this.state.isWon) {
|
|
1663
|
+
lines.push(` ${t.success("\u26A1 CIRCUIT SYNCHRONIZED! ALL NODES POWERED!")}`);
|
|
1664
|
+
lines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
|
|
1665
|
+
} else if (this.state.isGameOver) {
|
|
1666
|
+
lines.push(` ${t.error("\u274C CAPACITY EXHAUSTED! POWER COLLAPSE.")}`);
|
|
1667
|
+
lines.push(` ${t.muted("Press R to Retry Level, or P for Pause Menu.")}`);
|
|
1668
|
+
} else {
|
|
1669
|
+
lines.push(` ${t.muted("Controls: Arrows/WASD: Move \u2502 Space: Rotate \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
|
|
1670
|
+
}
|
|
1671
|
+
this.renderer.clear();
|
|
1672
|
+
this.renderer.draw(`
|
|
1673
|
+
${header}
|
|
1674
|
+
${lines.join("\n")}
|
|
1675
|
+
`);
|
|
1676
|
+
}
|
|
1677
|
+
getTileGlyph(tile) {
|
|
1678
|
+
if (tile.type === "source") return "S";
|
|
1679
|
+
if (tile.type === "target") return "T";
|
|
1680
|
+
if (tile.type === "blocked") return "\u2593";
|
|
1681
|
+
const [top, right, bottom, left] = tile.currentConnections;
|
|
1682
|
+
if (top && bottom && !right && !left) return "\u2502";
|
|
1683
|
+
if (!top && !bottom && right && left) return "\u2500";
|
|
1684
|
+
if (bottom && right && !top && !left) return "\u250C";
|
|
1685
|
+
if (bottom && left && !top && !right) return "\u2510";
|
|
1686
|
+
if (top && right && !bottom && !left) return "\u2514";
|
|
1687
|
+
if (top && left && !bottom && !right) return "\u2518";
|
|
1688
|
+
if (top && bottom && right && !left) return "\u251C";
|
|
1689
|
+
if (top && bottom && !right && left) return "\u2524";
|
|
1690
|
+
if (!top && bottom && right && left) return "\u252C";
|
|
1691
|
+
if (top && !bottom && right && left) return "\u2534";
|
|
1692
|
+
if (top && bottom && right && left) return "\u253C";
|
|
1693
|
+
return "\u2022";
|
|
1694
|
+
}
|
|
1695
|
+
getState() {
|
|
1696
|
+
return this.state;
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1700
|
+
// src/games/byte-runner/index.ts
|
|
1701
|
+
var HIGHWAY_HEIGHT = 16;
|
|
1702
|
+
var LANE_COUNT = 3;
|
|
1703
|
+
var ByteRunnerGame = class {
|
|
1704
|
+
id = "byte-runner";
|
|
1705
|
+
metadata = ALL_GAMES_METADATA["byte-runner"];
|
|
1706
|
+
config = null;
|
|
1707
|
+
renderer = defaultRenderer;
|
|
1708
|
+
input = new TerminalInputHandler();
|
|
1709
|
+
rng = new DeterministicRNG();
|
|
1710
|
+
gameLoopTimer = null;
|
|
1711
|
+
entityIdCounter = 0;
|
|
1712
|
+
entities = [];
|
|
1713
|
+
state = {
|
|
1714
|
+
playerLane: 1,
|
|
1715
|
+
isJumping: false,
|
|
1716
|
+
jumpTicksRemaining: 0,
|
|
1717
|
+
score: 0,
|
|
1718
|
+
distance: 0,
|
|
1719
|
+
cleanBytesCollected: 0,
|
|
1720
|
+
activeShield: false,
|
|
1721
|
+
slowMotionTicks: 0,
|
|
1722
|
+
magnetTicks: 0,
|
|
1723
|
+
doubleScoreTicks: 0,
|
|
1724
|
+
speedMs: 110,
|
|
1725
|
+
isGameOver: false,
|
|
1726
|
+
multiplier: 1
|
|
1727
|
+
};
|
|
1728
|
+
isPaused = false;
|
|
1729
|
+
pauseMenuIndex = 0;
|
|
1730
|
+
showTutorial = true;
|
|
1731
|
+
init(config) {
|
|
1732
|
+
this.config = config;
|
|
1733
|
+
this.renderer.setTheme(config.theme);
|
|
1734
|
+
this.rng = new DeterministicRNG(config.seed || Date.now());
|
|
1735
|
+
if (config.skipTutorial !== void 0) {
|
|
1736
|
+
this.showTutorial = !config.skipTutorial;
|
|
1737
|
+
}
|
|
1738
|
+
this.resetState(config.difficulty);
|
|
1739
|
+
}
|
|
1740
|
+
start() {
|
|
1741
|
+
this.isPaused = false;
|
|
1742
|
+
this.render();
|
|
1743
|
+
this.input.start(
|
|
1744
|
+
(key) => this.handleInput(key),
|
|
1745
|
+
() => {
|
|
1746
|
+
this.destroy();
|
|
1747
|
+
process.exit(0);
|
|
1748
|
+
}
|
|
1749
|
+
);
|
|
1750
|
+
this.scheduleNextTick();
|
|
1751
|
+
}
|
|
1752
|
+
pause() {
|
|
1753
|
+
this.isPaused = true;
|
|
1754
|
+
if (this.gameLoopTimer) {
|
|
1755
|
+
clearTimeout(this.gameLoopTimer);
|
|
1756
|
+
this.gameLoopTimer = null;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
resume() {
|
|
1760
|
+
this.isPaused = false;
|
|
1761
|
+
this.scheduleNextTick();
|
|
1762
|
+
this.render();
|
|
1763
|
+
}
|
|
1764
|
+
restart() {
|
|
1765
|
+
if (this.config) {
|
|
1766
|
+
this.resetState(this.config.difficulty);
|
|
1767
|
+
this.scheduleNextTick();
|
|
1768
|
+
this.render();
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
saveState() {
|
|
1772
|
+
return {
|
|
1773
|
+
state: this.state,
|
|
1774
|
+
entities: this.entities,
|
|
1775
|
+
showTutorial: this.showTutorial
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
loadState(saved) {
|
|
1779
|
+
if (saved["state"]) {
|
|
1780
|
+
this.state = saved["state"];
|
|
1781
|
+
}
|
|
1782
|
+
if (saved["entities"]) {
|
|
1783
|
+
this.entities = saved["entities"];
|
|
1784
|
+
}
|
|
1785
|
+
if (saved["showTutorial"] !== void 0) {
|
|
1786
|
+
this.showTutorial = !!saved["showTutorial"];
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
destroy() {
|
|
1790
|
+
if (this.gameLoopTimer) {
|
|
1791
|
+
clearTimeout(this.gameLoopTimer);
|
|
1792
|
+
this.gameLoopTimer = null;
|
|
1793
|
+
}
|
|
1794
|
+
this.input.stop();
|
|
1795
|
+
}
|
|
1796
|
+
resetState(difficulty) {
|
|
1797
|
+
let baseSpeed = 110;
|
|
1798
|
+
switch (difficulty) {
|
|
1799
|
+
case "easy":
|
|
1800
|
+
baseSpeed = 140;
|
|
1801
|
+
break;
|
|
1802
|
+
case "normal":
|
|
1803
|
+
baseSpeed = 110;
|
|
1804
|
+
break;
|
|
1805
|
+
case "hard":
|
|
1806
|
+
baseSpeed = 85;
|
|
1807
|
+
break;
|
|
1808
|
+
case "insane":
|
|
1809
|
+
baseSpeed = 65;
|
|
1810
|
+
break;
|
|
1811
|
+
}
|
|
1812
|
+
this.state = {
|
|
1813
|
+
playerLane: 1,
|
|
1814
|
+
isJumping: false,
|
|
1815
|
+
jumpTicksRemaining: 0,
|
|
1816
|
+
score: 0,
|
|
1817
|
+
distance: 0,
|
|
1818
|
+
cleanBytesCollected: 0,
|
|
1819
|
+
activeShield: false,
|
|
1820
|
+
slowMotionTicks: 0,
|
|
1821
|
+
magnetTicks: 0,
|
|
1822
|
+
doubleScoreTicks: 0,
|
|
1823
|
+
speedMs: baseSpeed,
|
|
1824
|
+
isGameOver: false,
|
|
1825
|
+
multiplier: 1
|
|
1826
|
+
};
|
|
1827
|
+
this.entities = [];
|
|
1828
|
+
}
|
|
1829
|
+
scheduleNextTick() {
|
|
1830
|
+
if (this.gameLoopTimer) {
|
|
1831
|
+
clearTimeout(this.gameLoopTimer);
|
|
1832
|
+
}
|
|
1833
|
+
if (this.isPaused || this.state.isGameOver || this.showTutorial) return;
|
|
1834
|
+
let delay = this.state.speedMs;
|
|
1835
|
+
if (this.state.slowMotionTicks > 0) {
|
|
1836
|
+
delay = Math.round(delay * 1.6);
|
|
1837
|
+
}
|
|
1838
|
+
this.gameLoopTimer = setTimeout(() => {
|
|
1839
|
+
this.tick();
|
|
1840
|
+
this.scheduleNextTick();
|
|
1841
|
+
}, delay);
|
|
1842
|
+
}
|
|
1843
|
+
tick() {
|
|
1844
|
+
if (this.state.isGameOver || this.isPaused || this.showTutorial) return;
|
|
1845
|
+
this.state.distance += 1;
|
|
1846
|
+
const pointGain = 1 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
|
|
1847
|
+
this.state.score += pointGain;
|
|
1848
|
+
if (this.state.jumpTicksRemaining > 0) {
|
|
1849
|
+
this.state.jumpTicksRemaining--;
|
|
1850
|
+
if (this.state.jumpTicksRemaining === 0) {
|
|
1851
|
+
this.state.isJumping = false;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
if (this.state.slowMotionTicks > 0) this.state.slowMotionTicks--;
|
|
1855
|
+
if (this.state.magnetTicks > 0) this.state.magnetTicks--;
|
|
1856
|
+
if (this.state.doubleScoreTicks > 0) this.state.doubleScoreTicks--;
|
|
1857
|
+
for (const ent of this.entities) {
|
|
1858
|
+
ent.y += 1;
|
|
1859
|
+
if (this.state.magnetTicks > 0 && ent.type === "clean" && ent.y >= HIGHWAY_HEIGHT - 6) {
|
|
1860
|
+
ent.lane = this.state.playerLane;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
const playerY = HIGHWAY_HEIGHT - 2;
|
|
1864
|
+
const remainingEntities = [];
|
|
1865
|
+
for (const ent of this.entities) {
|
|
1866
|
+
if (ent.y === playerY && ent.lane === this.state.playerLane) {
|
|
1867
|
+
if (ent.type === "corrupt") {
|
|
1868
|
+
if (this.state.isJumping) {
|
|
1869
|
+
remainingEntities.push(ent);
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1872
|
+
if (this.state.activeShield) {
|
|
1873
|
+
this.state.activeShield = false;
|
|
1874
|
+
this.config?.onAchievementUnlock?.("shield_matrix");
|
|
1875
|
+
if (this.config?.soundEnabled) playTerminalBell();
|
|
1876
|
+
continue;
|
|
1877
|
+
}
|
|
1878
|
+
this.state.isGameOver = true;
|
|
1879
|
+
this.config?.onGameOver?.(this.state.score);
|
|
1880
|
+
if (this.config?.soundEnabled) playTerminalBell();
|
|
1881
|
+
break;
|
|
1882
|
+
} else if (ent.type === "clean") {
|
|
1883
|
+
this.state.cleanBytesCollected++;
|
|
1884
|
+
this.state.score += 100 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
|
|
1885
|
+
this.config?.onScoreUpdate?.(this.state.score);
|
|
1886
|
+
if (this.state.cleanBytesCollected >= 50) {
|
|
1887
|
+
this.config?.onAchievementUnlock?.("packet_chaser");
|
|
1888
|
+
}
|
|
1889
|
+
if (this.config?.soundEnabled) playTerminalBell();
|
|
1890
|
+
continue;
|
|
1891
|
+
} else if (ent.type === "powerup") {
|
|
1892
|
+
this.activatePowerUp(ent.subType);
|
|
1893
|
+
if (this.config?.soundEnabled) playTerminalBell();
|
|
1894
|
+
continue;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
if (ent.y < HIGHWAY_HEIGHT) {
|
|
1898
|
+
remainingEntities.push(ent);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
this.entities = remainingEntities;
|
|
1902
|
+
if (this.state.distance >= 5e3) {
|
|
1903
|
+
this.config?.onAchievementUnlock?.("hyperspeed");
|
|
1904
|
+
}
|
|
1905
|
+
if (this.state.distance % 2 === 0) {
|
|
1906
|
+
this.spawnHighwayWave();
|
|
1907
|
+
}
|
|
1908
|
+
if (this.state.distance % 200 === 0 && this.state.speedMs > 45) {
|
|
1909
|
+
this.state.speedMs -= 2;
|
|
1910
|
+
}
|
|
1911
|
+
this.render();
|
|
1912
|
+
}
|
|
1913
|
+
activatePowerUp(type) {
|
|
1914
|
+
switch (type) {
|
|
1915
|
+
case "shield":
|
|
1916
|
+
this.state.activeShield = true;
|
|
1917
|
+
break;
|
|
1918
|
+
case "slow":
|
|
1919
|
+
this.state.slowMotionTicks = 60;
|
|
1920
|
+
break;
|
|
1921
|
+
case "magnet":
|
|
1922
|
+
this.state.magnetTicks = 70;
|
|
1923
|
+
break;
|
|
1924
|
+
case "double":
|
|
1925
|
+
this.state.doubleScoreTicks = 80;
|
|
1926
|
+
break;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
spawnHighwayWave() {
|
|
1930
|
+
const roll = this.rng.next();
|
|
1931
|
+
const lane = this.rng.nextInt(0, LANE_COUNT - 1);
|
|
1932
|
+
if (roll < 0.45) {
|
|
1933
|
+
const labels = ["[CORRUPT]", "[BAD_MEM]", "[NULL_PTR]", "[SEG_FLT]"];
|
|
1934
|
+
this.entities.push({
|
|
1935
|
+
id: ++this.entityIdCounter,
|
|
1936
|
+
lane,
|
|
1937
|
+
y: 0,
|
|
1938
|
+
type: "corrupt",
|
|
1939
|
+
label: this.rng.pick(labels)
|
|
1940
|
+
});
|
|
1941
|
+
} else if (roll < 0.8) {
|
|
1942
|
+
const labels = ["0x7F", "0xFF", "[CLEAN]", "[PACKET]"];
|
|
1943
|
+
this.entities.push({
|
|
1944
|
+
id: ++this.entityIdCounter,
|
|
1945
|
+
lane,
|
|
1946
|
+
y: 0,
|
|
1947
|
+
type: "clean",
|
|
1948
|
+
label: this.rng.pick(labels)
|
|
1949
|
+
});
|
|
1950
|
+
} else if (roll < 0.95) {
|
|
1951
|
+
const powerups = ["shield", "slow", "magnet", "double"];
|
|
1952
|
+
const chosen = this.rng.pick(powerups);
|
|
1953
|
+
const labels = {
|
|
1954
|
+
shield: "\u{1F6E1}\uFE0F [SHLD]",
|
|
1955
|
+
slow: "\u23F1\uFE0F [SLOW]",
|
|
1956
|
+
magnet: "\u{1F9F2} [MAG]",
|
|
1957
|
+
double: "\u26A1 [2X]"
|
|
1958
|
+
};
|
|
1959
|
+
this.entities.push({
|
|
1960
|
+
id: ++this.entityIdCounter,
|
|
1961
|
+
lane,
|
|
1962
|
+
y: 0,
|
|
1963
|
+
type: "powerup",
|
|
1964
|
+
subType: chosen,
|
|
1965
|
+
label: labels[chosen]
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
handleInput(key) {
|
|
1970
|
+
if (this.showTutorial) {
|
|
1971
|
+
if (key.name === "return" || key.name === "space") {
|
|
1972
|
+
this.showTutorial = false;
|
|
1973
|
+
this.scheduleNextTick();
|
|
1974
|
+
this.render();
|
|
1975
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
1976
|
+
this.destroy();
|
|
1977
|
+
this.config?.onExit?.();
|
|
1978
|
+
}
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
if (this.isPaused) {
|
|
1982
|
+
if (key.name === "up" || key.name === "w") {
|
|
1983
|
+
this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
|
|
1984
|
+
this.render();
|
|
1985
|
+
} else if (key.name === "down" || key.name === "s") {
|
|
1986
|
+
this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
|
|
1987
|
+
this.render();
|
|
1988
|
+
} else if (key.name === "return" || key.name === "space") {
|
|
1989
|
+
if (this.pauseMenuIndex === 0) {
|
|
1990
|
+
this.isPaused = false;
|
|
1991
|
+
this.scheduleNextTick();
|
|
1992
|
+
this.render();
|
|
1993
|
+
} else if (this.pauseMenuIndex === 1) {
|
|
1994
|
+
this.isPaused = false;
|
|
1995
|
+
this.restart();
|
|
1996
|
+
} else if (this.pauseMenuIndex === 2) {
|
|
1997
|
+
this.destroy();
|
|
1998
|
+
this.config?.onExit?.();
|
|
1999
|
+
}
|
|
2000
|
+
} else if (key.name === "escape" || key.name === "p") {
|
|
2001
|
+
this.isPaused = false;
|
|
2002
|
+
this.scheduleNextTick();
|
|
2003
|
+
this.render();
|
|
2004
|
+
} else if (key.name === "q") {
|
|
2005
|
+
this.destroy();
|
|
2006
|
+
this.config?.onExit?.();
|
|
2007
|
+
}
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
if (key.name === "escape" || key.name === "p") {
|
|
2011
|
+
this.isPaused = true;
|
|
2012
|
+
this.pauseMenuIndex = 0;
|
|
2013
|
+
if (this.gameLoopTimer) {
|
|
2014
|
+
clearTimeout(this.gameLoopTimer);
|
|
2015
|
+
this.gameLoopTimer = null;
|
|
2016
|
+
}
|
|
2017
|
+
this.render();
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
if (key.name === "q") {
|
|
2021
|
+
this.destroy();
|
|
2022
|
+
this.config?.onExit?.();
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
if (this.state.isGameOver) {
|
|
2026
|
+
if (key.name === "r") {
|
|
2027
|
+
this.restart();
|
|
2028
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
2029
|
+
this.destroy();
|
|
2030
|
+
this.config?.onExit?.();
|
|
2031
|
+
}
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
2034
|
+
if (key.name === "left" || key.name === "a") {
|
|
2035
|
+
if (this.state.playerLane > 0) {
|
|
2036
|
+
this.state.playerLane--;
|
|
2037
|
+
this.render();
|
|
2038
|
+
}
|
|
2039
|
+
} else if (key.name === "right" || key.name === "d") {
|
|
2040
|
+
if (this.state.playerLane < LANE_COUNT - 1) {
|
|
2041
|
+
this.state.playerLane++;
|
|
2042
|
+
this.render();
|
|
2043
|
+
}
|
|
2044
|
+
} else if (key.name === "up" || key.name === "w" || key.name === "space") {
|
|
2045
|
+
if (!this.state.isJumping) {
|
|
2046
|
+
this.state.isJumping = true;
|
|
2047
|
+
this.state.jumpTicksRemaining = 3;
|
|
2048
|
+
this.render();
|
|
2049
|
+
}
|
|
2050
|
+
} else if (key.name === "down" || key.name === "s") {
|
|
2051
|
+
this.state.isJumping = false;
|
|
2052
|
+
this.state.jumpTicksRemaining = 0;
|
|
2053
|
+
this.render();
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
render() {
|
|
2057
|
+
const t = this.renderer.getTheme();
|
|
2058
|
+
if (this.showTutorial) {
|
|
2059
|
+
const lines = [
|
|
2060
|
+
"",
|
|
2061
|
+
t.highlight("OBJECTIVE: SPRINT THE FIBER HIGHWAY"),
|
|
2062
|
+
"",
|
|
2063
|
+
"\u2022 Use Left/Right (or A/D) to switch between 3 data lanes.",
|
|
2064
|
+
"\u2022 Press Up / Space to Phase Jump over low corrupted blocks.",
|
|
2065
|
+
"\u2022 Collect Clean Byte packets to boost your score.",
|
|
2066
|
+
"\u2022 Grab Power-ups: [SHLD] Shield, [SLOW] Buffer, [MAG] Magnet, [2X] Double.",
|
|
2067
|
+
"\u2022 Speed escalates continuously with distance.",
|
|
2068
|
+
"",
|
|
2069
|
+
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"),
|
|
2070
|
+
t.primary("Press Space or Enter to launch \u2502 Esc / Q to Exit")
|
|
2071
|
+
];
|
|
2072
|
+
const box = this.renderer.createBox(lines, 64, "BYTE RUNNER MANUAL");
|
|
2073
|
+
this.renderer.clear();
|
|
2074
|
+
this.renderer.draw(`
|
|
2075
|
+
|
|
2076
|
+
${box}
|
|
2077
|
+
`);
|
|
2078
|
+
return;
|
|
2079
|
+
}
|
|
2080
|
+
if (this.isPaused) {
|
|
2081
|
+
const pauseItems = ["Resume Runner (Esc / Enter)", "Restart Run (R)", "Quit to Arcade / Terminal (Q)"];
|
|
2082
|
+
const pauseLines = [
|
|
2083
|
+
"",
|
|
2084
|
+
t.highlight("\u2550\u2550\u2550 HIGHWAY PACKET STREAM PAUSED \u2550\u2550\u2550"),
|
|
2085
|
+
"",
|
|
2086
|
+
...pauseItems.map((item, idx) => {
|
|
2087
|
+
if (idx === this.pauseMenuIndex) {
|
|
2088
|
+
return t.primary(` \u25B6 ${t.highlight(item)}`);
|
|
2089
|
+
}
|
|
2090
|
+
return t.muted(` ${item}`);
|
|
2091
|
+
}),
|
|
2092
|
+
"",
|
|
2093
|
+
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"),
|
|
2094
|
+
t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
|
|
2095
|
+
];
|
|
2096
|
+
const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
|
|
2097
|
+
this.renderer.clear();
|
|
2098
|
+
this.renderer.draw(`
|
|
2099
|
+
|
|
2100
|
+
${pauseBox}
|
|
2101
|
+
`);
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
const header = this.renderer.renderHeader({
|
|
2105
|
+
title: "BYTE RUNNER",
|
|
2106
|
+
category: "ARCADE",
|
|
2107
|
+
difficulty: this.config?.difficulty,
|
|
2108
|
+
score: this.state.score
|
|
2109
|
+
});
|
|
2110
|
+
const hudLines = [];
|
|
2111
|
+
const distStr = `${t.muted("Distance:")} ${t.primary(`${this.state.distance}m`)}`;
|
|
2112
|
+
const bytesStr = `${t.muted("Clean Bytes:")} ${t.accent(this.state.cleanBytesCollected.toString())}`;
|
|
2113
|
+
const buffs = [];
|
|
2114
|
+
if (this.state.activeShield) buffs.push(t.success("[SHIELD ACTIVE]"));
|
|
2115
|
+
if (this.state.slowMotionTicks > 0) buffs.push(t.warning(`[SLOW-MO ${Math.ceil(this.state.slowMotionTicks / 10)}s]`));
|
|
2116
|
+
if (this.state.magnetTicks > 0) buffs.push(t.secondary(`[MAGNET ${Math.ceil(this.state.magnetTicks / 10)}s]`));
|
|
2117
|
+
if (this.state.doubleScoreTicks > 0) buffs.push(t.highlight(`[2X SCORE ${Math.ceil(this.state.doubleScoreTicks / 10)}s]`));
|
|
2118
|
+
hudLines.push(` ${distStr} ${bytesStr} ${buffs.join(" ")}`);
|
|
2119
|
+
hudLines.push("");
|
|
2120
|
+
const trackWidth = 54;
|
|
2121
|
+
const laneWidth = 18;
|
|
2122
|
+
const trackLines = [];
|
|
2123
|
+
trackLines.push(` ${t.border("\u250C" + "\u2500".repeat(trackWidth) + "\u2510")}`);
|
|
2124
|
+
for (let y = 0; y < HIGHWAY_HEIGHT; y++) {
|
|
2125
|
+
let rowContent = "";
|
|
2126
|
+
for (let lane = 0; lane < LANE_COUNT; lane++) {
|
|
2127
|
+
const ent = this.entities.find((e) => e.lane === lane && e.y === y);
|
|
2128
|
+
let cellText = " ".repeat(laneWidth);
|
|
2129
|
+
if (ent) {
|
|
2130
|
+
let formattedLabel = ent.label;
|
|
2131
|
+
if (ent.type === "corrupt") {
|
|
2132
|
+
formattedLabel = t.error(ent.label);
|
|
2133
|
+
} else if (ent.type === "clean") {
|
|
2134
|
+
formattedLabel = t.success(ent.label);
|
|
2135
|
+
} else if (ent.type === "powerup") {
|
|
2136
|
+
formattedLabel = t.highlight(ent.label);
|
|
2137
|
+
}
|
|
2138
|
+
const cleanLen = ent.label.length;
|
|
2139
|
+
const leftPad = Math.floor((laneWidth - cleanLen) / 2);
|
|
2140
|
+
const rightPad = laneWidth - cleanLen - leftPad;
|
|
2141
|
+
cellText = " ".repeat(Math.max(0, leftPad)) + formattedLabel + " ".repeat(Math.max(0, rightPad));
|
|
2142
|
+
}
|
|
2143
|
+
if (y === HIGHWAY_HEIGHT - 2 && lane === this.state.playerLane) {
|
|
2144
|
+
const avatar = this.state.isJumping ? "\u25B2 [AIRBORNE] \u25B2" : "\u25B2\u2550\u2550[RUNNER]\u2550\u2550\u25B2";
|
|
2145
|
+
const colored = this.state.activeShield ? t.highlight(avatar) : t.primary(avatar);
|
|
2146
|
+
const pad = Math.max(0, Math.floor((laneWidth - 14) / 2));
|
|
2147
|
+
cellText = " ".repeat(pad) + colored + " ".repeat(Math.max(0, laneWidth - 14 - pad));
|
|
2148
|
+
}
|
|
2149
|
+
rowContent += cellText + (lane < LANE_COUNT - 1 ? t.border("\u2506") : "");
|
|
2150
|
+
}
|
|
2151
|
+
trackLines.push(` ${t.border("\u2502")}${rowContent}${t.border("\u2502")}`);
|
|
2152
|
+
}
|
|
2153
|
+
trackLines.push(` ${t.border("\u2514" + "\u2500".repeat(trackWidth) + "\u2518")}`);
|
|
2154
|
+
if (this.state.isGameOver) {
|
|
2155
|
+
trackLines.push(`
|
|
2156
|
+
${t.error("\u{1F4A5} SYSTEM FAULT: PACKET CORRUPTED!")}`);
|
|
2157
|
+
trackLines.push(` ${t.accent(`Final Distance: ${this.state.distance}m \u2502 Final Score: ${this.state.score}`)}`);
|
|
2158
|
+
trackLines.push(` ${t.muted("Press R to Re-engage Runner, or Esc / Q to Exit.")}`);
|
|
2159
|
+
} else {
|
|
2160
|
+
trackLines.push(` ${t.muted("Controls: Left/Right: Lane \u2502 Up/Space: Jump \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
|
|
2161
|
+
}
|
|
2162
|
+
this.renderer.clear();
|
|
2163
|
+
this.renderer.draw(`
|
|
2164
|
+
${header}
|
|
2165
|
+
${hudLines.join("\n")}
|
|
2166
|
+
${trackLines.join("\n")}
|
|
2167
|
+
`);
|
|
2168
|
+
}
|
|
2169
|
+
getState() {
|
|
2170
|
+
return this.state;
|
|
2171
|
+
}
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
// src/games/packet-man/index.ts
|
|
2175
|
+
var MAZE_TEMPLATE = [
|
|
2176
|
+
"###########################",
|
|
2177
|
+
"#............#............#",
|
|
2178
|
+
"#.####.#####.#.#####.####.#",
|
|
2179
|
+
"#O####.#####.#.#####.####O#",
|
|
2180
|
+
"#.####.#####.#.#####.####.#",
|
|
2181
|
+
"#.........................#",
|
|
2182
|
+
"#.####.##.#######.##.####.#",
|
|
2183
|
+
"#......##....#....##......#",
|
|
2184
|
+
"######.##### # #####.######",
|
|
2185
|
+
" #.# #.# ",
|
|
2186
|
+
"######.# ###---### #.######",
|
|
2187
|
+
"#......# # # #......#",
|
|
2188
|
+
"#.####.# ######### #.####.#",
|
|
2189
|
+
"#O..##...............##..O#",
|
|
2190
|
+
"###.##.##.#######.##.##.###",
|
|
2191
|
+
"#......##....#....##......#",
|
|
2192
|
+
"#.##########.#.##########.#",
|
|
2193
|
+
"#.........................#",
|
|
2194
|
+
"###########################"
|
|
2195
|
+
];
|
|
2196
|
+
var MAZE_WIDTH = 27;
|
|
2197
|
+
var MAZE_HEIGHT = 19;
|
|
2198
|
+
var PacketManGame = class {
|
|
2199
|
+
id = "packet-man";
|
|
2200
|
+
metadata = ALL_GAMES_METADATA["packet-man"];
|
|
2201
|
+
config = null;
|
|
2202
|
+
renderer = defaultRenderer;
|
|
2203
|
+
input = new TerminalInputHandler();
|
|
2204
|
+
rng = new DeterministicRNG();
|
|
2205
|
+
gameLoopTimer = null;
|
|
2206
|
+
grid = [];
|
|
2207
|
+
daemons = [];
|
|
2208
|
+
daemonsChompedInSurge = 0;
|
|
2209
|
+
pelletsEatenCount = 0;
|
|
2210
|
+
state = {
|
|
2211
|
+
playerX: 13,
|
|
2212
|
+
playerY: 13,
|
|
2213
|
+
playerDx: 0,
|
|
2214
|
+
playerDy: 0,
|
|
2215
|
+
desiredDx: 0,
|
|
2216
|
+
desiredDy: 0,
|
|
2217
|
+
mouthOpen: true,
|
|
2218
|
+
lives: 3,
|
|
2219
|
+
score: 0,
|
|
2220
|
+
level: 1,
|
|
2221
|
+
pelletsRemaining: 0,
|
|
2222
|
+
totalPellets: 0,
|
|
2223
|
+
frightenedTicksRemaining: 0,
|
|
2224
|
+
frightenedCombo: 0,
|
|
2225
|
+
isWon: false,
|
|
2226
|
+
isGameOver: false
|
|
2227
|
+
};
|
|
2228
|
+
isPaused = false;
|
|
2229
|
+
pauseMenuIndex = 0;
|
|
2230
|
+
showTutorial = true;
|
|
2231
|
+
tickIntervalMs = 150;
|
|
2232
|
+
init(config) {
|
|
2233
|
+
this.config = config;
|
|
2234
|
+
this.renderer.setTheme(config.theme);
|
|
2235
|
+
this.rng = new DeterministicRNG(config.seed || Date.now());
|
|
2236
|
+
if (config.skipTutorial !== void 0) {
|
|
2237
|
+
this.showTutorial = !config.skipTutorial;
|
|
2238
|
+
}
|
|
2239
|
+
this.resetGame(1, config.difficulty);
|
|
2240
|
+
}
|
|
2241
|
+
start() {
|
|
2242
|
+
this.isPaused = false;
|
|
2243
|
+
this.render();
|
|
2244
|
+
this.input.start(
|
|
2245
|
+
(key) => this.handleInput(key),
|
|
2246
|
+
() => {
|
|
2247
|
+
this.destroy();
|
|
2248
|
+
process.exit(0);
|
|
2249
|
+
}
|
|
2250
|
+
);
|
|
2251
|
+
this.scheduleNextTick();
|
|
2252
|
+
}
|
|
2253
|
+
pause() {
|
|
2254
|
+
this.isPaused = true;
|
|
2255
|
+
if (this.gameLoopTimer) {
|
|
2256
|
+
clearTimeout(this.gameLoopTimer);
|
|
2257
|
+
this.gameLoopTimer = null;
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
resume() {
|
|
2261
|
+
this.isPaused = false;
|
|
2262
|
+
this.scheduleNextTick();
|
|
2263
|
+
this.render();
|
|
2264
|
+
}
|
|
2265
|
+
restart() {
|
|
2266
|
+
if (this.config) {
|
|
2267
|
+
this.resetGame(1, this.config.difficulty);
|
|
2268
|
+
this.scheduleNextTick();
|
|
2269
|
+
this.render();
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
saveState() {
|
|
2273
|
+
return {
|
|
2274
|
+
state: this.state,
|
|
2275
|
+
grid: this.grid,
|
|
2276
|
+
daemons: this.daemons,
|
|
2277
|
+
showTutorial: this.showTutorial
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
loadState(saved) {
|
|
2281
|
+
if (saved["state"]) this.state = saved["state"];
|
|
2282
|
+
if (saved["grid"]) this.grid = saved["grid"];
|
|
2283
|
+
if (saved["daemons"]) this.daemons = saved["daemons"];
|
|
2284
|
+
if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
|
|
2285
|
+
}
|
|
2286
|
+
destroy() {
|
|
2287
|
+
if (this.gameLoopTimer) {
|
|
2288
|
+
clearTimeout(this.gameLoopTimer);
|
|
2289
|
+
this.gameLoopTimer = null;
|
|
2290
|
+
}
|
|
2291
|
+
this.input.stop();
|
|
2292
|
+
}
|
|
2293
|
+
resetGame(level, difficulty) {
|
|
2294
|
+
switch (difficulty) {
|
|
2295
|
+
case "easy":
|
|
2296
|
+
this.tickIntervalMs = 175;
|
|
2297
|
+
break;
|
|
2298
|
+
case "normal":
|
|
2299
|
+
this.tickIntervalMs = 145;
|
|
2300
|
+
break;
|
|
2301
|
+
case "hard":
|
|
2302
|
+
this.tickIntervalMs = 120;
|
|
2303
|
+
break;
|
|
2304
|
+
case "insane":
|
|
2305
|
+
this.tickIntervalMs = 95;
|
|
2306
|
+
break;
|
|
2307
|
+
}
|
|
2308
|
+
this.state = {
|
|
2309
|
+
playerX: 13,
|
|
2310
|
+
playerY: 13,
|
|
2311
|
+
playerDx: -1,
|
|
2312
|
+
playerDy: 0,
|
|
2313
|
+
desiredDx: -1,
|
|
2314
|
+
desiredDy: 0,
|
|
2315
|
+
mouthOpen: true,
|
|
2316
|
+
lives: 3,
|
|
2317
|
+
score: this.state.score,
|
|
2318
|
+
level,
|
|
2319
|
+
pelletsRemaining: 0,
|
|
2320
|
+
totalPellets: 0,
|
|
2321
|
+
frightenedTicksRemaining: 0,
|
|
2322
|
+
frightenedCombo: 0,
|
|
2323
|
+
isWon: false,
|
|
2324
|
+
isGameOver: false
|
|
2325
|
+
};
|
|
2326
|
+
this.daemonsChompedInSurge = 0;
|
|
2327
|
+
this.loadMaze();
|
|
2328
|
+
this.resetDaemons();
|
|
2329
|
+
}
|
|
2330
|
+
loadMaze() {
|
|
2331
|
+
this.grid = [];
|
|
2332
|
+
let pellets = 0;
|
|
2333
|
+
for (let y = 0; y < MAZE_HEIGHT; y++) {
|
|
2334
|
+
const row = [];
|
|
2335
|
+
const line = MAZE_TEMPLATE[y] || "";
|
|
2336
|
+
for (let x = 0; x < MAZE_WIDTH; x++) {
|
|
2337
|
+
const char = line[x] || " ";
|
|
2338
|
+
if (char === "#") {
|
|
2339
|
+
row.push("wall");
|
|
2340
|
+
} else if (char === ".") {
|
|
2341
|
+
row.push("pellet");
|
|
2342
|
+
pellets++;
|
|
2343
|
+
} else if (char === "O") {
|
|
2344
|
+
row.push("power");
|
|
2345
|
+
pellets++;
|
|
2346
|
+
} else if (char === "-") {
|
|
2347
|
+
row.push("gate");
|
|
2348
|
+
} else {
|
|
2349
|
+
row.push("empty");
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
this.grid.push(row);
|
|
2353
|
+
}
|
|
2354
|
+
this.state.pelletsRemaining = pellets;
|
|
2355
|
+
this.state.totalPellets = pellets;
|
|
2356
|
+
}
|
|
2357
|
+
resetDaemons() {
|
|
2358
|
+
this.daemons = [
|
|
2359
|
+
{
|
|
2360
|
+
id: "blinky",
|
|
2361
|
+
name: "Blinky",
|
|
2362
|
+
x: 13,
|
|
2363
|
+
y: 7,
|
|
2364
|
+
dx: 1,
|
|
2365
|
+
dy: 0,
|
|
2366
|
+
baseX: 25,
|
|
2367
|
+
baseY: 1,
|
|
2368
|
+
state: "chase",
|
|
2369
|
+
frightenedTicks: 0,
|
|
2370
|
+
colorName: "red"
|
|
2371
|
+
},
|
|
2372
|
+
{
|
|
2373
|
+
id: "pinky",
|
|
2374
|
+
name: "Pinky",
|
|
2375
|
+
x: 12,
|
|
2376
|
+
y: 11,
|
|
2377
|
+
dx: 0,
|
|
2378
|
+
dy: -1,
|
|
2379
|
+
baseX: 1,
|
|
2380
|
+
baseY: 1,
|
|
2381
|
+
state: "chase",
|
|
2382
|
+
frightenedTicks: 0,
|
|
2383
|
+
colorName: "pink"
|
|
2384
|
+
},
|
|
2385
|
+
{
|
|
2386
|
+
id: "inky",
|
|
2387
|
+
name: "Inky",
|
|
2388
|
+
x: 13,
|
|
2389
|
+
y: 11,
|
|
2390
|
+
dx: 0,
|
|
2391
|
+
dy: -1,
|
|
2392
|
+
baseX: 25,
|
|
2393
|
+
baseY: 17,
|
|
2394
|
+
state: "chase",
|
|
2395
|
+
frightenedTicks: 0,
|
|
2396
|
+
colorName: "cyan"
|
|
2397
|
+
},
|
|
2398
|
+
{
|
|
2399
|
+
id: "clyde",
|
|
2400
|
+
name: "Clyde",
|
|
2401
|
+
x: 14,
|
|
2402
|
+
y: 11,
|
|
2403
|
+
dx: 0,
|
|
2404
|
+
dy: -1,
|
|
2405
|
+
baseX: 1,
|
|
2406
|
+
baseY: 17,
|
|
2407
|
+
state: "chase",
|
|
2408
|
+
frightenedTicks: 0,
|
|
2409
|
+
colorName: "yellow"
|
|
2410
|
+
}
|
|
2411
|
+
];
|
|
2412
|
+
}
|
|
2413
|
+
scheduleNextTick() {
|
|
2414
|
+
if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
|
|
2415
|
+
if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
|
|
2416
|
+
this.gameLoopTimer = setTimeout(() => {
|
|
2417
|
+
this.tick();
|
|
2418
|
+
this.scheduleNextTick();
|
|
2419
|
+
}, this.tickIntervalMs);
|
|
2420
|
+
}
|
|
2421
|
+
tick() {
|
|
2422
|
+
if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
|
|
2423
|
+
this.state.mouthOpen = !this.state.mouthOpen;
|
|
2424
|
+
if (this.state.frightenedTicksRemaining > 0) {
|
|
2425
|
+
this.state.frightenedTicksRemaining--;
|
|
2426
|
+
if (this.state.frightenedTicksRemaining === 0) {
|
|
2427
|
+
for (const d of this.daemons) {
|
|
2428
|
+
if (d.state === "frightened") d.state = "chase";
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
if (this.canMove(this.state.playerX, this.state.playerY, this.state.desiredDx, this.state.desiredDy)) {
|
|
2433
|
+
this.state.playerDx = this.state.desiredDx;
|
|
2434
|
+
this.state.playerDy = this.state.desiredDy;
|
|
2435
|
+
}
|
|
2436
|
+
if (this.canMove(this.state.playerX, this.state.playerY, this.state.playerDx, this.state.playerDy)) {
|
|
2437
|
+
this.state.playerX += this.state.playerDx;
|
|
2438
|
+
this.state.playerY += this.state.playerDy;
|
|
2439
|
+
if (this.state.playerX < 0) this.state.playerX = MAZE_WIDTH - 1;
|
|
2440
|
+
else if (this.state.playerX >= MAZE_WIDTH) this.state.playerX = 0;
|
|
2441
|
+
this.chompCurrentTile();
|
|
2442
|
+
}
|
|
2443
|
+
this.moveDaemons();
|
|
2444
|
+
this.checkCollisions();
|
|
2445
|
+
this.render();
|
|
2446
|
+
}
|
|
2447
|
+
canMove(x, y, dx, dy, isDaemon = false) {
|
|
2448
|
+
let nx = x + dx;
|
|
2449
|
+
let ny = y + dy;
|
|
2450
|
+
if (nx < 0) nx = MAZE_WIDTH - 1;
|
|
2451
|
+
else if (nx >= MAZE_WIDTH) nx = 0;
|
|
2452
|
+
if (ny < 0 || ny >= MAZE_HEIGHT) return false;
|
|
2453
|
+
const tile = this.grid[ny]?.[nx];
|
|
2454
|
+
if (!tile || tile === "wall") return false;
|
|
2455
|
+
if (tile === "gate" && !isDaemon) return false;
|
|
2456
|
+
return true;
|
|
2457
|
+
}
|
|
2458
|
+
chompCurrentTile() {
|
|
2459
|
+
const tile = this.grid[this.state.playerY]?.[this.state.playerX];
|
|
2460
|
+
if (tile === "pellet") {
|
|
2461
|
+
this.grid[this.state.playerY][this.state.playerX] = "empty";
|
|
2462
|
+
this.state.score += 10;
|
|
2463
|
+
this.state.pelletsRemaining--;
|
|
2464
|
+
this.pelletsEatenCount++;
|
|
2465
|
+
this.config?.onScoreUpdate?.(this.state.score);
|
|
2466
|
+
if (this.pelletsEatenCount >= 50) {
|
|
2467
|
+
this.config?.onAchievementUnlock?.("first_chomp");
|
|
2468
|
+
}
|
|
2469
|
+
if (this.state.pelletsRemaining === 0) {
|
|
2470
|
+
this.state.isWon = true;
|
|
2471
|
+
this.config?.onAchievementUnlock?.("maze_sweeper");
|
|
2472
|
+
return;
|
|
2473
|
+
}
|
|
2474
|
+
} else if (tile === "power") {
|
|
2475
|
+
this.grid[this.state.playerY][this.state.playerX] = "empty";
|
|
2476
|
+
this.state.score += 50;
|
|
2477
|
+
this.state.pelletsRemaining--;
|
|
2478
|
+
this.daemonsChompedInSurge = 0;
|
|
2479
|
+
let surgeTicks = 45;
|
|
2480
|
+
if (this.config?.difficulty === "easy") surgeTicks = 65;
|
|
2481
|
+
else if (this.config?.difficulty === "hard") surgeTicks = 30;
|
|
2482
|
+
else if (this.config?.difficulty === "insane") surgeTicks = 18;
|
|
2483
|
+
this.state.frightenedTicksRemaining = surgeTicks;
|
|
2484
|
+
this.state.frightenedCombo = 0;
|
|
2485
|
+
for (const d of this.daemons) {
|
|
2486
|
+
if (d.state !== "eaten") {
|
|
2487
|
+
d.state = "frightened";
|
|
2488
|
+
d.dx = -d.dx;
|
|
2489
|
+
d.dy = -d.dy;
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
if (this.config?.soundEnabled) playTerminalBell();
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
moveDaemons() {
|
|
2496
|
+
const directions = [
|
|
2497
|
+
[0, -1],
|
|
2498
|
+
// Up
|
|
2499
|
+
[-1, 0],
|
|
2500
|
+
// Left
|
|
2501
|
+
[0, 1],
|
|
2502
|
+
// Down
|
|
2503
|
+
[1, 0]
|
|
2504
|
+
// Right
|
|
2505
|
+
];
|
|
2506
|
+
for (const d of this.daemons) {
|
|
2507
|
+
if (d.state === "eaten") {
|
|
2508
|
+
if (d.x === 13 && d.y === 9) {
|
|
2509
|
+
d.state = "chase";
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
const validDirs = [];
|
|
2513
|
+
for (const [dx, dy] of directions) {
|
|
2514
|
+
if (dx === -d.dx && dy === -d.dy) continue;
|
|
2515
|
+
if (this.canMove(d.x, d.y, dx, dy, true)) {
|
|
2516
|
+
validDirs.push([dx, dy]);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
if (validDirs.length === 0) {
|
|
2520
|
+
if (this.canMove(d.x, d.y, -d.dx, -d.dy, true)) {
|
|
2521
|
+
validDirs.push([-d.dx, -d.dy]);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
if (validDirs.length > 0) {
|
|
2525
|
+
let chosenDir;
|
|
2526
|
+
if (d.state === "frightened") {
|
|
2527
|
+
chosenDir = this.rng.pick(validDirs);
|
|
2528
|
+
} else {
|
|
2529
|
+
let targetX = this.state.playerX;
|
|
2530
|
+
let targetY = this.state.playerY;
|
|
2531
|
+
if (d.id === "pinky") {
|
|
2532
|
+
targetX += this.state.playerDx * 4;
|
|
2533
|
+
targetY += this.state.playerDy * 4;
|
|
2534
|
+
} else if (d.id === "clyde") {
|
|
2535
|
+
const dist = Math.hypot(d.x - this.state.playerX, d.y - this.state.playerY);
|
|
2536
|
+
if (dist < 6) {
|
|
2537
|
+
targetX = d.baseX;
|
|
2538
|
+
targetY = d.baseY;
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
chosenDir = validDirs[0];
|
|
2542
|
+
let minDist = Infinity;
|
|
2543
|
+
for (const [vx, vy] of validDirs) {
|
|
2544
|
+
const nx = d.x + vx;
|
|
2545
|
+
const ny = d.y + vy;
|
|
2546
|
+
const dist = Math.hypot(nx - targetX, ny - targetY);
|
|
2547
|
+
if (dist < minDist) {
|
|
2548
|
+
minDist = dist;
|
|
2549
|
+
chosenDir = [vx, vy];
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
d.dx = chosenDir[0];
|
|
2554
|
+
d.dy = chosenDir[1];
|
|
2555
|
+
d.x += d.dx;
|
|
2556
|
+
d.y += d.dy;
|
|
2557
|
+
if (d.x < 0) d.x = MAZE_WIDTH - 1;
|
|
2558
|
+
else if (d.x >= MAZE_WIDTH) d.x = 0;
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
checkCollisions() {
|
|
2563
|
+
for (const d of this.daemons) {
|
|
2564
|
+
if (d.x === this.state.playerX && d.y === this.state.playerY) {
|
|
2565
|
+
if (d.state === "frightened") {
|
|
2566
|
+
d.state = "eaten";
|
|
2567
|
+
d.x = 13;
|
|
2568
|
+
d.y = 9;
|
|
2569
|
+
this.state.frightenedCombo++;
|
|
2570
|
+
const points = 200 * Math.pow(2, this.state.frightenedCombo - 1);
|
|
2571
|
+
this.state.score += points;
|
|
2572
|
+
this.daemonsChompedInSurge++;
|
|
2573
|
+
if (this.daemonsChompedInSurge >= 4) {
|
|
2574
|
+
this.config?.onAchievementUnlock?.("daemon_slayer");
|
|
2575
|
+
}
|
|
2576
|
+
if (this.config?.soundEnabled) playTerminalBell();
|
|
2577
|
+
} else if (d.state === "chase") {
|
|
2578
|
+
this.state.lives--;
|
|
2579
|
+
if (this.config?.soundEnabled) playTerminalBell();
|
|
2580
|
+
if (this.state.lives <= 0) {
|
|
2581
|
+
this.state.isGameOver = true;
|
|
2582
|
+
this.config?.onGameOver?.(this.state.score);
|
|
2583
|
+
} else {
|
|
2584
|
+
this.state.playerX = 13;
|
|
2585
|
+
this.state.playerY = 13;
|
|
2586
|
+
this.state.playerDx = -1;
|
|
2587
|
+
this.state.playerDy = 0;
|
|
2588
|
+
this.state.desiredDx = -1;
|
|
2589
|
+
this.state.desiredDy = 0;
|
|
2590
|
+
this.resetDaemons();
|
|
2591
|
+
}
|
|
2592
|
+
break;
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
handleInput(key) {
|
|
2598
|
+
if (this.showTutorial) {
|
|
2599
|
+
if (key.name === "return" || key.name === "space") {
|
|
2600
|
+
this.showTutorial = false;
|
|
2601
|
+
this.scheduleNextTick();
|
|
2602
|
+
this.render();
|
|
2603
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
2604
|
+
this.destroy();
|
|
2605
|
+
this.config?.onExit?.();
|
|
2606
|
+
}
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
if (this.isPaused) {
|
|
2610
|
+
if (key.name === "up" || key.name === "w") {
|
|
2611
|
+
this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
|
|
2612
|
+
this.render();
|
|
2613
|
+
} else if (key.name === "down" || key.name === "s") {
|
|
2614
|
+
this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
|
|
2615
|
+
this.render();
|
|
2616
|
+
} else if (key.name === "return" || key.name === "space") {
|
|
2617
|
+
if (this.pauseMenuIndex === 0) {
|
|
2618
|
+
this.isPaused = false;
|
|
2619
|
+
this.scheduleNextTick();
|
|
2620
|
+
this.render();
|
|
2621
|
+
} else if (this.pauseMenuIndex === 1) {
|
|
2622
|
+
this.isPaused = false;
|
|
2623
|
+
this.resetGame(this.state.level, this.config?.difficulty || "normal");
|
|
2624
|
+
this.scheduleNextTick();
|
|
2625
|
+
this.render();
|
|
2626
|
+
} else if (this.pauseMenuIndex === 2) {
|
|
2627
|
+
this.destroy();
|
|
2628
|
+
this.config?.onExit?.();
|
|
2629
|
+
}
|
|
2630
|
+
} else if (key.name === "escape" || key.name === "p") {
|
|
2631
|
+
this.isPaused = false;
|
|
2632
|
+
this.scheduleNextTick();
|
|
2633
|
+
this.render();
|
|
2634
|
+
} else if (key.name === "q") {
|
|
2635
|
+
this.destroy();
|
|
2636
|
+
this.config?.onExit?.();
|
|
2637
|
+
}
|
|
2638
|
+
return;
|
|
2639
|
+
}
|
|
2640
|
+
if (key.name === "escape" || key.name === "p") {
|
|
2641
|
+
this.isPaused = true;
|
|
2642
|
+
this.pauseMenuIndex = 0;
|
|
2643
|
+
if (this.gameLoopTimer) {
|
|
2644
|
+
clearTimeout(this.gameLoopTimer);
|
|
2645
|
+
this.gameLoopTimer = null;
|
|
2646
|
+
}
|
|
2647
|
+
this.render();
|
|
2648
|
+
return;
|
|
2649
|
+
}
|
|
2650
|
+
if (key.name === "q") {
|
|
2651
|
+
this.destroy();
|
|
2652
|
+
this.config?.onExit?.();
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
if (this.state.isWon) {
|
|
2656
|
+
if (key.name === "return" || key.name === "space") {
|
|
2657
|
+
this.resetGame(this.state.level + 1, this.config?.difficulty || "normal");
|
|
2658
|
+
this.scheduleNextTick();
|
|
2659
|
+
this.render();
|
|
2660
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
2661
|
+
this.destroy();
|
|
2662
|
+
this.config?.onExit?.();
|
|
2663
|
+
}
|
|
2664
|
+
return;
|
|
2665
|
+
}
|
|
2666
|
+
if (this.state.isGameOver) {
|
|
2667
|
+
if (key.name === "r") {
|
|
2668
|
+
this.restart();
|
|
2669
|
+
} else if (key.name === "escape" || key.name === "q") {
|
|
2670
|
+
this.destroy();
|
|
2671
|
+
this.config?.onExit?.();
|
|
2672
|
+
}
|
|
2673
|
+
return;
|
|
2674
|
+
}
|
|
2675
|
+
if (key.name === "up" || key.name === "w") {
|
|
2676
|
+
this.state.desiredDx = 0;
|
|
2677
|
+
this.state.desiredDy = -1;
|
|
2678
|
+
} else if (key.name === "down" || key.name === "s") {
|
|
2679
|
+
this.state.desiredDx = 0;
|
|
2680
|
+
this.state.desiredDy = 1;
|
|
2681
|
+
} else if (key.name === "left" || key.name === "a") {
|
|
2682
|
+
this.state.desiredDx = -1;
|
|
2683
|
+
this.state.desiredDy = 0;
|
|
2684
|
+
} else if (key.name === "right" || key.name === "d") {
|
|
2685
|
+
this.state.desiredDx = 1;
|
|
2686
|
+
this.state.desiredDy = 0;
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
render() {
|
|
2690
|
+
const t = this.renderer.getTheme();
|
|
2691
|
+
if (this.showTutorial) {
|
|
2692
|
+
const lines = [
|
|
2693
|
+
"",
|
|
2694
|
+
t.highlight("OBJECTIVE: CHOMP BYTE PELLETS & PURGE DAEMONS"),
|
|
2695
|
+
"",
|
|
2696
|
+
"\u2022 Use Arrow Keys or WASD to navigate memory corridors.",
|
|
2697
|
+
"\u2022 Chomp all data pellets [ \xB7 ] to clear the sector.",
|
|
2698
|
+
"\u2022 Ingest Super Capacitors [ \u25CF ] to trigger Power Surge state.",
|
|
2699
|
+
"\u2022 During Power Surge, hunt vulnerable memory daemons for huge multipliers!",
|
|
2700
|
+
"\u2022 Wrap through the side tunnels to evade ambushes.",
|
|
2701
|
+
"",
|
|
2702
|
+
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"),
|
|
2703
|
+
t.primary("Press Space or Enter to start \u2502 Esc / Q to Exit")
|
|
2704
|
+
];
|
|
2705
|
+
const box = this.renderer.createBox(lines, 64, "PACKET MAN PROTOCOL MANUAL");
|
|
2706
|
+
this.renderer.clear();
|
|
2707
|
+
this.renderer.draw(`
|
|
2708
|
+
|
|
2709
|
+
${box}
|
|
2710
|
+
`);
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
if (this.isPaused) {
|
|
2714
|
+
const pauseItems = ["Resume Arcade (Esc / Enter)", "Restart Round (R)", "Quit to Arcade / Terminal (Q)"];
|
|
2715
|
+
const pauseLines = [
|
|
2716
|
+
"",
|
|
2717
|
+
t.highlight("\u2550\u2550\u2550 MEMORY MAZE PAUSED \u2550\u2550\u2550"),
|
|
2718
|
+
"",
|
|
2719
|
+
...pauseItems.map((item, idx) => {
|
|
2720
|
+
if (idx === this.pauseMenuIndex) {
|
|
2721
|
+
return t.primary(` \u25B6 ${t.highlight(item)}`);
|
|
2722
|
+
}
|
|
2723
|
+
return t.muted(` ${item}`);
|
|
2724
|
+
}),
|
|
2725
|
+
"",
|
|
2726
|
+
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"),
|
|
2727
|
+
t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
|
|
2728
|
+
];
|
|
2729
|
+
const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
|
|
2730
|
+
this.renderer.clear();
|
|
2731
|
+
this.renderer.draw(`
|
|
2732
|
+
|
|
2733
|
+
${pauseBox}
|
|
2734
|
+
`);
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
const header = this.renderer.renderHeader({
|
|
2738
|
+
title: "PACKET MAN",
|
|
2739
|
+
category: "ARCADE",
|
|
2740
|
+
difficulty: this.config?.difficulty,
|
|
2741
|
+
score: this.state.score,
|
|
2742
|
+
level: this.state.level
|
|
2743
|
+
});
|
|
2744
|
+
const hudLines = [];
|
|
2745
|
+
const livesStr = `${t.muted("Buffer Lives:")} ${t.highlight("\u25BA ".repeat(Math.max(0, this.state.lives)))}`;
|
|
2746
|
+
const surgeStr = this.state.frightenedTicksRemaining > 0 ? t.warning(`\u26A1 OVERCLOCK SURGE [${Math.ceil(this.state.frightenedTicksRemaining / 5)}s]`) : t.muted("NORMAL FLUX");
|
|
2747
|
+
hudLines.push(` ${livesStr} ${surgeStr} ${t.muted("Pellets:")} ${t.primary(this.state.pelletsRemaining.toString())}`);
|
|
2748
|
+
const boardLines = [];
|
|
2749
|
+
for (let y = 0; y < MAZE_HEIGHT; y++) {
|
|
2750
|
+
let row = " ";
|
|
2751
|
+
for (let x = 0; x < MAZE_WIDTH; x++) {
|
|
2752
|
+
if (x === this.state.playerX && y === this.state.playerY) {
|
|
2753
|
+
const char = this.getPlayerGlyph();
|
|
2754
|
+
row += t.highlight(char);
|
|
2755
|
+
continue;
|
|
2756
|
+
}
|
|
2757
|
+
const daemon = this.daemons.find((d) => d.x === x && d.y === y);
|
|
2758
|
+
if (daemon) {
|
|
2759
|
+
row += this.getDaemonGlyph(daemon);
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
const tile = this.grid[y][x];
|
|
2763
|
+
if (tile === "wall") {
|
|
2764
|
+
row += t.border("\u2588\u2588");
|
|
2765
|
+
} else if (tile === "pellet") {
|
|
2766
|
+
row += t.primary(" \xB7");
|
|
2767
|
+
} else if (tile === "power") {
|
|
2768
|
+
row += t.accent(" \u25CF");
|
|
2769
|
+
} else if (tile === "gate") {
|
|
2770
|
+
row += t.secondary("\u2550\u2550");
|
|
2771
|
+
} else {
|
|
2772
|
+
row += " ";
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
boardLines.push(row);
|
|
2776
|
+
}
|
|
2777
|
+
if (this.state.isWon) {
|
|
2778
|
+
boardLines.push(`
|
|
2779
|
+
${t.success("\u{1F389} MEMORY SECTOR COMPLETELY PURGED! EXCELLENT OPERATOR.")}`);
|
|
2780
|
+
boardLines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
|
|
2781
|
+
} else if (this.state.isGameOver) {
|
|
2782
|
+
boardLines.push(`
|
|
2783
|
+
${t.error("\u{1F4A5} SYSTEM FAULT: LIVES DEPLETED. KERNEL DUMP.")}`);
|
|
2784
|
+
boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Exit.")}`);
|
|
2785
|
+
} else {
|
|
2786
|
+
boardLines.push(`
|
|
2787
|
+
${t.muted("Controls: Arrows/WASD: Move \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
|
|
2788
|
+
}
|
|
2789
|
+
this.renderer.clear();
|
|
2790
|
+
this.renderer.draw(`
|
|
2791
|
+
${header}
|
|
2792
|
+
${hudLines.join("\n")}
|
|
2793
|
+
${boardLines.join("\n")}
|
|
2794
|
+
`);
|
|
2795
|
+
}
|
|
2796
|
+
getPlayerGlyph() {
|
|
2797
|
+
if (!this.state.mouthOpen) return "\u25CB ";
|
|
2798
|
+
if (this.state.playerDx === 1) return "\u25BA ";
|
|
2799
|
+
if (this.state.playerDx === -1) return "\u25C4 ";
|
|
2800
|
+
if (this.state.playerDy === -1) return "\u25B2 ";
|
|
2801
|
+
if (this.state.playerDy === 1) return "\u25BC ";
|
|
2802
|
+
return "\u25BA ";
|
|
2803
|
+
}
|
|
2804
|
+
getDaemonGlyph(d) {
|
|
2805
|
+
const t = this.renderer.getTheme();
|
|
2806
|
+
if (d.state === "frightened") {
|
|
2807
|
+
if (this.state.frightenedTicksRemaining < 10 && this.state.frightenedTicksRemaining % 2 === 0) {
|
|
2808
|
+
return t.accent("\xA7 ");
|
|
2809
|
+
}
|
|
2810
|
+
return t.secondary("\xA7 ");
|
|
2811
|
+
}
|
|
2812
|
+
if (d.state === "eaten") {
|
|
2813
|
+
return t.muted('""');
|
|
2814
|
+
}
|
|
2815
|
+
if (d.colorName === "red") return t.error("M ");
|
|
2816
|
+
if (d.colorName === "pink") return t.secondary("M ");
|
|
2817
|
+
if (d.colorName === "cyan") return t.primary("M ");
|
|
2818
|
+
return t.accent("M ");
|
|
2819
|
+
}
|
|
2820
|
+
getState() {
|
|
2821
|
+
return this.state;
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
|
|
2825
|
+
export {
|
|
2826
|
+
APP_NAME,
|
|
2827
|
+
APP_TAGLINE,
|
|
2828
|
+
APP_VERSION,
|
|
2829
|
+
MIN_TERMINAL_COLUMNS,
|
|
2830
|
+
MIN_TERMINAL_ROWS,
|
|
2831
|
+
ALL_GAMES_METADATA,
|
|
2832
|
+
UserSettingsSchema,
|
|
2833
|
+
UserProfileSchema,
|
|
2834
|
+
StorageManager,
|
|
2835
|
+
defaultStorage,
|
|
2836
|
+
AchievementManager,
|
|
2837
|
+
defaultAchievements,
|
|
2838
|
+
THEMES,
|
|
2839
|
+
getTheme,
|
|
2840
|
+
TerminalRenderer,
|
|
2841
|
+
defaultRenderer,
|
|
2842
|
+
TerminalInputHandler,
|
|
2843
|
+
TerminullEngine,
|
|
2844
|
+
defaultEngine,
|
|
2845
|
+
checkTerminalDimensions,
|
|
2846
|
+
playTerminalBell,
|
|
2847
|
+
formatTime,
|
|
2848
|
+
clamp,
|
|
2849
|
+
padCenter,
|
|
2850
|
+
ArcadeMenu,
|
|
2851
|
+
DeterministicRNG,
|
|
2852
|
+
NeonCircuitGame,
|
|
2853
|
+
ByteRunnerGame,
|
|
2854
|
+
PacketManGame
|
|
2855
|
+
};
|
|
2856
|
+
//# sourceMappingURL=chunk-5CMAXV4B.js.map
|