Originally Posted by
GregBrannon
You can ignore the advice given or take it. If you don't understand what someone is trying to tell you, then please ask for clarification.
okay.
--- Update ---
Originally Posted by
copeg
I used the equals() method, then I had some nullpointer error which i fixed in the constructor. Thanks
public class Board implements BoardUI
{
private String[][] board = new String[3][3];
private String winner = "No player";
private int sentinel = 0;
public Board()
{
board[0][0] = "";
board[0][1] ="";
board[0][2] = "";
board[1][0] = "";
board[1][1] = "";
board[1][2] = "";
board[2][0] = "";
board[2][1] = "";
board[2][2] = "";
}
public String getValue(int position)
{
if(position ==1){
return board[0][0];
}
if(position ==2){
return board[0][1];
}
if(position ==3){
return board[0][2];
}
if(position ==4){
return board[1][0];
}
if(position ==5){
return board[1][1];
}
if(position ==6){
return board[1][2];
}
if(position ==7){
return board[2][0];
}
if(position ==8){
return board[2][1];
}
if(position ==9){
return board[2][2];
}
else{
return "";
}
}
public int getSentinel()
{
return sentinel;
}
public void assignMove(String value, int position)
{
if(position ==1){
board[0][0] = value;
}
if(position ==2){
board[0][1] = value;
}
if(position ==3){
board[0][2] = value;
}
if(position ==4){
board[1][0] = value;
}
if(position ==5){
board[1][1] = value;
}
if(position ==6){
board[1][2] = value;
}
if(position ==7){
board[2][0] = value;
}
if(position ==8){
board[2][1] = value;
}
if(position ==9){
board[2][2] = value;
}
}
public String printWinner()
{
return winner;
}
public void checkForWin()
{
if
(
((board[0][0].equals("x")) &&(board[0][1].equals("x")) && (board[0][2].equals("x"))) ||
((board[1][0].equals("x")) &&(board[1][1].equals("x")) && (board[1][2].equals("x"))) ||
((board[2][0].equals("x")) &&(board[2][1].equals("x")) && (board[2][2].equals("x"))) ||
((board[0][0].equals("x")) &&(board[1][0].equals("x")) && (board[2][0].equals("x"))) ||
((board[1][0].equals("x")) &&(board[1][1].equals("x")) && (board[2][1].equals("x"))) ||
((board[0][2]=="x") &&(board[1][2]=="x") && (board[2][2]=="x")) ||
((board[0][0].equals("x")) &&(board[1][1].equals("x")) && (board[2][2].equals("x"))) ||
((board[0][2].equals("x")) &&(board[1][1].equals("x")) && (board[2][0].equals("x")))
)
{
winner = "Player 1";
sentinel= 1;
}
if
(
((board[0][0].equals("o")) &&(board[0][1].equals("o")) && (board[0][2].equals("o"))) ||
((board[1][0].equals("o")) &&(board[1][1].equals("o")) && (board[1][2].equals("o"))) ||
((board[2][0].equals("o")) &&(board[2][1].equals("o")) && (board[2][2].equals("o"))) ||
((board[0][0].equals("o")) &&(board[1][0].equals("o")) && (board[2][0].equals("o"))) ||
((board[1][0].equals("o")) &&(board[1][1].equals("o")) && (board[2][1].equals("o"))) ||
((board[0][2].equals("o")) &&(board[1][2].equals("o")) && (board[2][2].equals("o"))) ||
((board[0][0].equals("o")) &&(board[1][1].equals("o")) && (board[2][2].equals("o"))) ||
((board[0][2].equals("o")) &&(board[1][1].equals("o")) && (board[2][0].equals("o")))
)
{
winner = "Player 2";
sentinel= 1;
}
}
}