为什么这个javascript代码不起作用? [英] Why this javascript code doesn't work?

查看:79
本文介绍了为什么这个javascript代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好,我正在开发Reversi(奥赛罗)游戏,我遇到了一个场景,我将在板上发现空位,我写了(最后),但这并不准确。



请访问 http://jsfiddle.net/huL3qoa3/ [ ^ ]看到它。



点击在董事会的任何地方,都会显示一个警告,如果该位置是否为空,它运行不正常,有什么问题?



请帮助我。



感谢宝贵的时间。



TIA。

Hello everybody,I'was developing Reversi(Othello) Game,I faced a scenario which i was going to detect empty places on the board,i wrote it(finally) but it's not exact.

please visit http://jsfiddle.net/huL3qoa3/[^] to see it.

when you click anywhere on the board,an alert will be shown that,if the position is empty or not,it is not working well,what's the problem?

please help me.

thanks for your valuable time.

TIA.

推荐答案

可能是因为你的布尔返回被反转了?我将其更改为以下内容并且能够使其正常工作。我使用术语工作非常宽松,因为我相信你在代码中还有其他一些问题。



probably because you have your boolean returns reversed?? I changed it to the following and was able to get it "working". I am using the term "working" very loose because I believe you have some other problems in the code.

function IsEmpty(x, y) {
    var Temp1 = document.getElementsByTagName("img");
    var i;

    var xx, yy;
    xx = (x * 50) - 50 + ("px");
    yy = (y * 50) - 50 + ("px");

    for (i = 0; i < Temp1.length; i++) {
        if (Temp1[i].style.left != xx && Temp1[i].style.top != yy) {
            Empty = false;
        } else {
            Empty = true;
            break;
        }
    }

    return Empty;
}


我只是通过改变&&到||在以下函数中:



I solved it myself simply by changing && to || in following function:

function IsEmpty(x,y)
{
var Temp1=document.getElementsByTagName("img");
var i;

var xx,yy;
xx=(x*50)-50+("px");
yy=(y*50)-50+("px");

for(i=0;i<Temp1.length;i++)
{

if(Temp1[i].style.left!=xx || Temp1[i].style.top!=yy )
{
Empty=true;
}
else
{
Empty=false;
break;
}


}


这篇关于为什么这个javascript代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆