Skip to content
Snippets Groups Projects
Commit 2cf8b632 authored by Tarek's avatar Tarek
Browse files

Added checkWin method

parent 7c0066de
No related branches found
No related tags found
1 merge request!10Updated checkWin method to give back whether the game is finished & updated...
......@@ -52,8 +52,37 @@ public class Controller {
turnSign = 'X';
turnLabel.setText("X's turn");
}
checkWin();
}
private void checkWin() {
if ((turnSign == 'X') && (
(l00.getText().length() > 0 && l01.getText().length() > 0 && l02.getText().length() > 0 && l00.getText().charAt(0) == l01.getText().charAt(0) && l01.getText().charAt(0) == l02.getText().charAt(0)) ||
(l10.getText().length() > 0 && l11.getText().length() > 0 && l12.getText().length() > 0 && l10.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l12.getText().charAt(0)) ||
(l20.getText().length() > 0 && l21.getText().length() > 0 && l22.getText().length() > 0 && l20.getText().charAt(0) == l21.getText().charAt(0) && l21.getText().charAt(0) == l22.getText().charAt(0)) ||
(l00.getText().length() > 0 && l10.getText().length() > 0 && l20.getText().length() > 0 && l00.getText().charAt(0) == l10.getText().charAt(0) && l10.getText().charAt(0) == l20.getText().charAt(0)) ||
(l01.getText().length() > 0 && l11.getText().length() > 0 && l21.getText().length() > 0 && l01.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l21.getText().charAt(0)) ||
(l02.getText().length() > 0 && l12.getText().length() > 0 && l22.getText().length() > 0 && l02.getText().charAt(0) == l12.getText().charAt(0) && l12.getText().charAt(0) == l22.getText().charAt(0)) ||
(l00.getText().length() > 0 && l11.getText().length() > 0 && l22.getText().length() > 0 && l00.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l22.getText().charAt(0)) ||
(l20.getText().length() > 0 && l11.getText().length() > 0 && l02.getText().length() > 0 && l02.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l20.getText().charAt(0))))
turnLabel.setText("O won");
if ((turnSign == 'O') && (
(l00.getText().length() > 0 && l01.getText().length() > 0 && l02.getText().length() > 0 && l00.getText().charAt(0) == l01.getText().charAt(0) && l01.getText().charAt(0) == l02.getText().charAt(0)) ||
(l10.getText().length() > 0 && l11.getText().length() > 0 && l12.getText().length() > 0 && l10.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l12.getText().charAt(0)) ||
(l20.getText().length() > 0 && l21.getText().length() > 0 && l22.getText().length() > 0 && l20.getText().charAt(0) == l21.getText().charAt(0) && l21.getText().charAt(0) == l22.getText().charAt(0)) ||
(l00.getText().length() > 0 && l10.getText().length() > 0 && l20.getText().length() > 0 && l00.getText().charAt(0) == l10.getText().charAt(0) && l10.getText().charAt(0) == l20.getText().charAt(0)) ||
(l01.getText().length() > 0 && l11.getText().length() > 0 && l21.getText().length() > 0 && l01.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l21.getText().charAt(0)) ||
(l02.getText().length() > 0 && l12.getText().length() > 0 && l22.getText().length() > 0 && l02.getText().charAt(0) == l12.getText().charAt(0) && l12.getText().charAt(0) == l22.getText().charAt(0)) ||
(l00.getText().length() > 0 && l11.getText().length() > 0 && l22.getText().length() > 0 && l00.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l22.getText().charAt(0)) ||
(l20.getText().length() > 0 && l11.getText().length() > 0 && l02.getText().length() > 0 && l02.getText().charAt(0) == l11.getText().charAt(0) && l11.getText().charAt(0) == l20.getText().charAt(0))))
turnLabel.setText("X won");
}
/**
* Makes the button disappear, displays the sign and calls click to check the game state and change the sign
* show the label
......@@ -64,6 +93,7 @@ public class Controller {
l00.setText("" + turnSign);
b00.setVisible(false);
click(row, column);
}
/**
* Makes the button disappear, displays the sign and calls click to check the game state and change the sign
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment