-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissors.html
More file actions
380 lines (333 loc) · 10.4 KB
/
Copy pathRockPaperScissors.html
File metadata and controls
380 lines (333 loc) · 10.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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>石头剪刀布 - JustHTML 只需网页</title>
<script>
/**
* 动态加载(强制去除缓存) CSS 的函数
* @param {string} src - 要加载的 CSS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadStyle(src) {
return new Promise((resolve, reject) => {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
link.async = true;
link.onload = resolve;
link.onerror = reject;
document.head.appendChild(link);
});
}
/**
* 动态加载(强制去除缓存) JS 的函数
* @param {string} src - 要加载的 JS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
script.async = true;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
</script>
<script>
loadStyle('../assets/style.css')
let scriptArray = [
"../assets/AddHeader_Tools.js",
"../assets/AddFooter.js",
"../assets/AddIco.js",
"../assets/AutoRun.js",
]
scriptArray.forEach(script => {
loadScript(script);
});
</script>
<script src="../package/Vue/code/vue.global.prod.js"></script>
<script type="module" src="../package/Sober/code/main.js"></script>
<style>
.game-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.players-container {
display: flex;
justify-content: space-around;
width: 100%;
margin: 20px 0;
}
.player {
text-align: center;
padding: 20px;
background-color: var(--bg-secondary);
border-radius: var(--border-radius);
width: 45%;
}
.player-title {
font-size: 1.5em;
margin-bottom: 15px;
color: var(--accent-color);
}
.choice-display {
font-size: 4em;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
margin: 15px 0;
}
.choices-container {
display: flex;
justify-content: center;
gap: 20px;
margin: 30px 0;
}
.choice-btn {
font-size: 3em;
width: 100px;
height: 100px;
border-radius: 50%;
border: 2px solid var(--accent-color);
background-color: var(--bg-secondary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s;
}
.choice-btn:hover {
background-color: var(--bg-tertiary);
transform: scale(1.1);
}
.result-container {
margin: 30px 0;
text-align: center;
min-height: 100px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.8em;
font-weight: bold;
width: 100%;
}
.score-container {
display: flex;
justify-content: space-around;
width: 100%;
margin: 20px 0;
background-color: var(--bg-secondary);
padding: 15px;
border-radius: var(--border-radius);
}
.score-item {
text-align: center;
}
.score-value {
font-size: 2em;
color: var(--accent-color);
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin: 15px 0;
justify-content: center;
}
.info-box {
background-color: var(--bg-tertiary);
padding: 10px;
border-radius: var(--border-radius);
margin: 10px 0;
text-align: center;
}
.history-container {
width: 100%;
max-width: 600px;
margin-top: 20px;
}
.history-item {
padding: 10px;
background-color: var(--bg-secondary);
border-radius: var(--border-radius);
margin-bottom: 8px;
display: flex;
justify-content: space-between;
}
.winning-move {
color: #4ade80;
}
.losing-move {
color: #f87171;
}
.tie-move {
color: #94a3b8;
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<a href="../index.html" class="back-link">← 返回首页</a>
<div class="tool-section">
<h2>石头剪刀布</h2>
<p>经典的猜拳游戏</p>
<div class="info-box">
<p><strong>游戏规则:</strong></p>
<p>石头胜剪刀,剪刀胜布,布胜石头</p>
</div>
<div class="game-container">
<div class="players-container">
<div class="player">
<div class="player-title">玩家</div>
<div class="choice-display">{{ playerChoice ? playerChoice : '?' }}</div>
</div>
<div class="player">
<div class="player-title">电脑</div>
<div class="choice-display">{{ computerChoice ? computerChoice : '?' }}</div>
</div>
</div>
<div class="choices-container">
<button class="choice-btn" @click="makeChoice('✊')" title="石头">✊</button>
<button class="choice-btn" @click="makeChoice('✋')" title="布">✋</button>
<button class="choice-btn" @click="makeChoice('✌️')" title="剪刀">✌️</button>
</div>
<div class="result-container">
<div :class="resultClass">{{ resultText }}</div>
</div>
<div class="score-container">
<div class="score-item">
<div>玩家得分</div>
<div class="score-value">{{ playerScore }}</div>
</div>
<div class="score-item">
<div>平局</div>
<div class="score-value">{{ tieScore }}</div>
</div>
<div class="score-item">
<div>电脑得分</div>
<div class="score-value">{{ computerScore }}</div>
</div>
</div>
<div class="controls">
<button @click="resetGame">重置游戏</button>
<button @click="clearHistory">清空历史</button>
</div>
<div class="history-container" v-if="history.length > 0">
<h3>游戏历史</h3>
<div v-for="(record, index) in history" :key="index" class="history-item">
<span>
<span :class="getMoveClass(record.playerMove, record.result)">玩家: {{ record.playerMove }}</span>
vs
<span :class="getMoveClass(record.computerMove, record.result)">电脑: {{ record.computerMove }}</span>
</span>
<span>{{ record.result }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
const { createApp, ref, computed } = Vue;
createApp({
setup() {
const playerChoice = ref('');
const computerChoice = ref('');
const resultText = ref('请选择一个手势');
const resultClass = ref('');
const playerScore = ref(0);
const computerScore = ref(0);
const tieScore = ref(0);
const history = ref([]);
const choices = ['✊', '✋', '✌️'];
const determineWinner = (player, computer) => {
if (player === computer) {
return 'tie';
}
if (
(player === '✊' && computer === '✌️') ||
(player === '✋' && computer === '✊') ||
(player === '✌️' && computer === '✋')
) {
return 'player';
}
return 'computer';
};
const makeChoice = (playerSelection) => {
playerChoice.value = playerSelection;
// 模拟电脑思考时间
setTimeout(() => {
// 随机选择电脑的手势
const randomIndex = Math.floor(Math.random() * choices.length);
computerChoice.value = choices[randomIndex];
// 判断胜负
const winner = determineWinner(playerSelection, computerChoice.value);
// 更新分数
if (winner === 'player') {
playerScore.value++;
resultText.value = '你赢了!';
resultClass.value = 'winning-move';
} else if (winner === 'computer') {
computerScore.value++;
resultText.value = '电脑赢了!';
resultClass.value = 'losing-move';
} else {
tieScore.value++;
resultText.value = '平局!';
resultClass.value = 'tie-move';
}
// 添加到历史记录
history.value.unshift({
playerMove: playerSelection,
computerMove: computerChoice.value,
result: winner === 'player' ? '玩家胜' :
winner === 'computer' ? '电脑胜' : '平局',
timestamp: new Date().toLocaleTimeString()
});
}, 500);
};
const resetGame = () => {
playerChoice.value = '';
computerChoice.value = '';
resultText.value = '请选择一个手势';
resultClass.value = '';
};
const clearHistory = () => {
history.value = [];
};
const getMoveClass = (move, result) => {
if (result === '玩家胜') {
return move === playerChoice.value ? 'winning-move' : 'losing-move';
} else if (result === '电脑胜') {
return move === computerChoice.value ? 'winning-move' : 'losing-move';
} else {
return 'tie-move';
}
};
return {
playerChoice,
computerChoice,
resultText,
resultClass,
playerScore,
computerScore,
tieScore,
history,
makeChoice,
resetGame,
clearHistory,
getMoveClass
};
}
}).mount('#app');
</script>
</body>
</html>