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

Updated checkWin method to give back whether the game is finished & updated...

Updated checkWin method to give back whether the game is finished & updated the click method to use that information to show the new game pop up
parent 3b77a20a
No related branches found
No related tags found
1 merge request!10Updated checkWin method to give back whether the game is finished & updated...
......@@ -51,10 +51,6 @@ public class Controller {
*/
private Stage stage;
/**
* gameBoard access
*/
private GameBoard gameBoard = new GameBoard();
/**
* turns the player sign and checks the game state
......@@ -62,8 +58,7 @@ public class Controller {
* @param column the column of the tile
*/
private void click(int row, int column) throws IOException {
// Todo: Check for win
if(gameBoard.winCheck() ==1 || gameBoard.winCheck() == 2)
if(checkWin())
{
stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
......@@ -97,13 +92,12 @@ public class Controller {
}
}
checkWin();
}
/**
* Checks if the game is won or tied
*/
private void checkWin() {
private boolean checkWin() {
if (((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)) ||
......@@ -114,17 +108,20 @@ public class Controller {
(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)))) {
if (turnSign == 'X')
turnLabel.setText("O won");
else
turnLabel.setText("X won");
return;
else
turnLabel.setText("O won");
return true;
}
if (l00.getText().length() > 0 && l01.getText().length() > 0 && l02.getText().length() > 0 &&
l10.getText().length() > 0 && l11.getText().length() > 0 && l12.getText().length() > 0 &&
l20.getText().length() > 0 && l21.getText().length() > 0 && l22.getText().length() > 0)
l20.getText().length() > 0 && l21.getText().length() > 0 && l22.getText().length() > 0) {
turnLabel.setText("Tie");
return true;
}
return false;
}
......
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