-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame-interface.html
More file actions
1660 lines (1418 loc) · 60.9 KB
/
Copy pathGame-interface.html
File metadata and controls
1660 lines (1418 loc) · 60.9 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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>终端风格吃药游戏 - AI对战+道具商店版</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Courier New', monospace;
}
body {
background-color: #000;
color: #0f0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
overflow: auto;
touch-action: manipulation;
}
.terminal-container {
width: 100%;
max-width: 800px;
background-color: #000;
border: 2px solid #0f0;
box-shadow: 0 0 20px rgba(0, 255, 0, 0.3);
position: relative;
padding: 20px;
overflow: hidden;
}
.terminal-header {
border-bottom: 2px solid #0f0;
padding: 10px 0;
margin-bottom: 20px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
}
.terminal-title {
font-size: 1.5rem;
letter-spacing: 2px;
color: #0f0;
text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}
.screen {
display: none;
}
.active {
display: block;
}
.menu-options {
margin: 30px 0;
}
.menu-option {
font-size: 1.2rem;
margin: 15px 0;
padding: 10px;
cursor: pointer;
position: relative;
transition: all 0.3s;
}
.menu-option:hover {
background: rgba(0, 255, 0, 0.1);
}
.menu-option::before {
content: "> ";
color: #0f0;
}
.input-container {
margin: 20px 0;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
.input-prompt {
margin-right: 10px;
}
input {
background: transparent;
border: 1px solid #0f0;
padding: 8px;
color: #0f0;
font-size: 1rem;
outline: none;
width: 200px;
font-family: 'Courier New', monospace;
}
.pills-container {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin: 20px 0;
justify-content: center;
}
.pill {
font-size: 1.2rem;
padding: 12px 15px;
border: 1px solid #0f0;
min-width: 70px;
text-align: center;
position: relative;
background: rgba(0, 30, 0, 0.2);
}
.pill-number {
position: absolute;
top: -10px;
left: 5px;
font-size: 0.8rem;
background: #000;
padding: 0 5px;
}
.stats-container {
display: flex;
justify-content: space-between;
margin: 30px 0;
flex-wrap: wrap;
gap: 20px;
}
.player-stats {
width: 45%;
min-width: 250px;
}
.stat {
margin: 10px 0;
display: flex;
align-items: center;
}
.stat-title {
min-width: 80px;
}
.stat-value {
display: flex;
gap: 5px;
flex-wrap: wrap;
}
.life-icon {
color: #f00;
}
.health-icon {
color: #00f;
}
.message {
margin: 20px 0;
padding: 10px;
border: 1px solid #0f0;
min-height: 40px;
background: rgba(0, 30, 0, 0.2);
}
.privacy-content {
margin: 20px 0;
padding: 15px;
border: 1px solid #0f0;
line-height: 1.6;
background: rgba(0, 30, 0, 0.2);
}
.game-over {
color: #f00;
font-size: 1.5rem;
margin: 20px 0;
text-align: center;
}
.level-indicator {
font-size: 1.2rem;
color: #ff0;
margin-bottom: 10px;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.pill.red { color: #f00; }
.pill.blue { color: #00f; }
.pill.green { color: #0f0; }
.pill.yellow { color: #ff0; }
.pill.purple { color: #f0f; }
.eaten {
opacity: 0.3;
border-color: #555;
color: #555;
}
.ai-thinking {
animation: blink 1s infinite;
}
@keyframes blink {
0% { opacity: 0.3; }
50% { opacity: 1; }
100% { opacity: 0.3; }
}
.cursor {
position: relative;
display: inline-block;
}
.cursor::after {
content: "";
position: absolute;
top: 0;
right: -10px;
width: 8px;
height: 100%;
background: #0f0;
animation: blink 1s infinite;
}
.terminal-line {
margin: 5px 0;
}
.terminal-divider {
height: 1px;
background: #0f0;
margin: 15px 0;
opacity: 0.3;
}
.ai-section {
background: rgba(0, 100, 0, 0.1);
padding: 10px;
border: 1px solid #0a0;
margin: 10px 0;
}
.black-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
color: #f00;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
z-index: 1000;
font-size: 3rem;
text-align: center;
opacity: 0;
pointer-events: none;
transition: opacity 0.5s;
}
.black-screen.active {
opacity: 1;
pointer-events: auto;
}
.black-screen-message {
margin: 20px;
font-size: 2rem;
color: #f00;
text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 20px;
}
.btn {
background: #000;
color: #0f0;
border: 1px solid #0f0;
padding: 10px 15px;
cursor: pointer;
font-size: 1rem;
transition: all 0.3s;
}
.btn:hover {
background: rgba(0, 255, 0, 0.1);
}
.game-info {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin: 15px 0;
justify-content: space-between;
}
.info-box {
border: 1px solid #0f0;
padding: 10px;
flex: 1;
min-width: 200px;
background: rgba(0, 30, 0, 0.1);
}
.shop-container {
margin: 20px 0;
border: 1px solid #0f0;
padding: 15px;
background: rgba(0, 30, 0, 0.1);
}
.shop-title {
font-size: 1.3rem;
color: #ff0;
margin-bottom: 15px;
border-bottom: 1px solid #0f0;
padding-bottom: 5px;
}
.shop-items {
display: flex;
flex-wrap: wrap;
gap: 15px;
justify-content: space-between;
}
.shop-item {
border: 1px solid #0f0;
padding: 10px;
width: calc(50% - 10px);
min-width: 200px;
cursor: pointer;
transition: all 0.3s;
}
.shop-item:hover {
background: rgba(0, 255, 0, 0.1);
}
.item-name {
font-size: 1.1rem;
color: #0f0;
margin-bottom: 5px;
}
.item-price {
color: #ff0;
font-size: 0.9rem;
}
.item-desc {
font-size: 0.9rem;
color: #aaa;
margin-top: 5px;
}
.inventory-container {
margin: 15px 0;
border: 1px solid #0f0;
padding: 10px;
background: rgba(0, 30, 0, 0.1);
}
.inventory-title {
font-size: 1.1rem;
color: #0f0;
margin-bottom: 10px;
}
.inventory-items {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.inventory-item {
border: 1px solid #0f0;
padding: 5px 10px;
font-size: 0.9rem;
cursor: pointer;
}
.inventory-item:hover {
background: rgba(0, 255, 0, 0.1);
}
.tooltip {
position: absolute;
background: rgba(0, 0, 0, 0.8);
border: 1px solid #0f0;
padding: 5px 10px;
z-index: 100;
font-size: 0.9rem;
max-width: 300px;
pointer-events: none;
opacity: 0;
transition: opacity 0.3s;
}
.inventory-item:hover .tooltip {
opacity: 1;
}
.action-buttons {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin: 15px 0;
}
.action-btn {
background: rgba(0, 30, 0, 0.3);
border: 1px solid #0f0;
padding: 5px 10px;
cursor: pointer;
font-size: 0.9rem;
}
.action-btn:hover {
background: rgba(0, 255, 0, 0.2);
}
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
}
.modal.active {
opacity: 1;
pointer-events: auto;
}
.modal-content {
background: #000;
border: 2px solid #0f0;
padding: 20px;
max-width: 500px;
width: 90%;
}
.modal-title {
font-size: 1.3rem;
color: #0f0;
margin-bottom: 15px;
}
.modal-message {
margin-bottom: 20px;
}
.modal-close {
background: #000;
color: #0f0;
border: 1px solid #0f0;
padding: 8px 15px;
cursor: pointer;
}
</style>
</head>
<body>
<!-- 黑屏效果 -->
<div class="black-screen" id="black-screen">
<div class="black-screen-message">⚠️ 警告! ⚠️</div>
<div class="black-screen-message" id="black-screen-message">你吃下了有毒的药丸!</div>
</div>
<!-- 道具使用模态框 -->
<div class="modal" id="item-modal">
<div class="modal-content">
<div class="modal-title" id="modal-title">道具信息</div>
<div class="modal-message" id="modal-message"></div>
<button class="modal-close" onclick="closeModal()">关闭</button>
</div>
</div>
<div class="terminal-container">
<!-- 开始菜单 -->
<div id="menu-screen" class="screen active">
<div class="terminal-header">
<div class="terminal-title">吃药游戏终端 v3.0</div>
<div>状态: <span class="cursor">就绪</span></div>
</div>
<div class="terminal-line">> 欢迎来到吃药游戏终端</div>
<div class="terminal-line">> 请选择操作:</div>
<div class="menu-options">
<div class="menu-option" onclick="startGame(false)">开始游戏 (单人模式)</div>
<div class="menu-option" onclick="startGame(true)">AI作战 (双人对战)</div>
<div class="menu-option" onclick="showShop()">道具商店</div>
<div class="menu-option" onclick="showPrivacy()">隐私策略</div>
<div class="menu-option" onclick="exitGame()">退出游戏</div>
</div>
<div class="terminal-divider"></div>
<div class="terminal-line">> 游戏说明:</div>
<div class="terminal-line">- 选择药丸并承担中毒风险</div>
<div class="terminal-line">- 管理生命值(♥)和健康值(⬢)</div>
<div class="terminal-line">- 每关通过获得20分</div>
<div class="terminal-line">- 使用道具增加优势</div>
<div class="terminal-line">- AI模式中与AI对战</div>
<div class="terminal-divider"></div>
<div class="game-info">
<div class="info-box">
<div class="terminal-line">> 操作指南:</div>
<div class="terminal-line">- 输入药丸编号</div>
<div class="terminal-line">- 按确定或回车</div>
<div class="terminal-line">- 双指缩放页面</div>
</div>
<div class="info-box">
<div class="terminal-line">> 游戏提示:</div>
<div class="terminal-line">- 红色药丸: 1/5有毒</div>
<div class="terminal-line">- 蓝色药丸: 2/4有毒</div>
<div class="terminal-line">- 绿色药丸: 3/6有毒</div>
</div>
</div>
</div>
<!-- 道具商店 -->
<div id="shop-screen" class="screen">
<div class="terminal-header">
<div class="terminal-title">道具商店</div>
<div>当前积分: <span id="shop-score">0</span></div>
</div>
<div class="shop-container">
<div class="shop-title">> 可购买道具</div>
<div class="shop-items" id="shop-items">
<!-- 道具将通过JS动态生成 -->
</div>
</div>
<div class="terminal-divider"></div>
<div class="inventory-container">
<div class="inventory-title">> 我的道具</div>
<div class="inventory-items" id="player-inventory">
<!-- 玩家道具将通过JS动态生成 -->
</div>
</div>
<div class="terminal-divider"></div>
<button class="btn" style="width: 100%;" onclick="backToMenu()">返回菜单</button>
</div>
<!-- 游戏界面 -->
<div id="game-screen" class="screen">
<div class="terminal-header">
<div class="terminal-title">吃药游戏终端 - 游戏进行中</div>
<div class="level-indicator">
<span>关卡: <span id="level">1</span></span>
<span>得分: <span id="score">0</span></span>
</div>
</div>
<div class="level-indicator">
<span>第 <span id="level-display">1</span> 关:</span>
<span id="level-desc">5颗红色药丸 (1颗有毒)</span>
</div>
<!-- AI区域 -->
<div id="ai-section" class="ai-section">
<div class="terminal-line">> 对方 (AI):</div>
<div class="stats-container">
<div class="player-stats">
<div class="stat">
<div class="stat-title">血量:</div>
<div class="stat-value" id="ai-lives">
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
</div>
</div>
<div class="stat">
<div class="stat-title">健康值:</div>
<div class="stat-value" id="ai-health">
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
</div>
</div>
</div>
<div class="player-stats">
<div class="stat">
<div class="stat-title">得分:</div>
<div id="ai-score">0</div>
</div>
<div class="stat">
<div class="stat-title">道具:</div>
<div id="ai-items">无</div>
</div>
</div>
</div>
</div>
<div class="terminal-divider"></div>
<!-- 药丸区域 -->
<div class="pills-container" id="pills-container">
<!-- 药丸将通过JS动态生成 -->
</div>
<div class="terminal-divider"></div>
<!-- 玩家区域 -->
<div class="terminal-line">> 玩家:</div>
<div class="stats-container">
<div class="player-stats">
<div class="stat">
<div class="stat-title">血量:</div>
<div class="stat-value" id="player-lives">
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
<span class="life-icon">♥</span>
</div>
</div>
<div class="stat">
<div class="stat-title">健康值:</div>
<div class="stat-value" id="player-health">
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
<span class="health-icon">⬢</span>
</div>
</div>
</div>
<div class="player-stats">
<div class="stat">
<div class="stat-title">道具:</div>
<div id="player-items">无</div>
</div>
<div class="stat">
<div class="stat-title">剩余药丸:</div>
<div id="remaining-pills">5</div>
</div>
</div>
</div>
<div class="terminal-divider"></div>
<!-- 道具使用区域 -->
<div class="inventory-container">
<div class="inventory-title">> 我的道具 (点击使用)</div>
<div class="inventory-items" id="game-inventory">
<!-- 游戏中的道具将通过JS动态生成 -->
</div>
</div>
<div class="terminal-divider"></div>
<div class="input-container">
<div class="input-prompt">> 选择药丸编号:</div>
<input type="text" id="pill-input" autofocus>
<button class="btn" onclick="takePill()">确定</button>
</div>
<div class="message" id="message">> 游戏开始! 输入药丸编号并按确定...</div>
<div class="terminal-divider"></div>
<div class="controls">
<button class="btn" onclick="backToMenu()">返回菜单</button>
<button class="btn" onclick="resetGame()">重新开始</button>
<button class="btn" onclick="showShop()">道具商店</button>
</div>
</div>
<!-- 隐私策略界面 -->
<div id="privacy-screen" class="screen">
<div class="terminal-header">
<div class="terminal-title">隐私策略</div>
</div>
<div class="privacy-content">
> 请合理安排游戏时间,不要成为游戏的奴隶。
>
> 本终端游戏不收集任何用户数据,所有操作均在本地进行。
>
> 健康游戏忠告:
> 抵制不良游戏,拒绝盗版游戏;
> 注意自我保护,谨防受骗上当;
> 适度游戏益脑,沉迷游戏伤身;
> 合理安排时间,享受健康生活。
</div>
<div class="terminal-divider"></div>
<button class="btn" style="width: 100%; margin-top: 15px;" onclick="backToMenu()">返回菜单</button>
</div>
<!-- 游戏结束界面 -->
<div id="game-over-screen" class="screen">
<div class="terminal-header">
<div class="terminal-title">游戏结束</div>
</div>
<div class="game-over" id="game-over-message">游戏结束!</div>
<div class="terminal-line">> 最终得分: <span id="final-score">0</span></div>
<div class="terminal-line">> 通过关卡: <span id="levels-completed">0</span></div>
<div class="terminal-divider"></div>
<div class="terminal-line" id="ai-result"></div>
<div class="terminal-divider"></div>
<div class="menu-options">
<div class="menu-option" onclick="startGame(gameState.aiMode)">再玩一次</div>
<div class="menu-option" onclick="backToMenu()">返回菜单</div>
</div>
</div>
</div>
<script>
// 游戏状态
const gameState = {
level: 1,
playerScore: 0,
aiScore: 0,
playerLives: 5,
playerHealth: 5,
aiLives: 5,
aiHealth: 5,
pills: [],
currentPills: [],
gameOver: false,
playerTurn: true,
aiMode: false,
aiThinking: false,
playerInventory: [],
aiInventory: [],
usingItem: null
};
// 道具配置
const itemsConfig = [
{
id: 'candy',
name: '糖果',
price: 30,
description: '代替吃药且不受伤害',
aiChance: 0.3
},
{
id: 'detector',
name: '检测器',
price: 20,
description: '检测指定药丸是否有毒',
aiChance: 0.4
},
{
id: 'pliers',
name: '钳子',
price: 25,
description: '吃掉一颗药但不受伤害',
aiChance: 0.3
},
{
id: 'phone',
name: '电话',
price: 40,
description: '告诉你哪颗药有毒',
aiChance: 0.2
}
];
// 关卡配置
const levelConfig = {
1: { color: 'red', count: 5, poisonCount: 1, healthDeduct: 1 },
2: { color: 'blue', count: 4, poisonCount: 2, healthDeduct: 1 },
3: { color: 'green', count: 6, poisonCount: 3, healthDeduct: 2 },
4: { color: 'yellow', count: 6, poisonCount: 3, healthDeduct: 2 },
5: { color: 'purple', count: 6, poisonCount: 3, healthDeduct: 2 }
};
// 显示道具商店
function showShop() {
document.getElementById('shop-score').textContent = gameState.playerScore;
updateShopItems();
updatePlayerInventory();
document.querySelectorAll('.screen').forEach(screen => {
screen.classList.remove('active');
});
document.getElementById('shop-screen').classList.add('active');
}
// 更新商店道具
function updateShopItems() {
const shopItems = document.getElementById('shop-items');
shopItems.innerHTML = '';
itemsConfig.forEach(item => {
const itemElement = document.createElement('div');
itemElement.className = 'shop-item';
itemElement.innerHTML = `
<div class="item-name">${item.name}</div>
<div class="item-price">价格: ${item.price}分</div>
<div class="item-desc">${item.description}</div>
`;
itemElement.onclick = () => buyItem(item.id);
shopItems.appendChild(itemElement);
});
}
// 更新玩家道具
function updatePlayerInventory() {
const inventory = document.getElementById('player-inventory');
inventory.innerHTML = '';
if (gameState.playerInventory.length === 0) {
inventory.innerHTML = '<div>暂无道具</div>';
return;
}
// 统计道具数量
const itemCounts = {};
gameState.playerInventory.forEach(item => {
itemCounts[item] = (itemCounts[item] || 0) + 1;
});
// 显示道具
Object.keys(itemCounts).forEach(itemId => {
const item = itemsConfig.find(i => i.id === itemId);
if (item) {
const itemElement = document.createElement('div');
itemElement.className = 'inventory-item';
itemElement.innerHTML = `
${item.name} x${itemCounts[item.id]}
`;
itemElement.onclick = () => {};
inventory.appendChild(itemElement);
}
});
}
// 更新游戏中的道具显示
function updateGameInventory() {
const inventory = document.getElementById('game-inventory');
inventory.innerHTML = '';
if (gameState.playerInventory.length === 0) {
inventory.innerHTML = '<div>暂无道具</div>';
document.getElementById('player-items').textContent = '无';
return;
}
// 统计道具数量
const itemCounts = {};
gameState.playerInventory.forEach(item => {
itemCounts[item] = (itemCounts[item] || 0) + 1;
});
// 显示道具
Object.keys(itemCounts).forEach(itemId => {
const item = itemsConfig.find(i => i.id === itemId);
if (item) {
const itemElement = document.createElement('div');
itemElement.className = 'inventory-item';
itemElement.innerHTML = `
${item.name} x${itemCounts[item.id]}
`;
itemElement.onclick = () => useItem(item.id);
inventory.appendChild(itemElement);
}
});
// 更新状态栏道具显示
const itemNames = Object.keys(itemCounts).map(id => {
const item = itemsConfig.find(i => i.id === id);
return `${item.name} x${itemCounts[id]}`;
});
document.getElementById('player-items').textContent = itemNames.join(', ');
}
// 更新AI道具显示
function updateAIInventory() {
if (gameState.aiInventory.length === 0) {
document.getElementById('ai-items').textContent = '无';
return;
}
// 统计道具数量
const itemCounts = {};
gameState.aiInventory.forEach(item => {
itemCounts[item] = (itemCounts[item] || 0) + 1;
});
// 更新状态栏道具显示
const itemNames = Object.keys(itemCounts).map(id => {
const item = itemsConfig.find(i => i.id === id);
return `${item.name} x${itemCounts[id]}`;
});
document.getElementById('ai-items').textContent = itemNames.join(', ');
}
// 购买道具
function buyItem(itemId) {
const item = itemsConfig.find(i => i.id === itemId);
if (!item) return;
if (gameState.playerScore >= item.price) {
gameState.playerScore -= item.price;
gameState.playerInventory.push(itemId);
document.getElementById('shop-score').textContent = gameState.playerScore;
updatePlayerInventory();
// 显示购买成功消息
showModal('购买成功', `你成功购买了${item.name}!`);
} else {
showModal('积分不足', `购买${item.name}需要${item.price}分,你只有${gameState.playerScore}分。`);
}
}
// 使用道具
function useItem(itemId) {
if (!gameState.playerTurn || gameState.gameOver || gameState.aiThinking) return;
const item = itemsConfig.find(i => i.id === itemId);
if (!item) return;
// 检查是否有这个道具
const itemIndex = gameState.playerInventory.indexOf(itemId);
if (itemIndex === -1) return;
gameState.usingItem = itemId;
switch (itemId) {
case 'candy':
document.getElementById('message').textContent = `> 已选择${item.name},请选择要代替的药丸`;
break;
case 'detector':
document.getElementById('message').textContent = `> 已选择${item.name},请输入要检测的药丸编号`;
break;
case 'pliers':
document.getElementById('message').textContent = `> 已选择${item.name},请选择要安全吃下的药丸`;
break;
case 'phone':
usePhoneItem();
break;
}
}
// 使用电话道具
function usePhoneItem() {
const itemIndex = gameState.playerInventory.indexOf('phone');
if (itemIndex === -1) return;
// 找出有毒的药丸
const poisonousPills = [];
gameState.currentPills.forEach((pill, index) => {
const pillElement = document.querySelector(`.pills-container .pill:nth-child(${index + 1})`);