I am creating a Tic Tac Toe program, but I am getting a compile error that i can't figure out why..I am sure its a dumb reason. Any help will be greatly appreciated. If you figure out the reason for the compile error, could you also check the rest to make sure I did it right. Please Help. Assignment due soon. I put a comment next to the code with the error.
Here is my Class:
public class PlayTicTacToe { //instance variables private String[][] p;//2d array for the board private String player; //Constructor public PlayTicTacToe() { String p[][]=new String [3][3]; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { p[i][j]=" "; } } } // Accessor methods for the data public String getPlayer() { return player; } private int wonDiagonal() { return 1; } private int wonStraightLines() { for (int i=0;i<3;i++) { int play1=0; int play2=0; for (int j=0;j<3;j++) { if (p[i][j].equals("")) { } else if (p[i][j].equalsIgnoreCase("X")) { play1++; } else { play2++; } } if(play1==3) { return 1; } else if (play2==3) { return 2; } else { } } for (int j=0;j<3;j++) { int play1=0; int play2=0; for (int i=0;i<3;i++) { if (p[j][i].equals("")) { } else if (p[j][i].equalsIgnoreCase("X")) { play1++; } else { play2++; } } if(play1==3) { return 1; } else if (play2==3) { return 2; } else { } } return 0; } public int win() { if (wonDiagonal()|| wonStraightLines()) //Compile error is here!!!! Says: bad operand types for binary operator '||', first type: int; second type: int { return true; } else { return false; } } public void drawBoard() { System.out.println("|-----|"); System.out.println("|"+p[0][0]+"|"+p[0][1]+"|"+p[0][2]+"|"); System.out.println("|-----|"); System.out.println("|"+p[1][0]+"|"+p[1][1]+"|"+p[1][2]+"|"); System.out.println("|-----|"); System.out.println("|"+p[2][0]+"|"+p[2][1]+"|"+p[2][2]+"|"); System.out.println("|-----|"); } public void play() { Scanner scan=new Scanner(System.in); System.out.println("Player 1 choose a row and column."); int p1row=scan.nextInt(); int p1col=scan.nextInt(); p[p1row][p1col]="X"; System.out.println("Player 2 enter your move."); int p2row=scan.nextInt(); int p2col=scan.nextInt(); p[p2row][p2col]="O"; } } import java.util.Scanner; //This is my Runner. public class Runner { public static void main(String[] args) { Scanner in = new Scanner(System.in); PlayTicTacToe p = new PlayTicTacToe(); p.drawBoard(); while (!p.win()) { p.play(); p.drawBoard(); } System.out.println("Player " + p.getPlayer() + " wins!"); } }