【ife】任务三十四:听指令的小方块(二)
来源:互联网 发布:梦幻西游 知乎 编辑:程序博客网 时间:2024/04/27 19:00
document.getElementsByTagName("button")[0].onclick = function() {var value = document.getElementById("command").value;switch(value) {case "GO": go(); break;case "TUN LEF": tun_lef(); break;case "TUN RIG": tun_rig(); break;case "TUN BAC": tun_bac(); break;case "TRA LEF": tra_lef(); break;case "TRA TOP": tra_top(); break;case "TRA RIG": tra_rig(); break;case "TRA BOT": tra_bot(); break;case "MOV LEF": mov_lef(); break;case "MOV TOP": mov_top(); break;case "MOV RIG": mov_rig(); break;case "MOV BOT": mov_bot(); break;}}function go() {var square = document.getElementById("square"); var deg = square.style.transform.slice(7, -4);var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);switch(deg) {case "0":if (x == 0)alert("已到最上方!");else {x--;document.getElementById("box" + x + y).appendChild(square);}break;case "90":if (y == 9)alert("已到最右方!");else {y++;document.getElementById("box" + x + y).appendChild(square);}break;case "180":if (x == 9)alert("已到最下方!");else {x++;document.getElementById("box" + x + y).appendChild(square);}break;case "270":if (y == 0)alert("已到最左方!");else {y--;document.getElementById("box" + x + y).appendChild(square);}break;}}function tun_lef() {var square = document.getElementById("square");var deg = (square.style.transform.slice(7, -4) - '0' + 270) % 360;square.style.transform = "rotate("+ deg +"deg)";}function tun_rig() {var square = document.getElementById("square");var deg = (square.style.transform.slice(7, -4) - '0' + 90) % 360;square.style.transform = "rotate("+ deg +"deg)";}function tun_bac() {var square = document.getElementById("square");var deg = (square.style.transform.slice(7, -4) - '0' + 180) % 360;square.style.transform = "rotate("+ deg +"deg)";}function tra_lef() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);if (y == 0)alert("已到最左方!");else {y--;document.getElementById("box" + x + y).appendChild(square);}}function tra_top() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);if (x == 0)alert("已到最上方!");else {x--;document.getElementById("box" + x + y).appendChild(square);}}function tra_rig() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);if (y == 9)alert("已到最右方!");else {y++;document.getElementById("box" + x + y).appendChild(square);}}function tra_bot() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);if (x == 9)alert("已到最下方!");else {x++;document.getElementById("box" + x + y).appendChild(square);}}function mov_lef() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);square.style.transform = "rotate(270deg)";if (y == 0)alert("已到最左方!");else {y--;document.getElementById("box" + x + y).appendChild(square);}}function mov_top() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);square.style.transform = "rotate(0deg)";if (x == 0)alert("已到最上方!");else {x--;document.getElementById("box" + x + y).appendChild(square);}}function mov_rig() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);square.style.transform = "rotate(90deg)";if (y == 9)alert("已到最右方!");else {y++;document.getElementById("box" + x + y).appendChild(square);}}function mov_bot() {var square = document.getElementById("square"); var x = square.parentNode.getAttribute("id").slice(3, 4);var y = square.parentNode.getAttribute("id").slice(4, 5);square.style.transform = "rotate(180deg)";if (x == 9)alert("已到最下方!");else {x++;document.getElementById("box" + x + y).appendChild(square);}}
1 0
- 【ife】任务三十四:听指令的小方块(二)
- 【ife】任务三十三:听指令的小方块(一)
- 【ife】任务三十五:听指令的小方块(三)
- 【ife】任务三十六:听指令的小方块(四)
- 听指令的小方块
- 听指令的小方块(一)总结
- 百度前端学院任务:听指令的小方块的实现
- 【ife】任务二十三:JavaScript和树(二)
- 【ife】任务二十七:行星与飞船(二)
- 【ife】任务二十九:表单(一)单个表单项的检验
- 【ife】任务三十:表单(二)多个表单项的动态校验
- 基于java的俄罗斯小方块(二),code,code...
- 【ife】任务十四:零基础JavaScript编码(二)
- 【ife】任务十九:基础JavaScript练习(二)
- 【ife】任务二十:基础JavaScript练习(三)
- 【ife】任务二十一:基础JavaScript练习(四)
- 【ife】任务二十二:JavaScript和树(一)
- 【ife】任务二十四:JavaScript和树(三)
- CSC压缩矩阵
- shell学习--变量
- 快捷键-netbeans
- php那些容易出错的题型
- Android studio SO 导入巨坑!!必须将so文件放入jniLibs 目录下
- 【ife】任务三十四:听指令的小方块(二)
- shape用法
- C#中的<%# %>,<%= %>,<% %>
- sql语句给数据库表新增字段
- O - Bone Collector
- 微信支付code=-1的问题解决(坑之下划线)
- 背景图片修改大小
- web导航代码库
- 【C++解题报告】Hello, World!