From 200d92ff4af323bc986cb63973a63b29ad32accd Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 20:22:19 +0100 Subject: [PATCH 01/39] update AppController --- src/main/java/de/hsfulda/onses/App.java | 2 +- .../hsfulda/onses/controllers/AppController.java | 15 ++++++++++----- .../resources/de/hsfulda/onses/views/app.fxml | 7 +++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/App.java b/src/main/java/de/hsfulda/onses/App.java index 8712287..b1e280a 100644 --- a/src/main/java/de/hsfulda/onses/App.java +++ b/src/main/java/de/hsfulda/onses/App.java @@ -9,7 +9,7 @@ import javafx.stage.Stage; public class App extends Application { @Override public void start(Stage stage) throws Exception { - final AppController appController = new AppController(new Game()); + final AppController appController = new AppController(new Game(), stage); stage.setTitle("Onses - Uno Game"); stage.setScene(new Scene(appController.render())); diff --git a/src/main/java/de/hsfulda/onses/controllers/AppController.java b/src/main/java/de/hsfulda/onses/controllers/AppController.java index 5f8a4cc..d1eb5b4 100644 --- a/src/main/java/de/hsfulda/onses/controllers/AppController.java +++ b/src/main/java/de/hsfulda/onses/controllers/AppController.java @@ -1,29 +1,34 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; +import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Game; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.stage.Stage; import java.io.IOException; +import java.util.ArrayList; import java.util.Objects; public class AppController implements Controller { private final Game game; + private final Stage stage; - public AppController(Game game) { + public AppController(Game game, Stage stage) { this.game = game; + this.stage = stage; } @Override public Parent render() throws IOException { - final Parent parent = FXMLLoader.load(Main.class.getResource("views/app.fxml")); + GameController gameController = new GameController(game); + final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/app.fxml"))); Button button = (Button) parent.lookup("#startGameBtn"); - button.setOnAction(e -> { - System.out.println("Pressed"); - }); + return parent; } } diff --git a/src/main/resources/de/hsfulda/onses/views/app.fxml b/src/main/resources/de/hsfulda/onses/views/app.fxml index 7facd52..7205ca5 100644 --- a/src/main/resources/de/hsfulda/onses/views/app.fxml +++ b/src/main/resources/de/hsfulda/onses/views/app.fxml @@ -5,15 +5,14 @@ - - + - From 6d387835571b61f4142859551f4ff37e76b7df21 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 20:36:07 +0100 Subject: [PATCH 05/39] add Card Controller --- .../onses/controllers/CardController.java | 17 +++++++++++++++++ .../resources/de/hsfulda/onses/views/card.fxml | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/main/java/de/hsfulda/onses/controllers/CardController.java create mode 100644 src/main/resources/de/hsfulda/onses/views/card.fxml diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java new file mode 100644 index 0000000..c84835d --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -0,0 +1,17 @@ +package de.hsfulda.onses.controllers; + +import de.hsfulda.onses.Main; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; + +import java.io.IOException; +import java.util.Objects; + +public class CardController implements Controller { + @Override + public Parent render() throws IOException { + final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/card.fxml"))); + + return parent; + } +} diff --git a/src/main/resources/de/hsfulda/onses/views/card.fxml b/src/main/resources/de/hsfulda/onses/views/card.fxml new file mode 100644 index 0000000..fd33361 --- /dev/null +++ b/src/main/resources/de/hsfulda/onses/views/card.fxml @@ -0,0 +1,13 @@ + + + + + + + + + + + From 9da2281eac70d27f210082f8638566c947b34f1a Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:04:32 +0100 Subject: [PATCH 06/39] add setName and Color to CardController --- .../onses/controllers/CardController.java | 20 ++++++++++++++++ .../de/hsfulda/onses/views/card.fxml | 24 ++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java index c84835d..1ef955e 100644 --- a/src/main/java/de/hsfulda/onses/controllers/CardController.java +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -1,17 +1,37 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; +import de.hsfulda.onses.models.Card; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; +import javafx.scene.control.Label; +import javafx.scene.layout.Pane; import java.io.IOException; import java.util.Objects; public class CardController implements Controller { + + private Card card; + + public CardController(Card card) { + this.card = card; + } @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/card.fxml"))); + Pane mainPane = (Pane) parent.lookup("#cardPane"); + + mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: red")); + + final Label cardName = (Label) parent.lookup("#labelName"); + cardName.setText(this.card.getValue().name()); + return parent; } + + private String addStyle(String oldStyle, String newStyle) { + return oldStyle + "; " + newStyle; + } } diff --git a/src/main/resources/de/hsfulda/onses/views/card.fxml b/src/main/resources/de/hsfulda/onses/views/card.fxml index fd33361..4d7f84d 100644 --- a/src/main/resources/de/hsfulda/onses/views/card.fxml +++ b/src/main/resources/de/hsfulda/onses/views/card.fxml @@ -1,13 +1,19 @@ - - - - - - - + + + + + + + + + + + From 2fbfd63b1a8b7ef28bb47a556b54240852f8a5a0 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:23:31 +0100 Subject: [PATCH 07/39] add gameService to Controller Constructor --- src/main/java/de/hsfulda/onses/App.java | 6 ++-- .../onses/controllers/AppController.java | 10 +++--- .../onses/controllers/GameController.java | 14 +++++--- .../de/hsfulda/onses/views/game.fxml | 33 ++++++++++++++++--- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/App.java b/src/main/java/de/hsfulda/onses/App.java index b1e280a..bda0c20 100644 --- a/src/main/java/de/hsfulda/onses/App.java +++ b/src/main/java/de/hsfulda/onses/App.java @@ -1,7 +1,7 @@ package de.hsfulda.onses; import de.hsfulda.onses.controllers.AppController; -import de.hsfulda.onses.models.Game; +import de.hsfulda.onses.services.GameService; import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; @@ -9,9 +9,9 @@ import javafx.stage.Stage; public class App extends Application { @Override public void start(Stage stage) throws Exception { - final AppController appController = new AppController(new Game(), stage); + final AppController appController = new AppController(new GameService(), stage); - stage.setTitle("Onses - Uno Game"); + stage.setTitle("Onses - Uno"); stage.setScene(new Scene(appController.render())); stage.show(); } diff --git a/src/main/java/de/hsfulda/onses/controllers/AppController.java b/src/main/java/de/hsfulda/onses/controllers/AppController.java index 0c1e1c2..d2e0b80 100644 --- a/src/main/java/de/hsfulda/onses/controllers/AppController.java +++ b/src/main/java/de/hsfulda/onses/controllers/AppController.java @@ -2,6 +2,7 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; import de.hsfulda.onses.models.Game; +import de.hsfulda.onses.services.GameService; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; @@ -13,22 +14,23 @@ import java.util.Objects; public class AppController implements Controller { - private final Game game; + private final GameService gameService; private final Stage stage; - public AppController(Game game, Stage stage) { - this.game = game; + public AppController(GameService gameService, Stage stage) { + this.gameService = gameService; this.stage = stage; } @Override public Parent render() throws IOException { - GameController gameController = new GameController(game); + GameController gameController = new GameController(gameService); final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/app.fxml"))); Button button = (Button) parent.lookup("#startGameBtn"); button.setOnAction(e -> { try { stage.setScene(new Scene(gameController.render())); + stage.setTitle("Onses - Uno Game"); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 4eaf803..37f616f 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -1,21 +1,27 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; -import de.hsfulda.onses.models.Game; +import de.hsfulda.onses.models.Card; +import de.hsfulda.onses.services.GameService; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; +import javafx.scene.layout.Pane; import java.io.IOException; import java.util.Objects; public class GameController implements Controller { - private final Game game; - public GameController(Game game) { - this.game = game; + private final GameService gameService; + public GameController(GameService gameService) { + this.gameService = gameService; } @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/game.fxml"))); + CardController lastPlayedCardController = new CardController(new Card().setValue(Card.Value.FIVE).setColor(Card.Color.BLUE)); + + Pane lastPlayedCardPane = (Pane) parent.lookup("#lastPlayedCardPane"); + lastPlayedCardPane.getChildren().add(lastPlayedCardController.render()); return parent; } diff --git a/src/main/resources/de/hsfulda/onses/views/game.fxml b/src/main/resources/de/hsfulda/onses/views/game.fxml index 29510a4..ca16664 100644 --- a/src/main/resources/de/hsfulda/onses/views/game.fxml +++ b/src/main/resources/de/hsfulda/onses/views/game.fxml @@ -1,5 +1,6 @@ + @@ -8,16 +9,38 @@ - + + + - + + + From 73a69a4e6c6b9f61cb09fa2b97476346609ad26d Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:23:59 +0100 Subject: [PATCH 08/39] add Color and Type to CardController --- .../onses/controllers/CardController.java | 30 +++++++++++++++---- .../de/hsfulda/onses/views/card.fxml | 4 +-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java index 1ef955e..0f9ca86 100644 --- a/src/main/java/de/hsfulda/onses/controllers/CardController.java +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -20,12 +20,32 @@ public class CardController implements Controller { @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/card.fxml"))); - Pane mainPane = (Pane) parent.lookup("#cardPane"); - - mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: red")); - + final Pane mainPane = (Pane) parent.lookup("#cardPane"); final Label cardName = (Label) parent.lookup("#labelName"); - cardName.setText(this.card.getValue().name()); + + switch(card.getColor()) { + case RED -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: red")); + case BLUE -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: blue")); + case GREEN -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: green")); + case YELLOW -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: yellow")); + default -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: black")); + } + + switch(card.getValue()) { + case ONE -> cardName.setText("1"); + case TWO -> cardName.setText("2"); + case THREE -> cardName.setText("3"); + case FOUR -> cardName.setText("4"); + case FIVE -> cardName.setText("5"); + case SIX -> cardName.setText("6"); + case SEVEN -> cardName.setText("7"); + case EIGHT -> cardName.setText("8"); + case NINE -> cardName.setText("9"); + case SKIP -> cardName.setText("skip player"); + case CHOOSE -> cardName.setText("wish card"); + case DRAWTWO -> cardName.setText("+2"); + case REVERSE -> cardName.setText("reverse"); + } return parent; diff --git a/src/main/resources/de/hsfulda/onses/views/card.fxml b/src/main/resources/de/hsfulda/onses/views/card.fxml index 4d7f84d..964130d 100644 --- a/src/main/resources/de/hsfulda/onses/views/card.fxml +++ b/src/main/resources/de/hsfulda/onses/views/card.fxml @@ -7,9 +7,9 @@ - From 2a04f23dfe035473c4d148b745074885a189b2c1 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:25:07 +0100 Subject: [PATCH 09/39] refactoring: remove ExampleTest --- src/test/java/de/hsfulda/onses/ExampleTest.java | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/test/java/de/hsfulda/onses/ExampleTest.java diff --git a/src/test/java/de/hsfulda/onses/ExampleTest.java b/src/test/java/de/hsfulda/onses/ExampleTest.java deleted file mode 100644 index d4e9302..0000000 --- a/src/test/java/de/hsfulda/onses/ExampleTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.hsfulda.onses; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - -public class ExampleTest { - @Test - @DisplayName("Example Test") - public void exampleTest() { - int test = 1 + 1; - assertEquals(2, test); - } -} \ No newline at end of file From 58756e16d6eed6f652431e1440413fa0f9ec8916 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:33:14 +0100 Subject: [PATCH 10/39] add Testfx and first Gui Test --- pom.xml | 8 +++++++ src/test/java/de/hsfulda/onses/GuiTest.java | 25 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/java/de/hsfulda/onses/GuiTest.java diff --git a/pom.xml b/pom.xml index 7775e6f..6c76b08 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,14 @@ ${junit.version} test + + org.testfx + testfx-junit5 + 4.0.17 + test + + + diff --git a/src/test/java/de/hsfulda/onses/GuiTest.java b/src/test/java/de/hsfulda/onses/GuiTest.java new file mode 100644 index 0000000..3b93eaa --- /dev/null +++ b/src/test/java/de/hsfulda/onses/GuiTest.java @@ -0,0 +1,25 @@ +package de.hsfulda.onses; + +import javafx.stage.Stage; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.testfx.api.FxAssert; +import org.testfx.framework.junit5.ApplicationTest; +import static org.junit.jupiter.api.Assertions.*; +import static org.testfx.matcher.control.LabeledMatchers.*; + +public class GuiTest extends ApplicationTest { + private Stage stage; + + @Override + public void start(Stage stage) throws Exception { + this.stage = stage; + new App().start(stage); + } + + @Test + @DisplayName("Check Window Title") + void checkWindowsTitle() { + assertEquals("Onses - Uno", stage.getTitle()); + } +} From 75d2e3b9040133975da7ea09cde9c5782fbb8329 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:39:23 +0100 Subject: [PATCH 11/39] change build-project.sh to first build and then test --- build-project.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build-project.sh b/build-project.sh index 1c3edee..c0a8d6f 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,3 +1,5 @@ #!/bin/bash +echo "Build" +mvn clean compile echo "RUN JUnit Tests" -mvn clean test \ No newline at end of file +mvn clean test From 17675a56dfeb6db1fde854b121a5dd9028dd44c7 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:51:45 +0100 Subject: [PATCH 12/39] add Gui test for scene switch --- src/test/java/de/hsfulda/onses/GuiTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GuiTest.java b/src/test/java/de/hsfulda/onses/GuiTest.java index 3b93eaa..845c004 100644 --- a/src/test/java/de/hsfulda/onses/GuiTest.java +++ b/src/test/java/de/hsfulda/onses/GuiTest.java @@ -22,4 +22,11 @@ public class GuiTest extends ApplicationTest { void checkWindowsTitle() { assertEquals("Onses - Uno", stage.getTitle()); } + + @Test + @DisplayName("Check if window Switch is working") + void checkSceneSwitch() { + clickOn("#startGameBtn"); + assertEquals("Onses - Uno Game", stage.getTitle()); + } } From 8a7982aaa5ad16ee61d95a44a62fe3f1787cf433 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:54:00 +0100 Subject: [PATCH 13/39] add PlayerController --- .../onses/controllers/PlayerController.java | 17 +++++++++++++++++ .../de/hsfulda/onses/views/player.fxml | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/main/java/de/hsfulda/onses/controllers/PlayerController.java create mode 100644 src/main/resources/de/hsfulda/onses/views/player.fxml diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java new file mode 100644 index 0000000..7cdb72f --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -0,0 +1,17 @@ +package de.hsfulda.onses.controllers; + +import de.hsfulda.onses.Main; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; + +import java.io.IOException; +import java.util.Objects; + +public class PlayerController implements Controller { + @Override + public Parent render() throws IOException { + final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/player.fxml"))); + + return parent; + } +} diff --git a/src/main/resources/de/hsfulda/onses/views/player.fxml b/src/main/resources/de/hsfulda/onses/views/player.fxml new file mode 100644 index 0000000..fd33361 --- /dev/null +++ b/src/main/resources/de/hsfulda/onses/views/player.fxml @@ -0,0 +1,13 @@ + + + + + + + + + + + From e62424afd58a555bce236747838559b4c7cdef7c Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 22:49:11 +0100 Subject: [PATCH 14/39] add LastPlayedCard PropertyChangeListener --- .../onses/controllers/GameController.java | 22 ++++++++++++++++++- .../de/hsfulda/onses/views/game.fxml | 3 +-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 37f616f..2da4cb3 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -2,9 +2,11 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; import de.hsfulda.onses.models.Card; +import de.hsfulda.onses.models.Game; import de.hsfulda.onses.services.GameService; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; +import javafx.scene.control.Button; import javafx.scene.layout.Pane; import java.io.IOException; @@ -12,15 +14,33 @@ import java.util.Objects; public class GameController implements Controller { private final GameService gameService; + private final Game game; public GameController(GameService gameService) { this.gameService = gameService; + this.game = gameService.getGame(); } @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/game.fxml"))); + final Pane lastPlayedCardPane = (Pane) parent.lookup("#lastPlayedCardPane"); + + final Button playButton = (Button) parent.lookup("#playCardBtn"); CardController lastPlayedCardController = new CardController(new Card().setValue(Card.Value.FIVE).setColor(Card.Color.BLUE)); - Pane lastPlayedCardPane = (Pane) parent.lookup("#lastPlayedCardPane"); + game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> { + lastPlayedCardPane.getChildren().removeAll(); + try { + lastPlayedCardPane.getChildren().add(new CardController((Card) e.getNewValue()).render()); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + }); + + playButton.setOnAction(e -> { + gameService.playCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.ONE)); + }); + + lastPlayedCardPane.getChildren().add(lastPlayedCardController.render()); return parent; diff --git a/src/main/resources/de/hsfulda/onses/views/game.fxml b/src/main/resources/de/hsfulda/onses/views/game.fxml index ca16664..5ca0e51 100644 --- a/src/main/resources/de/hsfulda/onses/views/game.fxml +++ b/src/main/resources/de/hsfulda/onses/views/game.fxml @@ -6,7 +6,6 @@ - - - - - - - - + + - - + +