-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
463 lines (401 loc) · 16.4 KB
/
Copy pathscript.js
File metadata and controls
463 lines (401 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
class HackerSimulator {
constructor() {
this.output = document.querySelector('.output');
this.input = document.querySelector('.command-input');
this.game = new HackerGame();
this.currentMission = null;
this.commands = {
'help': '可用命令:\nhelp - 显示帮助\nclear - 清屏\nstatus - 显示角色状态\nmissions - 显示可用任务\nstart <任务ID> - 开始任务\ntools - 显示可用工具\nupgrade <技能名> - 升级技能\nunlock <工具名> - 解锁工具\nexit - 退出当前任务',
'clear': () => this.clearScreen(),
'status': () => this.showStatus(),
'missions': () => this.showMissions(),
'start': (id) => this.startMission(parseInt(id)),
'tools': () => this.showTools(),
'upgrade': (skill) => this.upgradeSkill(skill),
'unlock': (tool) => this.unlockTool(tool),
'exit': () => this.exitMission()
};
this.setupEventListeners();
this.welcomeMessage();
}
setupEventListeners() {
this.input.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
const input = this.input.value.trim().toLowerCase();
if (this.currentMission) {
this.handleMissionCommand(input);
} else {
const [command, ...args] = input.split(' ');
this.executeCommand(command, args);
}
this.input.value = '';
}
});
}
async handleMissionCommand(command) {
this.printCommand(command);
const result = await this.game.executeMissionCommand(command);
await this.typeText(result.message);
if (result.success && result.completed) {
await this.typeText('恭喜!任务完成!');
if (this.game.checkLevelUp()) {
await this.typeText('等级提升!');
}
this.currentMission = null;
this.updatePrompt();
}
}
updatePrompt() {
const promptElement = document.querySelector('.prompt');
if (this.currentMission) {
promptElement.textContent = `mission${this.currentMission.id}@hack:~$`;
} else {
promptElement.textContent = 'root@system:~$';
}
}
async exitMission() {
if (this.currentMission) {
this.currentMission = null;
this.updatePrompt();
await this.typeText('已退出任务模式');
} else {
await this.typeText('当前不在任务中');
}
}
async startMission(missionId) {
if (isNaN(missionId)) {
await this.typeText('请输入有效的任务ID');
return;
}
const result = await this.game.initializeMission(missionId);
if (result.success) {
this.currentMission = result.mission;
this.updatePrompt();
await this.typeText(result.message);
await this.typeText('\n任务模式已开启,请输入相应的命令来完成任务。\n输入 "exit" 可以退出任务。');
} else {
await this.typeText(result.message);
}
}
async typeText(text, speed = 50) {
const lines = text.split('\n');
for (const line of lines) {
const element = document.createElement('div');
element.classList.add('typing');
this.output.appendChild(element);
for (const char of line) {
element.textContent += char;
await new Promise(resolve => setTimeout(resolve, speed));
}
element.classList.remove('typing');
this.output.appendChild(document.createElement('br'));
}
this.scrollToBottom();
}
executeCommand(command, args = []) {
this.printCommand(command + (args.length ? ' ' + args.join(' ') : ''));
if (command === '') return;
if (this.commands[command]) {
if (typeof this.commands[command] === 'function') {
this.commands[command](...args);
} else {
this.typeText(this.commands[command]);
}
} else {
this.typeText('命令未找到。输入 "help" 获取可用命令列表。');
}
}
printCommand(command) {
const cmdLine = document.createElement('div');
cmdLine.innerHTML = `<span class="prompt">root@system:~$</span> ${command}`;
this.output.appendChild(cmdLine);
this.scrollToBottom();
}
clearScreen() {
this.output.innerHTML = '';
}
async showStatus() {
const status = this.game.getStatus();
const statusText = [
'===== 角色状态 =====',
`等级: ${status.level}`,
`经验值: ${status.exp}/${status.nextLevelExp}`,
'',
'技能等级:',
`暴力破解: ${status.skills.bruteforce}`,
`网络技术: ${status.skills.network}`,
`密码学: ${status.skills.crypto}`,
`隐身技术: ${status.skills.stealth}`,
'===================='
].join('\n');
await this.typeText(statusText);
}
async showMissions() {
const missions = this.game.getMissionStatus();
const missionText = ['===== 可用任务 ====='];
missions.forEach(mission => {
missionText.push(
`[任务 ${mission.id}] ${mission.name}`,
`描述: ${mission.description}`,
`详情: ${mission.details}`,
`难度: ${mission.difficulty}`,
`需求等级: ${mission.requiredLevel}`,
`需求技能: ${mission.requiredSkill} (当前等级: ${mission.skillLevel})`,
`需求工具: ${mission.requiredTools ? mission.requiredTools.join(', ') : mission.requiredTool}`,
`奖励: ${mission.reward} exp`,
`状态: ${mission.completed ? '已完成' : mission.available ? '可接取' : '需要解锁工具'}`,
''
);
});
missionText.push('====================');
await this.typeText(missionText.join('\n'));
}
async showTools() {
const tools = this.game.getAvailableTools();
const toolsText = ['===== 已解锁工具 ====='];
tools.forEach(tool => {
toolsText.push(
`\n${tool.name}: ${tool.description}`,
`技能加成: ${tool.skillBonus}`,
`${tool.tutorial}`,
''
);
});
toolsText.push('解锁新工具需要 500 经验值');
toolsText.push('====================');
await this.typeText(toolsText.join('\n'));
}
async upgradeSkill(skillName) {
if (!skillName) {
await this.typeText('请指定要升级的技能名称');
return;
}
const success = this.game.upgradeSkill(skillName);
if (success) {
await this.typeText(`${skillName} 技能升级成功!`);
} else {
await this.typeText('升级失败:经验值不足或技能名称无效');
}
}
async unlockTool(toolName) {
if (!toolName) {
await this.typeText('请指定要解锁的工具名称');
return;
}
const success = this.game.unlockTool(toolName);
if (success) {
await this.typeText(`${toolName} 工具解锁成功!`);
} else {
await this.typeText('解锁失败:经验值不足或工具名称无效');
}
}
async welcomeMessage() {
const welcome = [
'欢迎使用黑客模拟器 v2.0',
'你现在是一名初级黑客,完成任务获得经验值来提升等级和技能',
'输入 "help" 获取可用命令列表',
'----------------'
];
for (const line of welcome) {
await this.typeText(line);
}
}
scrollToBottom() {
this.output.scrollTop = this.output.scrollHeight;
}
}
// 黑客帝国动画类
class MatrixAnimation {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
this.resizeCanvas();
this.characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()';
this.fontSize = 14;
this.columns = 0;
this.drops = [];
this.initialize();
window.addEventListener('resize', () => {
this.resizeCanvas();
this.initialize();
});
}
resizeCanvas() {
this.canvas.width = window.innerWidth;
this.canvas.height = window.innerHeight;
}
initialize() {
this.columns = Math.floor(this.canvas.width / this.fontSize);
this.drops = Array(this.columns).fill(1);
}
draw() {
this.ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.ctx.fillStyle = '#0F0';
this.ctx.font = `${this.fontSize}px monospace`;
for (let i = 0; i < this.drops.length; i++) {
const text = this.characters[Math.floor(Math.random() * this.characters.length)];
this.ctx.fillText(text, i * this.fontSize, this.drops[i] * this.fontSize);
if (this.drops[i] * this.fontSize > this.canvas.height && Math.random() > 0.975) {
this.drops[i] = 0;
}
this.drops[i]++;
}
}
}
// 加载动画类
class LoadingAnimation {
constructor() {
this.matrixLoading = document.getElementById('matrixLoading');
this.canvas = document.getElementById('matrixCanvas');
this.progressBar = this.matrixLoading.querySelector('.progress-bar');
this.progressText = this.matrixLoading.querySelector('.progress-text');
this.statusText = this.matrixLoading.querySelector('.status-text');
this.matrixAnimation = new MatrixAnimation(this.canvas);
this.loadingMessages = [
'正在连接目标系统...',
'正在扫描系统漏洞...',
'正在破解防火墙...',
'正在绕过安全系统...',
'正在注入恶意代码...',
'正在获取系统权限...',
'正在植入后门程序...',
'正在清除入侵痕迹...',
'正在建立安全连接...',
'正在完成最终配置...'
];
}
start() {
this.matrixLoading.style.display = 'flex';
this.matrixLoading.style.opacity = '0';
// 淡入效果
setTimeout(() => {
this.matrixLoading.style.transition = 'opacity 1s ease-in';
this.matrixLoading.style.opacity = '1';
}, 100);
this.currentProgress = 0;
this.animationFrame = null;
this.startMatrixAnimation();
this.updateProgress();
}
startMatrixAnimation() {
const animate = () => {
this.matrixAnimation.draw();
this.animationFrame = requestAnimationFrame(animate);
};
animate();
}
updateProgress() {
const duration = 8000; // 总持续时间(毫秒)
const interval = 80; // 更新间隔(毫秒)
const steps = duration / interval;
const increment = 100 / steps;
let currentStep = 0;
const update = () => {
currentStep++;
const progress = Math.min(Math.floor((currentStep * increment)), 100);
// 使用缓动函数使进度更自然
const easedProgress = this.easeInOutQuad(progress / 100) * 100;
this.progressBar.style.width = `${easedProgress}%`;
this.progressText.textContent = `${progress}%`;
// 更新状态消息
if (progress % 10 === 0) {
const messageIndex = Math.floor(progress / 10);
if (this.loadingMessages[messageIndex]) {
this.fadeText(this.statusText, this.loadingMessages[messageIndex]);
}
}
if (progress < 100) {
setTimeout(update, interval);
} else {
setTimeout(() => {
this.complete();
}, 1000); // 完成后等待一秒再消失
}
};
update();
}
// 缓动函数
easeInOutQuad(t) {
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
// 文字淡入淡出效果
fadeText(element, newText) {
element.style.transition = 'opacity 0.5s ease';
element.style.opacity = '0';
setTimeout(() => {
element.textContent = newText;
element.style.opacity = '1';
}, 500);
}
complete() {
// 淡出效果
this.matrixLoading.style.transition = 'opacity 1.5s ease-out';
this.matrixLoading.style.opacity = '0';
setTimeout(() => {
cancelAnimationFrame(this.animationFrame);
this.matrixLoading.style.display = 'none';
// 聚焦到命令输入框
const commandInput = document.querySelector('.command-input');
commandInput.focus();
// 显示欢迎信息(带淡入效果)
const output = document.querySelector('.output');
output.style.opacity = '0';
output.innerHTML = `
<pre style="color: #00ff00; margin-bottom: 15px; line-height: 1.2;">
██╗ ██╗ █████╗ ██████╗██╗ ██╗███████╗██████╗
██║ ██║██╔══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗
███████║███████║██║ █████╔╝ █████╗ ██████╔╝
██╔══██║██╔══██║██║ ██╔═██╗ ██╔══╝ ██╔══██╗
██║ ██║██║ ██║╚██████╗██║ ██╗███████╗██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
SIMULATOR v2.0</pre>
<div class="welcome-text" style="opacity: 0; transform: translateY(20px); transition: all 1s ease-out;">欢迎来到黑客模拟器!输入 <span style="color: #00ff00">help</span> 查看可用命令。</div>
`;
// 欢迎信息淡入
setTimeout(() => {
output.style.transition = 'opacity 1s ease-in';
output.style.opacity = '1';
// 添加延迟显示欢迎文本的动画效果
setTimeout(() => {
const welcomeText = output.querySelector('.welcome-text');
welcomeText.style.opacity = '1';
welcomeText.style.transform = 'translateY(0)';
}, 500);
}, 100);
}, 1500);
}
}
// 游戏介绍弹窗逻辑
document.addEventListener('DOMContentLoaded', () => {
const introModal = document.getElementById('introModal');
const startGameBtn = document.getElementById('startGame');
const langBtns = document.querySelectorAll('.lang-btn');
const zhSection = document.querySelector('.intro-section.zh');
const enSection = document.querySelector('.intro-section.en');
const loadingAnimation = new LoadingAnimation();
// 语言切换
langBtns.forEach(btn => {
btn.addEventListener('click', () => {
const lang = btn.dataset.lang;
langBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
if (lang === 'zh') {
zhSection.style.display = 'block';
enSection.style.display = 'none';
startGameBtn.textContent = '开始游戏';
} else {
zhSection.style.display = 'none';
enSection.style.display = 'block';
startGameBtn.textContent = 'Start Game';
}
});
});
// 开始游戏按钮点击事件
startGameBtn.addEventListener('click', () => {
introModal.style.display = 'none';
loadingAnimation.start();
});
// 初始化模拟器
new HackerSimulator();
});