<分区>
我正在制作一个迷宫游戏,我正在使用一个表格来进行迷宫布局。 Angular 色移动完美,但它穿过墙壁对于墙壁,我使用类似 <td style="border-right:10px solid #000000;">
的东西.它有效,但这个 Angular 色几乎是一个幽灵。有没有办法让 Angular 色在到达 border
时停止? ?我的迷宫在 http://thomaswd.com/maze .
<分区>
我正在制作一个迷宫游戏,我正在使用一个表格来进行迷宫布局。 Angular 色移动完美,但它穿过墙壁对于墙壁,我使用类似 <td style="border-right:10px solid #000000;">
的东西.它有效,但这个 Angular 色几乎是一个幽灵。有没有办法让 Angular 色在到达 border
时停止? ?我的迷宫在 http://thomaswd.com/maze .
最佳答案
由于您使用的是 jQuery,并且墙壁由单元格上的类显示,因此您可以使用 jQuery 的 hasClass
方法检查您尝试移入的单元格是否有墙。
function up() {
//check if the cell has a border on the bottom
if ($("#td" + (algernon - 8)).hasClass('b')) return;
$("td").css("background","transparent");
algernon -= 8;
setTimeout("refresh()", 0);
}
function down() {
//check if the cell has a border on the top
if ($("#td" + (algernon + 8)).hasClass('t')) return;
$("td").css("background","transparent");
algernon += 8;
setTimeout("refresh()", 0);
}
function leftclick() {
//check if the cell has a border on the right
if ($("#td" + (algernon - 1)).hasClass('r')) return;
$("td").css("background","transparent");
algernon -= 1;
setTimeout("refresh()", 0);
}
function rightclick() {
//check if the cell has a border on the left
if ($("#td" + (algernon + 1)).hasClass('l')) return;
$("td").css("background","transparent");
algernon += 1;
setTimeout("refresh()", 0);
}
希望对你有帮助
关于javascript - 在迷宫墙上停止角色 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14902019/