-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblack.html
More file actions
337 lines (300 loc) · 7.05 KB
/
black.html
File metadata and controls
337 lines (300 loc) · 7.05 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
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<style>
*{
transition: all .5s;
}
.bigBox{
position: relative;
width: 270px;
height: 500px;
overflow: hidden;
border: solid 1px #000;
box-shadow: 2px 2px 10px rgba(0,0,0,.2);
box-sizing: border-box;
}
.box{
position: absolute;
width: 250px;
margin: 20px;
bottom: 0px;
padding: 200px 0;
}
.box4{
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 20px;
width: 100px;
height: 40px;
background: #fff;
border: 1px solid #000;
box-shadow: 5px 5px 10px rgba(0,0,0,.2);
}
.box5{
position: absolute;
top: 20px;
left: 50%;
opacity: 0;
transform: translateX(-50%);
color: #FF0000;
font-size: 24px;
}
.box6,.box7,.box8{
width: 60px;
height: 40px;
margin: 0 10px;
background: #fff;
border: 1px solid #000;
box-shadow: 5px 5px 10px rgba(0,0,0,.2);
}
.box2,.box3{
position: absolute;
top: 10px;
transform: translateX(-50%);
margin: 0 0 ;
}
.box2{
left: 20%;
}
.box3{
right:10%;
}
.head{
position: absolute;
width: 100%;
height: 40px;
background: #FFFFFF;
box-shadow: 5px 5px 10px rgba(0,0,0,.2);
border: 1px solid #000;
box-sizing: border-box;
}
.odd{
background:#ccc;
margin:10px;
text-align:center;
color:#fff;
width:50px;
height:50px;
line-height:50px;
box-shadow: 2px 2px 10px rgba(0,0,0,.2);
}
.bothBox1{
display: inline-block;
border: 1px solid #000;
}
.bothBox2{
opacity: 0;
display: inline;
margin:50px;
}
.bothBox3{
opacity: 0;
display: inline;
}
.bothBox4{
display: inline-block;
border: 1px solid #000;
}
.bothBox5{
opacity: 0;
display: inline;
margin:50px;
}
.bothBox6{
opacity: 0;
display: inline;
}
.bothBox7{
display: inline-block;
border: 1px solid #000;
}
.bothBox8{
display: inline;
opacity: 0;
}
.bothBox9{
opacity: 0;
display: inline;
margin:50px;
}
.demo1{
background: #000;
}
.demo2{
background: green;
}
.smlBox{
margin: 20px 0;
}
.boxActive{
opacity: 0;
}
.boxActives{
background: red;
opacity: 0.5;
}
.boxAmin1{
animation: flotop 60s forwards;
}
.boxAmin2{
animation: flotop 40s forwards;
}
.boxAmin3{
animation: flotop 20s forwards;
}
.box5Amin{
animation: fadeinout .5s forwards;
}
@keyframes flotop{
from{bottom: 0px;}
to{bottom: -5000px;}
}
@keyframes fadeinout{
from{opacity: 1;}
to{opacity: 0;}
}
</style>
<div class="bigBox">
<div class="box"></div>
<div class="head">
<h4 class="box2">分数:0</h4>
<h4 class="box3">倒计时:</h4>
</div>
<h4 class="box5"></h4>
<button class="box4">开始游戏</button>
</div>
<div class="smlBox">
<button class="box6">简单</button>
<button class="box7">中等</button>
<button class="box8">困难</button>
</div>
<div class="btn">
<h1>别踩黑块 游戏</h1>
</div>
<script>
// Math.ceil(Math.random()*9) //随机九位数
window.onload = function(){
inHtml()
}
var jiannum = 20 //倒计时
var resNum = 10 //加分值
var spe3 = "boxAmin3"
var spe2 = "boxAmin2"
var spe1 = "boxAmin1"
function spe(oclass){
var spe = oclass
return spe
}
var speNs = 0
var box6 = document.querySelector('.box6')
var box7 = document.querySelector('.box7')
var box8 = document.querySelector('.box8')
box6.onclick = function(){
speNs = 1
alert('你选择了简单系数,点击开始游戏')
}
box7.onclick = function(){
speNs = 2
alert('你选择了中等系数,点击开始游戏')
}
box8.onclick = function(){
speNs = 3
alert('你选择了困难系数,点击开始游戏')
}
function inHtml() {
var box = document.querySelector('.box')
var box3 = document.querySelector('.box3')
var box4 = document.querySelector('.box4')
var boxs = 1000 //盒子数量
var boxHtml = ''
for (var i = 0; i < boxs; i++) {
boxHtml = boxHtml + '<div class="odd bothBox' + Math.ceil(Math.random()*9) + '"></div>'
}
box.innerHTML += boxHtml
box3.innerHTML = '倒计时:' + jiannum
box4.addEventListener('click',Game,true)
}
function Game() {
var box = document.querySelector('.box')
var box2 = document.querySelector('.box2')
var box3 = document.querySelector('.box3')
var box4 = document.querySelector('.box4')
var box5 = document.querySelector('.box5')
var jishuIndex = document.querySelectorAll('.odd');
var jiafenNum = 0;
if(speNs == 0){
var speNum = spe(spe1)
}else if(speNs == 1){
var speNum = spe(spe1)
}else if(speNs == 2){
var speNum = spe(spe2)
}else if(speNs == 3){
var speNum = spe(spe3)
}
box4.removeEventListener('click',Game,false)
box4.style.bottom = '-40px'
box2.innerHTML = '分数:' + jiafenNum
box.classList.add(speNum);
for (var i = 0; i < jishuIndex.length; i++) {
jishuIndex[i].index = i
jishuIndex[i].addEventListener('click',function(){
if (this.index % 2 == 1) {
jishuIndex[this.index].classList.add("boxActives");
box5.innerHTML = '-10'
box5.classList.add("box5Amin");
setTimeout(function () {
box5.classList.remove("box5Amin");
jiafenNum = jiafenNum - resNum;
box2.innerHTML = '分数:' + jiafenNum
if (jiafenNum < 0) {
jiafenNum = 0;
box2.innerHTML = '分数:' + jiafenNum
}
},200)
} else {
setTimeout(function () {
box5.classList.remove("box5Amin");
},200)
jishuIndex[this.index].classList.add("boxActive");
box5.innerHTML = '+10'
box5.classList.add("box5Amin");
jiafenNum = jiafenNum + resNum;
box2.innerHTML = '分数:' + jiafenNum
}
},false)
if (jishuIndex[i].index % 2 == 1) {
jishuIndex[i].classList.add("demo1");
}else {
jishuIndex[i].classList.add("demo2");
}
}
function timer() {
jiannum--;
box3.innerHTML = '倒计时:' + jiannum
}
var timerss = setInterval(function () {
timer()
if (jiannum == 0) {
alert('游戏结束,你的分数为:' + jiafenNum + '分')
jiannum = resNum;
jiafenNum = 0;
box2.innerHTML = '分数:' + jiafenNum
inHtml()
startNum = 0
clearInterval(timerss)
var box = document.querySelector('.box')
box.classList.remove(speNum);
box4.style.bottom = '20px'
}
}, 1000)
}
</script>
</body>
</html>