I am building a game of tic tac toe and I am getting this warning on my method.
The code is kinda complex and repeating an if statement, I do not know if there is a way around this warning. any kind of help would be appreciated.
public void checkWin() {
if ((board[0] == board[1]) && (board[1] == board[2]) && board[2] != 0) {
win(0);
}
if ((board[3] == board[4]) && (board[4] == board[5]) && board[5] != 0) {
win(5);
}
if ((board[6] == board[7]) && (board[7] == board[8]) && board[8] != 0) {
win(8);
}
//----------------------------------------------------------------------
if ((board[0] == board[3]) && (board[3] == board[6]) && board[6] != 0) {
win(6);
}
if ((board[1] == board[4]) && (board[4] == board[7]) && board[7] != 0) {
win(7);
}
if ((board[2] == board[5]) && (board[5] == board[8]) && board[8] != 0) {
win(8);
}
//---------------------------------------------------------------------
if ((board[0] == board[4]) && (board[4] == board[8]) && board[8] != 0) {
win(8);
}
if ((board[6] == board[4]) && (board[4] == board[2]) && board[2] != 0) {
win(2);
}
for (int i = 0; i < board.length; i++) {
if (board[i] == 0) return;
}
if (!won) draw();
}