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