-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
625 lines (566 loc) · 17.9 KB
/
index.html
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>听令小方块</title>
<style>
body {
margin: 0;
padding: 0;
}
#content-wrap {
width: 600px;
float: left;
}
.main {
margin-bottom: 20px;
}
.clearfix:after {
content: '.';
display: block;
height: 0;
clear: both;
visibility: hidden;
overflow: hidden;
}
.row .item, .col .item {
width: 50px;
height: 50px;
}
.row .item {
display: inline-block;
margin-right: -4.5px;
text-align: center;
line-height: 3em;
}
.row {
margin-left: 50px;
}
.col {
float: left;
}
.col .item {
text-align: center;
line-height: 50px;
}
.box-wrap {
position: relative;
left: 0;
top: 0;
float: left;
width: 500px;
height: 500px;
border: 2px solid #000;
box-sizing: content-box;
}
.box {
float: left;
vertical-align: top;
width: 50px;
height: 50px;
outline: 1px solid #ccc;
box-sizing: border-box;
}
.flow {
position: absolute;
top: 150px;
left: 200px;
width: 50px;
height: 50px;
box-sizing: border-box;
border: 1px solid #ccc;
background: linear-gradient(to bottom, blue 20%, red 20%);
}
.btn-wrap {
width: 600px;
text-align: center;
}
.btn-wrap button {
height: 30px;
border: none;
padding: 0 10px;
margin-bottom: 10px;
border-radius: 4px;
color: #fff;
background-color: #269abc;
}
.exp {
float: left;
overflow: hidden;
}
</style>
</head>
<body>
<div id="content-wrap">
<!--横标-->
<div class="row">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
</div>
<div class="main clearfix">
<!--竖标-->
<div class="col">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
</div>
<!--方格-->
<div class="box-wrap clearfix">
<div class="box item00"></div>
<div class="box item01"></div>
<div class="box item02"></div>
<div class="box item03"></div>
<div class="box item04"></div>
<div class="box item05"></div>
<div class="box item06"></div>
<div class="box item07"></div>
<div class="box item08"></div>
<div class="box item09"></div>
<div class="box item10"></div>
<div class="box item11"></div>
<div class="box item12"></div>
<div class="box item13"></div>
<div class="box item14"></div>
<div class="box item15"></div>
<div class="box item16"></div>
<div class="box item17"></div>
<div class="box item18"></div>
<div class="box item19"></div>
<div class="box item20"></div>
<div class="box item21"></div>
<div class="box item22"></div>
<div class="box item23"></div>
<div class="box item24"></div>
<div class="box item25"></div>
<div class="box item26"></div>
<div class="box item27"></div>
<div class="box item28"></div>
<div class="box item29"></div>
<div class="box item30"></div>
<div class="box item31"></div>
<div class="box item32"></div>
<div class="box item33"></div>
<div class="box item34"></div>
<div class="box item35"></div>
<div class="box item36"></div>
<div class="box item37"></div>
<div class="box item38"></div>
<div class="box item39"></div>
<div class="box item40"></div>
<div class="box item41"></div>
<div class="box item42"></div>
<div class="box item43"></div>
<div class="box item44"></div>
<div class="box item45"></div>
<div class="box item46"></div>
<div class="box item47"></div>
<div class="box item48"></div>
<div class="box item49"></div>
<div class="box item50"></div>
<div class="box item51"></div>
<div class="box item52"></div>
<div class="box item53"></div>
<div class="box item54"></div>
<div class="box item55"></div>
<div class="box item56"></div>
<div class="box item57"></div>
<div class="box item58"></div>
<div class="box item59"></div>
<div class="box item60"></div>
<div class="box item61"></div>
<div class="box item62"></div>
<div class="box item63"></div>
<div class="box item64"></div>
<div class="box item65"></div>
<div class="box item66"></div>
<div class="box item67"></div>
<div class="box item68"></div>
<div class="box item69"></div>
<div class="box item70"></div>
<div class="box item71"></div>
<div class="box item72"></div>
<div class="box item73"></div>
<div class="box item74"></div>
<div class="box item75"></div>
<div class="box item76"></div>
<div class="box item77"></div>
<div class="box item78"></div>
<div class="box item79"></div>
<div class="box item80"></div>
<div class="box item81"></div>
<div class="box item82"></div>
<div class="box item83"></div>
<div class="box item84"></div>
<div class="box item85"></div>
<div class="box item86"></div>
<div class="box item87"></div>
<div class="box item88"></div>
<div class="box item89"></div>
<div class="box item90"></div>
<div class="box item91"></div>
<div class="box item92"></div>
<div class="box item93"></div>
<div class="box item94"></div>
<div class="box item95"></div>
<div class="box item96"></div>
<div class="box item97"></div>
<div class="box item98"></div>
<div class="box item99"></div>
<div class="flow"></div>
</div>
</div>
<div class="btn-wrap">
<button type="button" id="go">go</button>
<button type="button" id="tun-lef">turn left</button>
<button type="button" id="tun-rit">turn right</button>
<button type="button" id="tun-bac">turn back</button>
</div>
<div class="btn-wrap">
<button type="button" id="tra-lef">tra left</button>
<button type="button" id="tra-top">tra top</button>
<button type="button" id="tra-rig">tra right</button>
<button type="button" id="tra-bot">tra bottom</button>
<br>
<button type="button" id="mov-lef">mov left</button>
<button type="button" id="mov-top">mov top</button>
<button type="button" id="mov-rig">mov right</button>
<button type="button" id="mov-bot">mov bottom</button>
</div>
</div>
<div class="exp">
<h3>按钮说明</h3>
<p><strong>go</strong>: 向蓝色边方向前进一格</p>
<p><strong>turn left</strong>: 向左(逆时针)旋转90度</p>
<p><strong>turn right</strong>: 向右(顺时针)旋转90度</p>
<p><strong>turn back</strong>: 向右旋转180度</p>
<p><strong>tra left</strong>: 向屏幕的左侧移动一格,方向不变</p>
<p><strong>tra top</strong>: 向屏幕的上面移动一格,方向不变</p>
<p><strong>tra right</strong>: 向屏幕的右侧移动一格,方向不变</p>
<p><strong>tra bottom</strong>: 向屏幕的下面移动一格,方向不变</p>
<p><strong>mov left</strong>: 方向转向屏幕左侧,并向屏幕的左侧移动一格</p>
<p><strong>mov top</strong>: 方向转向屏幕上面,向屏幕的上面移动一格</p>
<p><strong>mov right</strong>: 方向转向屏幕右侧,向屏幕的右侧移动一格</p>
<p><strong>mov bottom</strong>: 方向转向屏幕下面,向屏幕的下面移动一格</p>
</div>
<script>
var boxWrap = document.getElementsByClassName('box-wrap')[0];
var flow = boxWrap.getElementsByClassName('flow')[0];
var go = document.getElementById('go');
var tunLef = document.getElementById('tun-lef');
var tunRit = document.getElementById('tun-rit');
var tunBac = document.getElementById('tun-bac');
var traLef = document.getElementById('tra-lef');
var traTop = document.getElementById('tra-top');
var traRig = document.getElementById('tra-rig');
var traBot = document.getElementById('tra-bot');
var movLef = document.getElementById('mov-lef');
var movTop = document.getElementById('mov-top');
var movRig = document.getElementById('mov-rig');
var movBot = document.getElementById('mov-bot');
var deg = 0, direction = 1;
var options = {
duration: 1000,
iterations: 1,
fill: 'forwards'
};
/*向左转和向右转的实现函数*/
function trans(x, y) {
var frames = [
{
borderRadius: 0,
transform: 'rotate(' + x + 'deg)'
},
{
borderRadius: '50%'
},
{
borderRadius: 0,
transform: 'rotate(' + y + 'deg)'
}
];
flow.animate(frames, options);
}
/*点击向左转后*/
tunLef.onclick = function () {
trans(deg, (deg - 90));
deg -= 90;
};
/*点击向右转后*/
tunRit.onclick = function () {
trans(deg, (deg + 90));
deg += 90;
};
/*点击向后转*/
tunBac.onclick = function () {
trans(deg, (deg + 180));
deg += 180;
};
/*方向判断方法*/
function judge() {
if (deg >= 0) {
var i = deg % 360;
switch (i) {
case 0:
direction = 1;
break;
case 90:
direction = 2;
break;
case 180:
direction = 3;
break;
case 270:
direction = 4;
break;
default:
return;
}
} else if (deg < 0) {
var j = deg % 360;
switch (j) {
case -90:
direction = 4;
break;
case -180:
direction = 3;
break;
case -270:
direction = 2;
break;
case 0:
direction = 1;
break;
default:
return;
}
}
}
/*向前一步的方法一(上下)*/
function goFunc(m, n) {
var frames = [
{
top: m + 'px'
},
{
top: n + 'px'
}
];
flow.animate(frames, options);
}
/*向前移动一步的方法二(左右)*/
function goFunc2(m, n) {
var frames = [
{
left: m + 'px'
},
{
left: n + 'px'
}
];
flow.animate(frames, options);
}
/*向前一步*/
function forwork() {
judge();
var top = flow.offsetTop;
var left = flow.offsetLeft;
if (direction === 1) {
if (top >= 50) {
goFunc(top, (top - 50));
} else {
return false;
}
} else if (direction === 2) {
if (left <= 400) {
goFunc2(left, (left + 50));
} else {
return false
}
} else if (direction === 3) {
if (top <= 400) {
goFunc(top, (top + 50));
} else {
return false;
}
} else if (direction === 4) {
if (left >= 50) {
goFunc2(left, (left - 50));
}
}
}
/*点击向前一步*/
go.onclick = function () {
forwork();
};
/*向左右侧移动一格方法*/
function traFunc(a, b) {
var frames = [
{
left: a + 'px'
},
{
left: b + 'px'
}
];
flow.animate(frames, options);
}
/*向上下侧移动一格的方法*/
function traFunc2(a, b) {
var frames = [
{
top: a + 'px'
},
{
top: b + 'px'
}
];
flow.animate(frames, options);
}
traLef.onclick = function () {
var top = flow.offsetTop;
var left = flow.offsetLeft;
if (left >= 50 && left <= 400) {
traFunc(left, (left - 50));
} else {
//return false;
}
};
traRig.onclick = function () {
var top = flow.offsetTop;
var left = flow.offsetLeft;
if (left >= 50 && left <= 400) {
traFunc(left, (left + 50));
} else {
return false;
}
};
traTop.onclick = function () {
var top = flow.offsetTop;
var left = flow.offsetLeft;
if (top >= 50 && top <= 400) {
traFunc2(top, (top - 50));
} else {
return false;
}
};
traBot.onclick = function () {
var top = flow.offsetTop;
var left = flow.offsetLeft;
if (top >= 50 && top <= 400) {
traFunc2(top, (top + 50));
} else {
return false;
}
};
/*方向转向左右侧,并向左右侧移动一格*/
function mov(p, q, z, w) {
var frames = [
{
left: p + 'px',
borderRadius: 0,
transform: 'rotate(' + (z * 90) + 'deg)'
},
{
borderRadius: '50%'
},
{
left: q + 'px',
borderRadius: 0,
transform: 'rotate(' + w + 'deg)'
}
];
flow.animate(frames, options);
}
/*方向转向上下侧,并向上下侧移动一格*/
function mov2(p, q, z, w) {
var frames = [
{
top: p + 'px',
borderRadius: 0,
transform: 'rotate(' + (z * 90) + 'deg)'
},
{
borderRadius: '50%'
},
{
top: q + 'px',
borderRadius: 0,
transform: 'rotate(' + w + 'deg)'
}
];
flow.animate(frames, options);
}
movLef.onclick = function () {
judge();
var top = flow.offsetTop;
var left = flow.offsetLeft;
var tarDeg = 270;
var dir = direction - 1;
if (left >= 50 && left <= 400) {
mov(left, (left - 50), dir, tarDeg);
direction = 4;
deg = 270;
} else {
return false;
}
};
movRig.onclick = function () {
judge();
var top = flow.offsetTop;
var left = flow.offsetLeft;
var tarDeg = 90;
var dir = direction - 1;
if (left >= 50 && left <= 400) {
mov(left, (left + 50), dir, tarDeg);
direction = 2;
deg = 90;
} else {
return false;
}
};
movTop.onclick = function () {
judge();
var top = flow.offsetTop;
var left = flow.offsetLeft;
var tarDeg = 0;
var dir = direction - 1;
if (top >= 50 && top <= 400) {
mov2(top, (top - 50), dir, tarDeg);
direction = 1;
deg = 0;
} else {
return false;
}
};
movBot.onclick = function () {
judge();
var top = flow.offsetTop;
var left = flow.offsetLeft;
var tarDeg = 180;
var dir = direction - 1;
if (top >= 50 && top <= 400) {
mov2(top, (top + 50), dir, tarDeg);
direction = 3;
deg = 180;
} else {
return false;
}
};
</script>
</body>
</html>