I have a multi class program in which I'm trying to make winning conditions for. However when I attempt to compare the 2D array that contains an object, with another object of the same kind.
Here is a sample, I've tested the bare bones and the method does work, it's the if statements that do not, any help is very much appreciated.
(Yes I converted them to strings with the quotations, however the statement doesn't work either way)
public boolean winner()//Checks to see if someone has won.
{
XO x = new XO("X");//creates the objects to mimic the players
XO o = new XO("O");
if((board [0][0]+"").equals(o+"") && (board [0][1]+"").equals(o+"") && (board [0][2]+"").equals(o+""))//top horizontal row
{
return true;
}
else if((board [0][1]+"").equals(o+"") && (board [1][1]+"").equals(o+"") && (board [2][1]+"").equals(o+""))//mid horizontal row
{
return true;
}
else if((board [0][2]+"").equals(o+"") && (board [1][2]+"").equals(o+"") && (board [2][2]+"").equals(o+""))//bottom horizontal row
{
return true;
}
else if((board [0][0]+"").equals(o+"") && (board [0][1]+"").equals(o+"") && (board [0][2]+"").equals(o+""))//left vertical row
{
return true;
}
else if((board [1][0]+"").equals(o+"") && (board [1][1]+"").equals(o+"") && (board [1][2]+"").equals(o+""))//mid vertical row
{
return true;
}
else if((board [2][0]+"").equals(o+"") && (board [2][1]+"").equals(o+"") && (board [2][2]+"").equals(o+""))//right vertical row
{
return true;
}
else if((board [0][0]+"").equals(o+"") && (board [1][1]+"").equals(o+"") && (board [2][2]+"").equals(o+""))//declining diagonal row
{
return true;
}
else if((board [2][0]+"").equals(o+"") && (board [1][1]+"").equals(o+"") && (board [0][2]+"").equals(o+""))//rising diagonal row
{
return true;// respectively the same for the lines below
}
//Above O wins, Below X wins
else if((board [0][0]+"").equals(x+"") && (board [0][1]+"").equals(x+"") && (board [0][2]+"").equals(x+""))//top horizontal row
{
return true;
}
else if((board [0][1]+"").equals(x+"") && (board [1][1]+"").equals(x+"") && (board [2][1]+"").equals(x+""))//mid horizontal row
{
return true;
}
else if((board [0][2]+"").equals(x+"") && (board [1][2]+"").equals(x+"") && (board [2][2]+"").equals(x+""))//bottom horizontal row
{
return true;
}
else if((board [0][0]+"").equals(x+"") && (board [0][1]+"").equals(x+"") && (board [0][2]+"").equals(x+""))//left vertical row
{
return true;
}
else if((board [1][0]+"").equals(x+"") && (board [1][1]+"").equals(x+"") && (board [1][2]+"").equals(x+""))//mid vertical row
{
return true;
}
else if((board [2][0]+"").equals(x+"") && (board [2][1]+"").equals(x+"") && (board [2][2]+"").equals(x+""))//right vertical row
{
return true;
}
else if((board [0][0]+"").equals(x+"") && (board [1][1]+"").equals(x+"") && (board [2][2]+"").equals(x+""))//declining diagonal row
{
return true;
}
else if((board [2][0]+"").equals(x+"") && (board [1][1]+"").equals(x+"") && (board [0][2]+"").equals(x+""))//rising diagonal row
{
return true;// respectively the same for the lines below
}
else//if none of these are fulfilled
return false;}