-
Notifications
You must be signed in to change notification settings - Fork 0
/
ife_task_3.5.html
445 lines (413 loc) · 8.37 KB
/
ife_task_3.5.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>task 3.4</title>
<style type="text/css">
#boxs{display: inline-block; width: 600px; }
.top{margin-left: 51px; height: 51px;}
.top div{float: left; width: 51px; text-align: center; font: 20px/51px SimSun;}
.side{float: left; width: 50px;}
.side div{height: 51px; text-align: center; font: 20px/51px SimSun;}
#blocks{position: relative; clear: left; display: inline-block; width: 509px; height: 509px; border: solid 2px #333333;}
.clearfix:after{content: '.'; clear: both; display: block; height: 0; overflow: hidden; visibility: hidden;}
span{display: block; float: left; margin: 0; padding: 0; width: 50px; height: 50px; border-left:solid 1px #cccccc; border-top:solid 1px #cccccc;}
div span:first-child{border-left: none;}
#div1 span{border-top:none;}
.bottom{margin-left: 51px; margin-top: 20px;}
#block{position: absolute; left: 0; top: 0; transition:1s; width: 50px; height: 50px; background: url(http://images.yyshhhh.com/3.4block.png); background-repeat: no-repeat;}
#instr{display: inline-block; font: 14px/28px Microsoft Yahei;}
}
</style>
</head>
<body>
<div id="boxs">
<div class="top">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
<div class="side">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
<div id="blocks">
<div class="clearfix" id="div1">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="clearfix">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div id="block"></div>
</div>
<div class="bottom">
<input type="" name="" id="order">
<input type="button" name="" value="执行" id="btn">
</div>
</div>
<div id="instr">
<pre>
说明:
小方块的蓝色部分是小方块的前进方向
命令:
go 向前进方向前进一格
turn lef 逆时针旋转九十度
turn rig 顺时针旋转九十度
turn bac 旋转一百八十度
tra lef 向左移动一格
move lef 前进方向改为向左并向左前进一格
tra rig 向右移动一格
move rig 前进方向改为向右并向右前进一格
tra top 向上移动一格
move top 前进方向改为向上并向上前进一格
tra bot 向下移动一格
move bot 前进方向改为向下并向下前进一格
</pre>
</div>
<script type="text/javascript">
var order = document.getElementById('order');
var btn = document.getElementById('btn');
var obj = {
x: 0,
y: 0,
dir: 0
};
var blocks = document.getElementById('blocks');
var block = document.getElementById('block');
function shine( obj ){
block.style.left = obj.x*51 + 'px';
block.style.top = obj.y*51 + 'px';
var deg = ((obj.dir%4 == 0 && 0) || (obj.dir%4 == 1 && -90) || (obj.dir%4 == 2 && 180) || (obj.dir%4 == 3 && 90)) + 'deg';
block.style.transform = 'rotate(' + deg + ')';
}
//TURN lEFT
function turnLef (obj) {
obj.dir = obj.dir + 1;
return obj;
}
//TURN RIGHT
function turnRig (obj) {
obj.dir = obj.dir + 3;
return obj;
}
//TURN BACK
function turnBac (obj) {
obj.dir = obj.dir + 2;
return obj;
}
//GO
function go (obj){
var dirr = obj.dir % 4;
switch(dirr){
case 0:
if (obj.y > 0){
--obj.y;
}
else {
alert('超过边界')
}
break;
case 1:
if (obj.x > 0){
--obj.x;
}
else {
alert('超过边界')
}
break;
case 2:
if (obj.y < 9){
++obj.y;
}
else {
alert('超过边界')
}
break;
case 3:
if (obj.x < 9){
++obj.x;
}
else {
alert('超过边界')
}
break;
}
return obj;
}
//tra lef
function traLef (obj){
if (obj.x > 0 ){
--obj.x;
}
else {
alert('超过边界')
}
return obj;
}
//tra top
function traTop (obj){
if (obj.y > 0 ){
--obj.y;
}
else {
alert('超过边界')
}
return obj;
}
//tra rig
function traRig (obj){
if (obj.x < 9 ){
++ obj.x;
}
else {
alert('超过边界')
}
return obj;
}
//tra bot
function traBot (obj){
if (obj.y < 9 ){
++obj.y;
}
else {
alert('超过边界')
}
return obj;
}
//mov lef
function movLef (obj){
block.style.transform = 'rotate(-90deg)';
if (obj.x > 0 ){
--obj.x;
}
else {
alert('超过边界')
}
block.style.left = obj.x*51 + 'px';
block.style.top = obj.y*51 + 'px';
obj.dir = 1;
return obj;
}
//mov top
function movTop (obj){
block.style.transform = 'rotate(0deg)';
if (obj.y > 0 ){
--obj.y;
}
else {
alert('超过边界')
}
block.style.left = obj.x*51 + 'px';
block.style.top = obj.y*51 + 'px';
obj.dir = 0;
return obj;
}
//mov rig
function movRig (obj){
block.style.transform = 'rotate(90deg)';
if (obj.x < 9 ){
++ obj.x;
}
else {
alert('超过边界')
}
block.style.left = obj.x*51 + 'px';
block.style.top = obj.y*51 + 'px';
obj.dir = 3;
return obj;
}
//mov bot
function movBot (obj){
block.style.transform = 'rotate(180deg)';
if (obj.y < 9 ){
++obj.y;
}
else {
alert('超过边界')
}
block.style.left = obj.x*51 + 'px';
block.style.top = obj.y*51 + 'px';
obj.dir = 2;
return obj;
}
btn.onclick = function(){
if (order.value.toLowerCase() == "go"){
go(obj);
shine(obj);
}
else if (order.value.toLowerCase() == 'turn lef'){
turnLef (obj);
shine(obj);
}
else if (order.value.toLowerCase() == 'turn rig'){
turnRig (obj);
shine(obj);
}
else if (order.value.toLowerCase() == 'turn bac'){
turnBac (obj);
shine(obj);
}
else if(order.value.toLowerCase() == 'tra lef'){
traLef(obj);
shine(obj);
}
else if(order.value.toLowerCase() == 'mov lef'){
movLef(obj);
}
else if(order.value.toLowerCase() == 'tra top'){
traTop(obj);
shine(obj);
}
else if(order.value.toLowerCase() == 'mov top'){
movTop(obj);
}
else if(order.value.toLowerCase() == 'tra rig'){
traRig(obj);
shine(obj);
}
else if(order.value.toLowerCase() == 'mov rig'){
movRig(obj);
}
else if(order.value.toLowerCase() == 'tra bot'){
traBot(obj);
shine(obj);
}
else if(order.value.toLowerCase() == 'mov bot'){
movBot(obj);
}
else {
alert('请输入正确的指令');
}
}
</script>
</body>
</html>