1

我正在制作一个迷宫游戏,并且我正在使用一张桌子进行迷宫布局。角色移动完美,但它穿过墙壁对于墙壁,我正在使用类似的东西 <td style="border-right:10px solid #000000;">。它有效,但角色几乎是一个幽灵。有没有办法让角色在到达 a 时停止border?我的迷宫位于http://thomaswd.com/maze

4

2 回答 2

1

保存老鼠所在的单元格,然后在请求移动时,检查当前单元格是否在用户试图去的方向上有边框,或者未来的单元格是否有相反方向的边框,然后中止如果确实如此,请移动请求。例如,如果用户单击右键,则检查当前单元格是否有右边框,或者老鼠要移动到的单元格是否有左边框。

于 2013-02-15T19:47:03.557 回答
1

hasClass由于您使用的是 jQuery,并且墙壁由单元格上的类显示,您可以使用 jQuery 的方法检查您尝试移动到的单元格是否有墙壁。

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);
}

我希望这有帮助

于 2013-02-15T19:53:55.890 回答