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

Added a tie detection to the checkWin method + javadoc

parent 2cf8b632
No related branches found
No related tags found
1 merge request!10Updated checkWin method to give back whether the game is finished & updated...
......@@ -56,7 +56,9 @@ public class Controller {
checkWin();
}
/**
* Checks if the game is won or tied
*/
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)) ||
......@@ -78,6 +80,11 @@ 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))))
turnLabel.setText("X won");
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)
turnLabel.setText("Tie");
}
......
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