pwnedjoo
04-26-2005, 01:54 PM
I have put the following if statement into the mouse released event handler in a program I am working on,
if (frogs[0].frogsLocator == r6Pos || frogs[0].frogsLocator == r8Pos &&
frogs[1].frogsLocator == r8Pos || frogs[1].frogsLocator == r6Pos &&
frogs[2].frogsLocator == r1Pos || frogs[2].frogsLocator == r1Pos &&
frogs[3].frogsLocator == r3Pos || frogs[3].frogsLocator == r3Pos )
{
System.out.println("Winnar \r\n");
}
it is supposed to check the positions of all the points at which my frogs are sitting and then carry out the print line statement, however it doesn't. The or staement is necessary as in the puzzle the frog can be in either one of two places.
I have tried diagnosing the problem with a series of system outs and the co-ordinates are being updated for each move and do match when the puzzle is completed however the if statement is either
a) boloney
or
b) not being reached
i have tried variations on this, as before the if statement there are a series of "if, else if's" but no matter where i put it it has no effect;
* A sample of 1 of 8 preceding if statements *
if (originalPos == r1Pos)
{
if (newPos.x >= r5.x && newPos.y >= r5.y && newPos.x <= r5.x + 100 && newPos.y <= r5.y + 100 && r5PosOccupied == false)
{
frogs[selectedindex].snapFrog(r5Pos);
r5PosOccupied = true;
r1PosOccupied = false;
frogs[selectedindex].getlocation(r5Pos);
repaint();
}
else if (newPos.x >= r7.x && newPos.y >= r7.y && newPos.x <= r7.x + 100 && newPos.y <= r7.y + 100 && r7PosOccupied == false)
{
frogs[selectedindex].snapFrog(r7Pos);
r7PosOccupied = true;
r1PosOccupied = false;
frogs[selectedindex].getlocation(r7Pos);
repaint();
}
else
{
frogs[selectedindex].snapFrog(r1Pos);
repaint();
}
}
any ideas anyone :0
if (frogs[0].frogsLocator == r6Pos || frogs[0].frogsLocator == r8Pos &&
frogs[1].frogsLocator == r8Pos || frogs[1].frogsLocator == r6Pos &&
frogs[2].frogsLocator == r1Pos || frogs[2].frogsLocator == r1Pos &&
frogs[3].frogsLocator == r3Pos || frogs[3].frogsLocator == r3Pos )
{
System.out.println("Winnar \r\n");
}
it is supposed to check the positions of all the points at which my frogs are sitting and then carry out the print line statement, however it doesn't. The or staement is necessary as in the puzzle the frog can be in either one of two places.
I have tried diagnosing the problem with a series of system outs and the co-ordinates are being updated for each move and do match when the puzzle is completed however the if statement is either
a) boloney
or
b) not being reached
i have tried variations on this, as before the if statement there are a series of "if, else if's" but no matter where i put it it has no effect;
* A sample of 1 of 8 preceding if statements *
if (originalPos == r1Pos)
{
if (newPos.x >= r5.x && newPos.y >= r5.y && newPos.x <= r5.x + 100 && newPos.y <= r5.y + 100 && r5PosOccupied == false)
{
frogs[selectedindex].snapFrog(r5Pos);
r5PosOccupied = true;
r1PosOccupied = false;
frogs[selectedindex].getlocation(r5Pos);
repaint();
}
else if (newPos.x >= r7.x && newPos.y >= r7.y && newPos.x <= r7.x + 100 && newPos.y <= r7.y + 100 && r7PosOccupied == false)
{
frogs[selectedindex].snapFrog(r7Pos);
r7PosOccupied = true;
r1PosOccupied = false;
frogs[selectedindex].getlocation(r7Pos);
repaint();
}
else
{
frogs[selectedindex].snapFrog(r1Pos);
repaint();
}
}
any ideas anyone :0