Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.
Posted
Updated 11-Sep-14 5:37am
v2

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.

JavaScript
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;
}
 
Share this answer
 
I solved it myself simply by changing && to || in following function:

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


}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900