6
6
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
7
< title > 24点</ title >
8
8
< style >
9
+ body {
10
+ font-family : Arial, sans-serif;
11
+ display : flex;
12
+ flex-direction : column;
13
+ align-items : center;
14
+ background-color : # f0f8ff ;
15
+ margin : 0 ;
16
+ padding : 20px ;
17
+ }
18
+ h1 {
19
+ color : # 333 ;
20
+ margin-bottom : 10px ;
21
+ }
22
+ .game-info {
23
+ display : flex;
24
+ justify-content : space-between;
25
+ width : 100% ;
26
+ max-width : 600px ;
27
+ margin-bottom : 20px ;
28
+ }
9
29
.card-container {
10
30
display : flex;
11
- justify-content : flex-start;
12
- margin-top : 20px ;
13
- width : 80% ;
31
+ justify-content : center;
14
32
flex-wrap : wrap;
15
-
33
+ gap : 10px ;
34
+ margin-top : 20px ;
35
+ width : 100% ;
36
+ max-width : 600px ;
16
37
}
17
-
18
38
.card {
19
39
width : 100px ;
20
40
height : 150px ;
21
- background-color : # f0f0f0 ;
41
+ background-color : # fff ;
22
42
border-radius : 15px ;
23
43
display : flex;
24
44
justify-content : center;
25
45
align-items : center;
26
46
font-size : 24px ;
27
47
font-weight : bold;
28
- box-shadow : 2px 2px 8px rgba (0 , 0 , 0 , 0.2 );
29
- margin : 1vmin ;
48
+ box-shadow : 0 4px 8px rgba (0 , 0 , 0 , 0.1 );
49
+ transition : transform 0.2s ;
50
+ }
51
+ .card : hover {
52
+ transform : translateY (-5px );
30
53
}
31
-
32
54
button {
33
- margin-top : 20 px ;
55
+ margin : 10 px ;
34
56
padding : 10px 20px ;
35
57
font-size : 16px ;
36
58
cursor : pointer;
59
+ background-color : # 4CAF50 ;
60
+ color : white;
61
+ border : none;
62
+ border-radius : 5px ;
63
+ transition : background-color 0.3s ;
64
+ }
65
+ button : hover {
66
+ background-color : # 45a049 ;
67
+ }
68
+ # operation {
69
+ display : none;
70
+ position : fixed;
71
+ top : 50% ;
72
+ left : 50% ;
73
+ transform : translate (-50% , -50% );
74
+ background-color : white;
75
+ padding : 20px ;
76
+ border-radius : 10px ;
77
+ box-shadow : 0 0 10px rgba (0 , 0 , 0 , 0.3 );
78
+ z-index : 1000 ;
79
+ }
80
+ # overlay {
81
+ display : none;
82
+ position : fixed;
83
+ top : 0 ;
84
+ left : 0 ;
85
+ width : 100% ;
86
+ height : 100% ;
87
+ background-color : rgba (0 , 0 , 0 , 0.5 );
88
+ z-index : 999 ;
37
89
}
38
90
</ style >
39
91
</ head >
40
92
41
93
< body >
42
- < h1 > 24点</ h1 >
43
- < div id = "score " style ="font-size: 2em;font-weight: bold; "> 得分: 0</ div >
44
- < div style ="display:flex;justify-content:space-between ">
45
-
46
-
47
- < button onclick ="drawCards() "> 抽牌</ button >
48
- < button onclick ="cal() " style ="display: none; "> 算牌</ button >
49
- < button onclick ="gaveup() " > 放弃牌</ button >
50
- < button onclick ="showResult(true) " style ="display: none; "> 显示结果</ button >
51
- < div id ="counter " style ="font-size: 2em;font-weight: bold; "> </ div >
94
+ < h1 > 24点游戏</ h1 >
95
+ < div class ="game-info ">
96
+ < div id ="score " style ="font-size: 1.5em; font-weight: bold; "> 得分: 0</ div >
97
+ < div id ="counter " style ="font-size: 1.5em; font-weight: bold; "> </ div >
52
98
</ div >
53
-
54
99
< div >
55
- < div class ="card-container " id ="cardContainer "> <!-- 这里将显示抽出的牌 --> </ div >
56
- < div id ="outputs " style ="display: none;font-size: 1.5em; " onclick ="drawCards() "> </ div >
57
- < div id ="inputs " > </ div >
100
+ < button onclick ="drawCards() "> 开始</ button >
101
+ < button onclick ="unhide() " id ="calButton " style ="display: none; "> 算牌</ button >
102
+ < button onclick ="gaveup() "> 放弃牌</ button >
103
+ < button onclick ="showResult(true) " style ="display: none; "> 显示结果</ button >
58
104
</ div >
105
+ < div class ="card-container " id ="cardContainer "> </ div >
106
+ < div id ="outputs " style ="display: none; font-size: 1.5em; " onclick ="drawCards() "> </ div >
107
+ < div id ="inputs "> </ div >
108
+ < div id ="overlay " onclick ="hide() "> </ div >
59
109
< div id ="operation ">
60
- <!-- 显示四个按钮,代表四则运算,点击后赋值selectedMethod 0:+,1:-,2:*,3:/-->
61
-
62
- < button onclick ="selectedMethod(0) "> +</ button >
63
- < button onclick ="selectedMethod(1) "> -</ button >
64
- < button onclick ="selectedMethod(2) "> *</ button >
65
- < button onclick ="selectedMethod(3) "> /</ button >
110
+ < button onclick ="selectedMethod(0) "> +</ button >
111
+ < button onclick ="selectedMethod(1) "> -</ button >
112
+ < button onclick ="selectedMethod(2) "> ×</ button >
113
+ < button onclick ="selectedMethod(3) "> ÷</ button >
66
114
</ div >
67
115
< script type ="text/javascript " src ="str.js "> </ script >
68
116
@@ -79,6 +127,16 @@ <h1>24点</h1>
79
127
const method = [ '+' , '-' , '*' , '/' ] ;
80
128
var interval ;
81
129
var score = 0 ;
130
+ function unhide ( ) {
131
+ document . getElementById ( 'operation' ) . style . display = 'block' ;
132
+ document . getElementById ( 'overlay' ) . style . display = 'block' ;
133
+ }
134
+
135
+ function hide ( ) {
136
+ document . getElementById ( 'operation' ) . style . display = 'none' ;
137
+ document . getElementById ( 'overlay' ) . style . display = 'none' ;
138
+ }
139
+
82
140
function gaveup ( ) {
83
141
clearInterval ( interval ) ; // 停止计时器
84
142
fail ( ) ; // 倒计时结束,触发fail函数
@@ -116,6 +174,7 @@ <h1>24点</h1>
116
174
function selectedMethod ( i ) {
117
175
selMethod = i ;
118
176
if ( selectedCards . length == 2 ) {
177
+ hide ( ) ;
119
178
var cd = calc ( checkCardSourceReturnCardNumber ( selectedCards [ 0 ] ) , selMethod , checkCardSourceReturnCardNumber ( selectedCards [ 1 ] ) ) ;
120
179
document . getElementById ( `card${ selectedCards [ 0 ] } ` ) . style . display = "none" ;
121
180
document . getElementById ( `card${ selectedCards [ 1 ] } ` ) . style . display = "none" ;
@@ -199,6 +258,9 @@ <h1>24点</h1>
199
258
if ( selectedCards . length < 2 ) {
200
259
selectedCards . push ( index ) ;
201
260
document . getElementById ( `card${ index } ` ) . style . border = "2px solid blue" ;
261
+ if ( selectedCards . length == 2 ) {
262
+ unhide ( ) ;
263
+ }
202
264
} else if ( selectedCards . length == 2 ) {
203
265
if ( selMethod != - 1 ) {
204
266
var cd = calc ( checkCardSourceReturnCardNumber ( selectedCards [ 0 ] ) , selMethod , checkCardSourceReturnCardNumber ( selectedCards [ 1 ] ) ) ;
0 commit comments