-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
658 lines (555 loc) · 21.4 KB
/
Copy pathindex.html
File metadata and controls
658 lines (555 loc) · 21.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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>🔢 猜数字游戏</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 15px;
color: #333;
}
.game-container {
background-color: #ffffff;
padding: 30px 20px;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 100%;
max-width: 420px;
text-align: center;
}
.emoji-title {
font-size: 3em;
margin-bottom: 10px;
}
h1 {
color: #667eea;
margin: 0 0 15px 0;
font-size: 1.6em;
}
.subtitle {
color: #888;
font-size: 0.9em;
margin-bottom: 20px;
}
.game-info {
background: #f8f9fa;
border-radius: 12px;
padding: 12px;
margin-bottom: 15px;
}
.attempts {
font-size: 1em;
color: #555;
margin: 0;
}
.attempts span {
color: #667eea;
font-weight: bold;
font-size: 1.2em;
}
/* 角色选择 */
.character-select {
margin-bottom: 15px;
}
.character-select h3 {
font-size: 0.85em;
color: #666;
margin-bottom: 10px;
}
.character-list {
display: flex;
justify-content: center;
gap: 8px;
flex-wrap: wrap;
}
.character-btn {
padding: 8px 12px;
border: 2px solid #e0e0e0;
border-radius: 20px;
background: white;
cursor: pointer;
font-size: 0.85em;
transition: all 0.3s;
}
.character-btn:hover {
transform: scale(1.05);
}
.character-btn.active {
border-color: #667eea;
background: #667eea;
color: white;
}
/* 语音开关 */
.voice-toggle {
position: fixed;
top: 20px;
right: 20px;
background: white;
border: none;
border-radius: 50%;
width: 45px;
height: 45px;
font-size: 1.3em;
cursor: pointer;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
transition: all 0.3s;
z-index: 100;
}
.voice-toggle:hover {
transform: scale(1.1);
}
.voice-toggle.off {
opacity: 0.5;
}
/* 输入区域 */
.input-area {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 12px;
}
#guessInput {
width: 100%;
padding: 15px;
border: 3px solid #e0e0e0;
border-radius: 12px;
font-size: 1.3em;
text-align: center;
transition: all 0.3s;
outline: none;
}
#guessInput:focus {
border-color: #667eea;
box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}
.btn {
width: 100%;
padding: 14px;
border: none;
border-radius: 12px;
cursor: pointer;
font-size: 1em;
font-weight: 600;
transition: all 0.3s;
}
#submitGuess {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
#submitGuess:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}
#submitGuess:disabled {
background: #ccc;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
#resetButton {
background: #f8f9fa;
color: #666;
border: 2px solid #e0e0e0;
margin-top: 8px;
}
#resetButton:hover {
background: #e9ecef;
border-color: #ccc;
}
/* 状态消息 */
#message {
font-size: 1.1em;
margin: 15px 0;
min-height: 25px;
font-weight: 600;
}
.status {
font-weight: bold;
min-height: 20px;
margin-top: 12px;
padding: 10px;
border-radius: 8px;
font-size: 0.95em;
}
.status.hint-high {
background: #fff3cd;
color: #856404;
}
.status.hint-low {
background: #d1ecf1;
color: #0c5460;
}
.status.win {
background: #d4edda;
color: #155724;
}
.status.error {
background: #f8d7da;
color: #721c24;
}
/* 动画 */
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
.bounce {
animation: bounce 0.5s ease;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-10px); }
75% { transform: translateX(10px); }
}
.shake {
animation: shake 0.4s ease;
}
/* 历史记录 */
.history {
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid #eee;
}
.history h3 {
color: #666;
font-size: 0.85em;
margin-bottom: 8px;
}
.history-list {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 6px;
}
.history-item {
background: #f0f0f0;
padding: 5px 10px;
border-radius: 15px;
font-size: 0.8em;
color: #555;
}
.history-item.high {
background: #fff3cd;
color: #856404;
}
.history-item.low {
background: #d1ecf1;
color: #0c5460;
}
/* 角色特定样式 */
.game-container.robot {
font-family: 'Courier New', monospace;
}
.game-container.cat .emoji-title {
animation: bounce 0.3s infinite alternate;
}
.game-container.dongbei {
background: linear-gradient(135deg, #ff6b6b 0%, #ffa500 100%);
color: white;
}
.game-container.dongbei h1,
.game-container.dongbei .subtitle,
.game-container.dongbei .attempts,
.game-container.dongbei .history h3 {
color: white;
}
.game-container.dongbei .history-item {
background: rgba(255,255,255,0.3);
color: white;
}
.game-container.dongbei .character-btn.active {
background: white;
color: #ff6b6b;
}
.game-container.tv {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
color: white;
}
.game-container.tv h1,
.game-container.tv .subtitle,
.game-container.tv .attempts {
color: white;
}
.game-container.tv .character-btn.active {
background: #11998e;
color: white;
border-color: white;
}
</style>
</head>
<body>
<!-- 语音开关按钮 -->
<button id="voiceToggle" class="voice-toggle" title="点击开启/关闭语音">🔊</button>
<div class="game-container" id="gameContainer">
<div class="emoji-title" id="emojiTitle">🎮</div>
<h1 id="gameTitle">猜数字游戏</h1>
<p class="subtitle" id="gameSubtitle">我想了一个 1-100 的数字,你能猜出来吗?</p>
<!-- 角色选择 -->
<div class="character-select">
<h3>👇 选择你的对手 👇</h3>
<div class="character-list">
<button class="character-btn active" data-char="default">🎮 普通</button>
<button class="character-btn" data-char="robot">🤖 机器人</button>
<button class="character-btn" data-char="cat">🐱 傲娇猫</button>
<button class="character-btn" data-char="dongbei">🔥 东北老铁</button>
<button class="character-btn" data-char="tv">📺 电视购物</button>
</div>
</div>
<div class="game-info">
<p class="attempts">已尝试次数:<span id="attemptCount">0</span></p>
</div>
<p id="message">输入数字开始游戏!</p>
<div class="input-area">
<input type="number" id="guessInput" placeholder="输入 1-100" min="1" max="100">
<button id="submitGuess" class="btn">提交猜测</button>
</div>
<button id="resetButton" class="btn">🔄 重新开始</button>
<p id="statusMessage" class="status"></p>
<div class="history" id="historySection" style="display: none;">
<h3>📋 猜测记录</h3>
<div class="history-list" id="historyList"></div>
</div>
</div>
<script>
// --- 角色配置 ---
const characters = {
default: {
name: "普通",
emoji: "🎮",
title: "猜数字游戏",
subtitle: "我想了一个 1-100 的数字,你能猜出来吗?",
startMsg: "游戏开始!我想了一个一,到一百之间的数字,请你猜一猜。",
tooHigh: "太大了,请猜一个更小的数字",
tooLow: "太小了,请猜一个更大的数字",
win3: "太厉害了!你就是数字大师!",
win6: "恭喜你猜对了!非常棒!",
winMore: "恭喜你猜对了!继续加油!",
reset: "好的,重新开始!",
error: "请输入一 到一百之间的有效数字"
},
robot: {
name: "机器人",
emoji: "🤖",
title: "SYSTEM",
subtitle: "【系统】请输入 1-100 之间的数字",
startMsg: "系统初始化完成,请进行第一次猜测操作",
tooHigh: "错误!当前数值超过目标值,请降低输入",
tooLow: "错误!当前数值低于目标值,请提高输入",
win3: "警告!人类表现优异,怀疑存在作弊行为",
win6: "运算结束,目标数值已确定",
winMore: "任务完成,恭喜玩家",
reset: "系统重置中,请稍候",
error: "警告!检测到非法输入,请重新输入"
},
cat: {
name: "傲娇猫",
emoji: "🐱",
title: "哼~本喵的游戏",
subtitle: "喵~猜对本喵的数字就赏你小鱼干~",
startMsg: "哼~游戏开始啦!本喵想了一个数字,限你十次之内猜到!喵~",
tooHigh: "太大了啦!笨人类!再猜!",
tooLow: "太小了啦!是不是傻?再试试!",
win3: "哇!你、你这么聪明的吗!本喵服了!",
win6: "嗯...勉强及格吧,再接再厉哦~",
winMore: "好吧,你赢了...给本喵撸一下就原谅你~",
reset: "喵~再来一局,这次可不许让着我!",
error: "笨死了!不是说了1到100吗!"
},
dongbei: {
name: "东北老铁",
emoji: "🔥",
title: "整活猜数",
subtitle: "老铁,整一个?猜对请你喝酒!",
startMsg: "哎呀妈呀来啦!老铁整活开始!整一个1到100的数儿,整呗~",
tooHigh: "哎呀妈呀整大了!使点劲儿,整小滴!",
tooLow: "艾玛整小了!使把劲儿,往大了整!",
win3: "哎呀我擦!老铁666啊!3次就整明白了!",
win6: "中!老铁挺给力啊!6次整明白了!",
winMore: "来了老弟!恭喜恭喜,整明白了!必须整一杯!",
reset: "来来来!继续整!这次我整个更刺激的!",
error: "哎呀妈呀!你整啥玩意儿呢?1到100会不会?"
},
tv: {
name: "电视购物",
emoji: "📺",
title: "★限时猜数★",
subtitle: "只要99次!猜对数字就是你的!",
startMsg: "观众朋友们!今天我们带来的是——猜数字!只要在100次之内猜对,数字就是你的!机不可失!开始!",
tooHigh: "高了高了!不要9998,不要998,只要继续猜!",
tooLow: "低了低了!朋友们,最新报价,只要继续猜!",
win3: "3次!只要3次!这是什么?这是奇迹!这是神迹!",
win6: "6次!太棒了!数量有限!先到先得!",
winMore: "恭喜恭喜!猜对了!数量有限!预购从速!",
reset: "不要走开!精彩继续!新一轮猜数即将开始!",
error: "哎呀!参数错误!请重新输入!99,98,97...不是这个!"
}
};
// --- 游戏变量 ---
let secretNumber;
let attempts = 0;
let guessHistory = [];
let voiceEnabled = true;
let speechSynth = window.speechSynthesis;
let currentChar = "default";
// --- DOM 元素获取 ---
const guessInput = document.getElementById('guessInput');
const submitButton = document.getElementById('submitGuess');
const resetButton = document.getElementById('resetButton');
const messageDisplay = document.getElementById('message');
const statusMessage = document.getElementById('statusMessage');
const attemptCount = document.getElementById('attemptCount');
const historySection = document.getElementById('historySection');
const historyList = document.getElementById('historyList');
const voiceToggle = document.getElementById('voiceToggle');
const gameContainer = document.getElementById('gameContainer');
const emojiTitle = document.getElementById('emojiTitle');
const gameTitle = document.getElementById('gameTitle');
const gameSubtitle = document.getElementById('gameSubtitle');
const characterBtns = document.querySelectorAll('.character-btn');
// --- 语音功能 ---
function speak(text, lang = 'zh-CN') {
if (!voiceEnabled) return;
speechSynth.cancel();
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = lang;
utterance.rate = currentChar === 'dongbei' ? 1.1 : (currentChar === 'robot' ? 0.8 : 0.9);
utterance.pitch = currentChar === 'cat' ? 1.2 : (currentChar === 'robot' ? 0.5 : 1);
const voices = speechSynth.getVoices();
const chineseVoice = voices.find(v => v.lang.includes('zh'));
if (chineseVoice) {
utterance.voice = chineseVoice;
}
speechSynth.speak(utterance);
}
// 语音开关
voiceToggle.addEventListener('click', () => {
voiceEnabled = !voiceEnabled;
voiceToggle.textContent = voiceEnabled ? '🔊' : '🔇';
voiceToggle.classList.toggle('off', !voiceEnabled);
if (voiceEnabled) {
speak('语音已开启');
}
});
// 角色选择
characterBtns.forEach(btn => {
btn.addEventListener('click', () => {
characterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
currentChar = btn.dataset.char;
const char = characters[currentChar];
// 更新界面
emojiTitle.textContent = char.emoji;
gameTitle.textContent = char.title;
gameSubtitle.textContent = char.subtitle;
// 更新容器样式
gameContainer.className = 'game-container ' + currentChar;
speak('你好!我是' + char.name + '!' + char.startMsg);
});
});
// --- 核心函数 ---
function initializeGame() {
secretNumber = Math.floor(Math.random() * 100) + 1;
attempts = 0;
guessHistory = [];
const char = characters[currentChar];
messageDisplay.textContent = char.subtitle;
messageDisplay.className = "";
statusMessage.textContent = "";
statusMessage.className = "status";
guessInput.value = '';
guessInput.disabled = false;
submitButton.disabled = false;
attemptCount.textContent = "0";
historySection.style.display = "none";
historyList.innerHTML = "";
guessInput.focus();
speak(char.startMsg);
console.log("🎮 新游戏开始!答案:" + secretNumber);
}
function updateHistory() {
historySection.style.display = "block";
const char = characters[currentChar];
historyList.innerHTML = guessHistory.map(item => {
const className = item.result === char.tooHigh ? "high" : (item.result === char.tooLow ? "low" : "");
return `<span class="history-item ${className}">${item.number}</span>`;
}).join('');
}
function checkGuess() {
const userGuess = parseInt(guessInput.value);
const char = characters[currentChar];
if (isNaN(userGuess) || userGuess < 1 || userGuess > 100) {
statusMessage.textContent = "⚠️ 请输入 1-100 之间的有效数字";
statusMessage.className = "status error shake";
setTimeout(() => statusMessage.classList.remove("shake"), 400);
speak(char.error);
guessInput.value = '';
guessInput.focus();
return;
}
attempts++;
attemptCount.textContent = attempts;
if (userGuess === secretNumber) {
messageDisplay.innerHTML = `🎉 ${char.name}说:答案就是 <strong>${secretNumber}</strong>!`;
messageDisplay.className = "bounce";
let winMsg;
if (attempts <= 3) winMsg = char.win3;
else if (attempts <= 6) winMsg = char.win6;
else winMsg = char.winMore;
statusMessage.textContent = "✨ " + winMsg;
statusMessage.className = "status win";
guessHistory.push({ number: userGuess, result: "✓" });
updateHistory();
speak(winMsg);
endGame(true);
} else if (userGuess < secretNumber) {
messageDisplay.textContent = char.tooLow;
messageDisplay.className = "";
statusMessage.textContent = `提示:${userGuess} 小了`;
statusMessage.className = "status hint-low";
guessHistory.push({ number: userGuess, result: char.tooLow });
updateHistory();
speak(char.tooLow);
} else {
messageDisplay.textContent = char.tooHigh;
messageDisplay.className = "";
statusMessage.textContent = `提示:${userGuess} 大了`;
statusMessage.className = "status hint-high";
guessHistory.push({ number: userGuess, result: char.tooHigh });
updateHistory();
speak(char.tooHigh);
}
guessInput.value = '';
guessInput.focus();
}
function endGame(isWin) {
guessInput.disabled = true;
submitButton.disabled = true;
}
// --- 事件监听器 ---
submitButton.addEventListener('click', checkGuess);
guessInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
checkGuess();
}
});
resetButton.addEventListener('click', () => {
const char = characters[currentChar];
speak(char.reset);
setTimeout(initializeGame, 500);
});
window.speechSynthesis.getVoices();
// --- 启动游戏 ---
initializeGame();
</script>
</body>
</html>