Skip to content

Commit f4cfb46

Browse files
authored
Update index.html
增加了重置本局按钮,修复了重点牌面和重点开始的错误
1 parent c57a54b commit f4cfb46

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

32-24-Point-Poker-Game/index.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ <h1>24点游戏</h1>
9797
<div id="counter" style="font-size: 1.5em; font-weight: bold;"></div>
9898
</div>
9999
<div>
100-
<button onclick="drawCards()">开始</button>
100+
<button onclick="drawCards()" id="startButton">开始</button>
101101
<button onclick="unhide()" id="calButton" style="display: none;">算牌</button>
102-
<button onclick="gaveup()">放弃牌</button>
102+
<button onclick="gaveup()">放弃本局</button>
103+
<button onclick="resetCals(-1)">重置本局</button>
103104
<button onclick="showResult(true)" style="display: none;">显示结果</button>
104105
</div>
105106
<div class="card-container" id="cardContainer"></div>
@@ -201,7 +202,8 @@ <h1>24点游戏</h1>
201202
function drawCards() {
202203
startCountdown();
203204
// 清空上次输出
204-
document.getElementById("outputs").innerHTML = " ";
205+
document.getElementById("outputs").innerHTML = " ";
206+
document.getElementById("startButton").style.display = "none";
205207
showResult(false);
206208
// 随机抽取4张不重复的牌
207209
let drawnCards = [];
@@ -255,7 +257,15 @@ <h1>24点游戏</h1>
255257
};
256258
var selectedCards = [];
257259
function clcikCard(index) {
258-
if (selectedCards.length < 2) {
260+
// 检查是否已经选中了这张卡片
261+
const cardIndex = selectedCards.indexOf(index);
262+
if (cardIndex !== -1) {
263+
// 如果已经选中,取消选择
264+
document.getElementById(`card${index}`).style.border = "none";
265+
selectedCards.splice(cardIndex, 1);
266+
// 如果之前已经显示操作窗口,现在应该隐藏
267+
hide();
268+
} else if (selectedCards.length < 2) {
259269
selectedCards.push(index);
260270
document.getElementById(`card${index}`).style.border = "2px solid blue";
261271
if(selectedCards.length == 2){
@@ -414,4 +424,4 @@ <h1>24点游戏</h1>
414424
</script>
415425
</body>
416426

417-
</html>
427+
</html>

0 commit comments

Comments
 (0)