@@ -97,9 +97,10 @@ <h1>24点游戏</h1>
97
97
< div id ="counter " style ="font-size: 1.5em; font-weight: bold; "> </ div >
98
98
</ div >
99
99
< div >
100
- < button onclick ="drawCards() "> 开始</ button >
100
+ < button onclick ="drawCards() " id =" startButton " > 开始</ button >
101
101
< 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 >
103
104
< button onclick ="showResult(true) " style ="display: none; "> 显示结果</ button >
104
105
</ div >
105
106
< div class ="card-container " id ="cardContainer "> </ div >
@@ -201,7 +202,8 @@ <h1>24点游戏</h1>
201
202
function drawCards ( ) {
202
203
startCountdown ( ) ;
203
204
// 清空上次输出
204
- document . getElementById ( "outputs" ) . innerHTML = " " ;
205
+ document . getElementById ( "outputs" ) . innerHTML = " " ;
206
+ document . getElementById ( "startButton" ) . style . display = "none" ;
205
207
showResult ( false ) ;
206
208
// 随机抽取4张不重复的牌
207
209
let drawnCards = [ ] ;
@@ -255,7 +257,15 @@ <h1>24点游戏</h1>
255
257
} ;
256
258
var selectedCards = [ ] ;
257
259
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 ) {
259
269
selectedCards . push ( index ) ;
260
270
document . getElementById ( `card${ index } ` ) . style . border = "2px solid blue" ;
261
271
if ( selectedCards . length == 2 ) {
@@ -414,4 +424,4 @@ <h1>24点游戏</h1>
414
424
</ script >
415
425
</ body >
416
426
417
- </ html >
427
+ </ html >
0 commit comments