This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                6年前关闭。
            
                    
我正在制作一个迷宫游戏,并且正在使用一张桌子作为迷宫布局。角色可以完美移动,但可以穿过墙壁。对于墙壁,我使用的是<td style="border-right:10px solid #000000;">之类的东西。它可以工作,但是角色几乎是个鬼。有没有办法使字符在到达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/

10-12 15:43