From 8e12396bfd101c5865e3fdefae11f2bee7b65974 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Thu, 26 Nov 2020 18:43:03 +0300 Subject: [PATCH] lab-06: Solution idea --- lab-06/src/GamePane.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lab-06/src/GamePane.java b/lab-06/src/GamePane.java index f77e84c..4bd88ec 100644 --- a/lab-06/src/GamePane.java +++ b/lab-06/src/GamePane.java @@ -12,6 +12,10 @@ import javafx.stage.Stage; public class GamePane extends GridPane implements EventHandler { + /* + Another solution to getting the state of Button(Box) is to extend Button and + add member (Player playedBy) + */ private Button btnExit; private Button btnRestart; private Button[][] btnGame; @@ -44,10 +48,11 @@ public class GamePane extends GridPane implements EventHandler { public void restart() { System.out.println("Starting new game"); - for (int i = 0; i < btnGame.length; i++) { + //Row + for (Button[] buttons : btnGame) { //Element - for (int j = 0; j < btnGame[i].length; j++) { - btnGame[i][j].setText("-"); + for (Button button : buttons) { + button.setText("-"); } } done = false; @@ -72,7 +77,7 @@ public class GamePane extends GridPane implements EventHandler { } } - private void checkWin() throws Exception { + private void checkWin() { //check horizontal for (int i = 0; i < 3; i++){ int xCount = 0; @@ -133,7 +138,7 @@ public class GamePane extends GridPane implements EventHandler { } } - private void announceWin(Player player) throws Exception { + private void announceWin(Player player) { done = true; WinDialog w = new WinDialog(player); w.start(new Stage()); @@ -189,7 +194,7 @@ public class GamePane extends GridPane implements EventHandler { } @Override - public void start(Stage stage) throws Exception { + public void start(Stage stage) { VBox root = new VBox(); root.setAlignment(Pos.CENTER); root.setPadding(new Insets(15,15,15,15));