From 9b39a8f99f336cf4e414ae6a0af423abc70f7aae Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 7 Feb 2024 20:52:13 +0100 Subject: [PATCH 01/26] show cards face down if the player is enemy --- .../onses/controllers/CardController.java | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java index 0f9ca86..eeffa39 100644 --- a/src/main/java/de/hsfulda/onses/controllers/CardController.java +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -23,28 +23,34 @@ public class CardController implements Controller { final Pane mainPane = (Pane) parent.lookup("#cardPane"); final Label cardName = (Label) parent.lookup("#labelName"); - 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")); + if(!card.isFacedown()) { + 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"); + if(card.isFacedown()) { + cardName.setText("Card"); + } else { + 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"); + } } From 336510435d8b1104325ae3837babe3903e10e712 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 7 Feb 2024 21:06:36 +0100 Subject: [PATCH 02/26] add card selected --- src/main/java/de/hsfulda/onses/models/Card.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Card.java b/src/main/java/de/hsfulda/onses/models/Card.java index 2dbc3d5..568851f 100644 --- a/src/main/java/de/hsfulda/onses/models/Card.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -7,11 +7,14 @@ public class Card { public final static String PROPERTY_COLOR = "color"; public final static String PROPERTY_VALUE = "value"; + public final static String PROPERTY_SELECTED = "selected"; + protected PropertyChangeSupport listeners; private Color color; private Value value; private boolean facedown = false; + private boolean selected; public enum Color { RED, BLUE, GREEN, YELLOW, BLACK; @@ -51,6 +54,17 @@ public class Card { return this; } + public boolean isSelected() { + return selected; + } + + public Card setSelected(boolean selected) { + final boolean oldValue = this.selected; + this.selected = selected; + this.firePropertyChange(PROPERTY_SELECTED, oldValue, selected); + return this; + } + public PropertyChangeSupport listeners() { if(this.listeners == null) { this.listeners = new PropertyChangeSupport(this); From 41c58743422ee4c1e24923635f47ec5b15276854 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 7 Feb 2024 21:06:50 +0100 Subject: [PATCH 03/26] add card test --- src/test/java/de/hsfulda/onses/CardTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/CardTest.java b/src/test/java/de/hsfulda/onses/CardTest.java index d7ea092..57d5060 100644 --- a/src/test/java/de/hsfulda/onses/CardTest.java +++ b/src/test/java/de/hsfulda/onses/CardTest.java @@ -87,4 +87,14 @@ public class CardTest { } + @Test + @DisplayName("test if card is selected") + void testIfCardIsSelected() { + Card card = new Card().setSelected(true); + + assertTrue(card.isSelected()); + card.setSelected(false); + assertFalse(card.isSelected()); + } + } \ No newline at end of file From ff62cd9f40dc43d982cf44332960a1ec22934622 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 7 Feb 2024 21:07:44 +0100 Subject: [PATCH 04/26] add property change support for currentCard --- src/main/java/de/hsfulda/onses/models/Player.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 9dbfa14..15dd5f7 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -7,6 +7,7 @@ import java.util.ArrayList; public class Player { public final static String PROPERTY_PLAYER_DECK = "playerDeck"; + public final static String PROPERTY_CURRENT_CARD = "currentCard"; protected PropertyChangeSupport listeners; @@ -74,7 +75,9 @@ public class Player { } public Player setCurrentCard(Card currentCard) { + final Card oldCard = this.currentCard; this.currentCard = currentCard; + this.firePropertyChange(PROPERTY_CURRENT_CARD, oldCard, currentCard); return this; } From f5b7c26cf7fe413fa6202621b5489fc0457f1e17 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 7 Feb 2024 21:23:43 +0100 Subject: [PATCH 05/26] add selected Card player --- .../onses/controllers/CardController.java | 28 +++++++++++++++++-- .../onses/controllers/GameController.java | 4 +-- .../onses/controllers/PlayerController.java | 4 +-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java index eeffa39..5e2aef6 100644 --- a/src/main/java/de/hsfulda/onses/controllers/CardController.java +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -2,6 +2,7 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; import de.hsfulda.onses.models.Card; +import de.hsfulda.onses.models.Player; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.control.Label; @@ -12,10 +13,12 @@ import java.util.Objects; public class CardController implements Controller { - private Card card; + private final Card card; + private final Player player; - public CardController(Card card) { + public CardController(Card card, Player player) { this.card = card; + this.player = player; } @Override public Parent render() throws IOException { @@ -53,6 +56,27 @@ public class CardController implements Controller { } } + if(player != null && !player.isEnemy()) { + mainPane.setOnMousePressed(e -> { + Card oldCard = player.getCurrentCard(); + if(oldCard != null) { + oldCard.setSelected(false); + } + player.setCurrentCard(card); + card.setSelected(true); + }); + } + + card.listeners().addPropertyChangeListener(Card.PROPERTY_SELECTED, e -> { + boolean oldValue = (boolean) e.getOldValue(); + if(oldValue) { + mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-border-color: black")); + } else { + mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-border-color: pink")); + } + + }); + return parent; } diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 11ae0ae..70cc61b 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -27,14 +27,14 @@ public class GameController implements Controller { final Pane playerPane = (Pane) parent.lookup("#playerPane"); final Button playButton = (Button) parent.lookup("#playCardBtn"); - CardController lastPlayedCardController = new CardController(game.getLastPlayedCard()); + CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null); PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst()); PlayerController enemyController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getLast()); game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> { lastPlayedCardPane.getChildren().removeAll(); try { - lastPlayedCardPane.getChildren().add(new CardController((Card) e.getNewValue()).render()); + lastPlayedCardPane.getChildren().add(new CardController((Card) e.getNewValue(), null).render()); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java index 1757520..5a11d1c 100644 --- a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -26,14 +26,14 @@ public class PlayerController implements Controller { final HBox cards = (HBox) parent.lookup("#cardsHBox"); for(Card card : player.getPlayerDeck()) { - cards.getChildren().add(new CardController(card).render()); + cards.getChildren().add(new CardController(card, player).render()); } player.listeners().addPropertyChangeListener(Player.PROPERTY_PLAYER_DECK, e -> { cards.getChildren().clear(); for(Card card : player.getPlayerDeck()) { try { - cards.getChildren().add(new CardController(card).render()); + cards.getChildren().add(new CardController(card, player).render()); } catch (IOException ex) { throw new RuntimeException(ex); } From 73eb148e5a0fc212d06ef6c9a6bc2138fdbce7c0 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:11:08 +0100 Subject: [PATCH 06/26] refactoring: add player to card --- src/main/java/de/hsfulda/onses/models/Card.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Card.java b/src/main/java/de/hsfulda/onses/models/Card.java index 568851f..ab2a1a9 100644 --- a/src/main/java/de/hsfulda/onses/models/Card.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -16,6 +16,8 @@ public class Card { private boolean facedown = false; private boolean selected; + private Player player; + public enum Color { RED, BLUE, GREEN, YELLOW, BLACK; }; @@ -65,6 +67,15 @@ public class Card { return this; } + public Player getPlayer() { + return player; + } + + public Card setPlayer(Player player) { + this.player = player; + return this; + } + public PropertyChangeSupport listeners() { if(this.listeners == null) { this.listeners = new PropertyChangeSupport(this); From d8fe01936acf7124dd7da2763e7ef2d77bd748d5 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:11:46 +0100 Subject: [PATCH 07/26] refactoring: set player to card by addCard --- src/main/java/de/hsfulda/onses/models/Player.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 15dd5f7..e20dd1d 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -23,6 +23,7 @@ public class Player { } public void addCardToPlayerDeck(Card card) { + card.setPlayer(this); final ArrayList oldplayerDeck = new ArrayList<>(this.playerDeck); playerDeck.add(card); this.firePropertyChange(PROPERTY_PLAYER_DECK, oldplayerDeck, playerDeck); From e56c6802351f3efd8085f4aaace07969e9b65d9e Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:14:02 +0100 Subject: [PATCH 08/26] add test for player set card player --- src/test/java/de/hsfulda/onses/PlayerTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index 9ce04fd..7dab45d 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -114,4 +114,15 @@ public class PlayerTest { player.setCurrentCard(card); assertEquals(card, player.getCurrentCard()); } + + @Test + @DisplayName("Set Player by Card") + void testPlayerSetByCard() { + Player player = new Player(); + Card card = new Card(); + + assertNull(card.getPlayer()); + player.addCardToPlayerDeck(card); + assertEquals(player, card.getPlayer()); + } } From 019515e7a02a2e0f6de0ecf36343d1673a152925 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:14:51 +0100 Subject: [PATCH 09/26] refactoring: add set player ad cardDraw --- src/main/java/de/hsfulda/onses/services/GameService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index fc4edf3..668c177 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -54,7 +54,8 @@ public class GameService { player = game.getPlayerService().getPlayerList().getLast(); } for (int i = 0; i < amount; i++) { - player.getPlayerDeck().add(game.getDrawCardDeck().getFirst().setFacedown(isFaceDown)); + Card newCard = game.getDrawCardDeck().getFirst().setFacedown(isFaceDown).setPlayer(player); + player.getPlayerDeck().add(newCard); game.getDrawCardDeck().removeFirst(); } if (amount == 1 && !player.getPlayerDeck().isEmpty()) { @@ -133,6 +134,9 @@ public class GameService { } public void playCard(Card card) { + if(card.getPlayer() != null) { + card.getPlayer().removeCardFromPlayerDeck(card); + } // add lastPlayedCard back to drawCardDeck this.addLastPlayedCardToDrawCardDeck(); game.setLastPlayedCard(card); From 1f3eab3dde108d0239a7776480009e2974851107 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:15:28 +0100 Subject: [PATCH 10/26] refactoring: fix play card --- .../de/hsfulda/onses/controllers/GameController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 70cc61b..0abedb7 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -41,7 +41,14 @@ public class GameController implements Controller { }); playButton.setOnAction(e -> { - gameService.playCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.ONE)); + Card cardToPlay = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); + if(gameService.legalMove(cardToPlay)) { + System.out.println(cardToPlay.getPlayer()); + if(cardToPlay.getPlayer() != null) { + cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay); + gameService.playCard(cardToPlay); + } + } }); From 351cdb37df09bd5b72af46d357e93ef4518caf50 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:21:01 +0100 Subject: [PATCH 11/26] refactoring: fix remove card from bot --- src/main/java/de/hsfulda/onses/controllers/GameController.java | 1 - src/main/java/de/hsfulda/onses/services/PlayerService.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 0abedb7..fbf3b66 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -43,7 +43,6 @@ public class GameController implements Controller { playButton.setOnAction(e -> { Card cardToPlay = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); if(gameService.legalMove(cardToPlay)) { - System.out.println(cardToPlay.getPlayer()); if(cardToPlay.getPlayer() != null) { cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay); gameService.playCard(cardToPlay); diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 14382d3..8b96412 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -57,7 +57,7 @@ public class PlayerService { } else { player = playerList.getLast(); } - player.getPlayerDeck().remove(card); + player.removeCardFromPlayerDeck(card); } public void botMove() { From f3deb95784b1105edc55860f109d9525006bcadd Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:22:19 +0100 Subject: [PATCH 12/26] refactoring: add names to player pane --- .../java/de/hsfulda/onses/controllers/PlayerController.java | 2 +- src/main/java/de/hsfulda/onses/services/PlayerService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java index 5a11d1c..0779359 100644 --- a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -40,7 +40,7 @@ public class PlayerController implements Controller { } }); - playerNameLabel.setText("Test"); + playerNameLabel.setText(player.getPlayerName()); return parent; } diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 8b96412..94b24cc 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -46,8 +46,8 @@ public class PlayerService { } public PlayerService() { - addPlayerToList(new Player().setPlayerService(this)); - addPlayerToList(new Player().setPlayerService(this)); + addPlayerToList(new Player().setPlayerService(this).setPlayerName("Player")); + addPlayerToList(new Player().setPlayerService(this).setPlayerName("Bot")); } public void removeCardFromPlayerDeck(Card card) { From 6f66a2e979b6300dea749716787f181cf0b0b7bb Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 12:28:04 +0100 Subject: [PATCH 13/26] add drawCard Btn --- .../java/de/hsfulda/onses/controllers/GameController.java | 5 +++++ src/main/resources/de/hsfulda/onses/views/game.fxml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index fbf3b66..7ab7151 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -26,6 +26,7 @@ public class GameController implements Controller { final Pane enemyPane = (Pane) parent.lookup("#enemyPane"); final Pane playerPane = (Pane) parent.lookup("#playerPane"); final Button playButton = (Button) parent.lookup("#playCardBtn"); + final Button drawCardButton = (Button) parent.lookup("#drawCardBtn"); CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null); PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst()); @@ -50,6 +51,10 @@ public class GameController implements Controller { } }); + drawCardButton.setOnAction(e -> { + gameService.drawCard(1); + }); + lastPlayedCardPane.getChildren().add(lastPlayedCardController.render()); playerPane.getChildren().add(playerController.render()); diff --git a/src/main/resources/de/hsfulda/onses/views/game.fxml b/src/main/resources/de/hsfulda/onses/views/game.fxml index e0e8f23..892ce90 100644 --- a/src/main/resources/de/hsfulda/onses/views/game.fxml +++ b/src/main/resources/de/hsfulda/onses/views/game.fxml @@ -36,7 +36,7 @@ - + diff --git a/src/test/java/de/hsfulda/onses/GuiTest.java b/src/test/java/de/hsfulda/onses/GuiTest.java index 845c004..eec7715 100644 --- a/src/test/java/de/hsfulda/onses/GuiTest.java +++ b/src/test/java/de/hsfulda/onses/GuiTest.java @@ -10,11 +10,13 @@ import static org.testfx.matcher.control.LabeledMatchers.*; public class GuiTest extends ApplicationTest { private Stage stage; + private App app; @Override public void start(Stage stage) throws Exception { this.stage = stage; - new App().start(stage); + app = new App(); + app.start(stage); } @Test From 6d417a6a57aa02d67f3d115592803c13f1ff0f27 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 21:19:00 +0100 Subject: [PATCH 17/26] add remove all Controllers by destroy --- .../onses/controllers/AppController.java | 13 +++++++-- .../onses/controllers/GameController.java | 29 +++++++++++++++++-- .../onses/controllers/PlayerController.java | 11 ++++++- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/AppController.java b/src/main/java/de/hsfulda/onses/controllers/AppController.java index b5de34e..03a6e0a 100644 --- a/src/main/java/de/hsfulda/onses/controllers/AppController.java +++ b/src/main/java/de/hsfulda/onses/controllers/AppController.java @@ -8,6 +8,7 @@ import javafx.scene.Parent; import javafx.scene.control.Button; import java.io.IOException; +import java.util.ArrayList; import java.util.Objects; public class AppController implements Controller { @@ -15,13 +16,16 @@ public class AppController implements Controller { private final GameService gameService; private final App app; + private final ArrayList controllers = new ArrayList<>(); + public AppController(App app, GameService gameService) { this.app = app; - this.gameService = gameService; + this.gameService = gameService; } @Override public Parent render() throws IOException { - GameController gameController = new GameController(gameService); + GameController gameController = new GameController(app, gameService); + controllers.add(gameController); final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/app.fxml"))); Button button = (Button) parent.lookup("#startGameBtn"); @@ -38,6 +42,11 @@ public class AppController implements Controller { @Override public void destroy() { + int i = 0; + while(i < controllers.size()) { + Controller controller = controllers.get(i++); + controller.destroy(); + } } } diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 2f7ba5c..d173009 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -1,5 +1,6 @@ package de.hsfulda.onses.controllers; +import de.hsfulda.onses.App; import de.hsfulda.onses.Main; import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Game; @@ -9,13 +10,21 @@ import javafx.scene.Parent; import javafx.scene.control.Button; import javafx.scene.layout.Pane; +import java.beans.PropertyChangeEvent; import java.io.IOException; +import java.util.ArrayList; import java.util.Objects; public class GameController implements Controller { private final GameService gameService; private final Game game; - public GameController(GameService gameService) { + private final App app; + + private PropertyChangeEvent lastPlayedCardPropertyChangeEvent; + + private final ArrayList controllers = new ArrayList<>(); + public GameController(App app, GameService gameService) { + this.app = app; this.gameService = gameService; this.game = gameService.getGame(); } @@ -27,20 +36,31 @@ public class GameController implements Controller { final Pane playerPane = (Pane) parent.lookup("#playerPane"); final Button playButton = (Button) parent.lookup("#playCardBtn"); final Button drawCardButton = (Button) parent.lookup("#drawCardBtn"); + final Button exitGameButton = (Button) parent.lookup("#exitBtn"); CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null); PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst()); PlayerController enemyController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getLast()); + controllers.add(lastPlayedCardController); + controllers.add(playerController); + controllers.add(enemyController); + game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> { lastPlayedCardPane.getChildren().removeAll(); try { - lastPlayedCardPane.getChildren().add(new CardController((Card) e.getNewValue(), null).render()); + CardController tmp = new CardController((Card) e.getNewValue(), null); + controllers.add(tmp); + lastPlayedCardPane.getChildren().add(tmp.render()); } catch (IOException ex) { throw new RuntimeException(ex); } }); + exitGameButton.setOnAction(e -> { + app.show(new AppController(app, new GameService())); + }); + playButton.setOnAction(e -> { Card cardToPlay = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); if(gameService.legalMove(cardToPlay)) { @@ -70,6 +90,11 @@ public class GameController implements Controller { @Override public void destroy() { + int i = 0; + while(i < controllers.size()) { + Controller controller = controllers.get(i++); + controller.destroy(); + } } } diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java index 6742b09..57d7078 100644 --- a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -9,11 +9,13 @@ import javafx.scene.control.Label; import javafx.scene.layout.HBox; import java.io.IOException; +import java.util.ArrayList; import java.util.Objects; public class PlayerController implements Controller { private final Player player; + private final ArrayList controllers = new ArrayList<>(); public PlayerController(Player player) { this.player = player; @@ -25,7 +27,9 @@ public class PlayerController implements Controller { final HBox cards = (HBox) parent.lookup("#cardsHBox"); for(Card card : player.getPlayerDeck()) { - cards.getChildren().add(new CardController(card, player).render()); + CardController newCardController = new CardController(card, player); + controllers.add(newCardController); + cards.getChildren().add(newCardController.render()); } player.listeners().addPropertyChangeListener(Player.PROPERTY_PLAYER_DECK, e -> { @@ -51,6 +55,11 @@ public class PlayerController implements Controller { @Override public void destroy() { + int i = 0; + while(i < controllers.size()) { + Controller controller = controllers.get(i++); + controller.destroy(); + } } } From 622499b5761f443340c24a2519c3680aa3649e0b Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Thu, 8 Feb 2024 21:26:02 +0100 Subject: [PATCH 18/26] refactoring: cleanup destroy Methode --- .../java/de/hsfulda/onses/controllers/AppController.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/AppController.java b/src/main/java/de/hsfulda/onses/controllers/AppController.java index 03a6e0a..80d6da9 100644 --- a/src/main/java/de/hsfulda/onses/controllers/AppController.java +++ b/src/main/java/de/hsfulda/onses/controllers/AppController.java @@ -42,10 +42,7 @@ public class AppController implements Controller { @Override public void destroy() { - int i = 0; - - while(i < controllers.size()) { - Controller controller = controllers.get(i++); + for (Controller controller : controllers) { controller.destroy(); } } From b0a5abcb256d6c149250c18c347a9d9211180bb0 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Thu, 8 Feb 2024 21:27:21 +0100 Subject: [PATCH 19/26] refactoring: cleanup destroy Methode --- .../java/de/hsfulda/onses/controllers/GameController.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index d173009..1dff304 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -90,10 +90,7 @@ public class GameController implements Controller { @Override public void destroy() { - int i = 0; - - while(i < controllers.size()) { - Controller controller = controllers.get(i++); + for (Controller controller : controllers) { controller.destroy(); } } From 57aad8efb6518b499a2df23a8a60ef76c90cc3f0 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Thu, 8 Feb 2024 21:28:23 +0100 Subject: [PATCH 20/26] refactoring cleanup destroy Methode for PlayController --- .../java/de/hsfulda/onses/controllers/PlayerController.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java index 57d7078..4815e02 100644 --- a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -55,10 +55,7 @@ public class PlayerController implements Controller { @Override public void destroy() { - int i = 0; - - while(i < controllers.size()) { - Controller controller = controllers.get(i++); + for (Controller controller : controllers) { controller.destroy(); } } From e3a96ec19389797d981e27bf04ab5a8f10201ced Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 22:19:43 +0100 Subject: [PATCH 21/26] add remove propertyChange listeners at destroy of controller --- README.md | 3 +++ src/main/java/de/hsfulda/onses/App.java | 2 +- .../de/hsfulda/onses/controllers/AppController.java | 9 ++------- .../de/hsfulda/onses/controllers/CardController.java | 12 ++++++++---- .../de/hsfulda/onses/controllers/GameController.java | 11 +++++++---- .../hsfulda/onses/controllers/PlayerController.java | 9 +++++++-- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b7219f9..b5308df 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Onses - Uno Game +## Disclaimer for Tests +**!!Do not move the mouse while tests are running!!** + ## git setup after clone ```shell git config user.name "" diff --git a/src/main/java/de/hsfulda/onses/App.java b/src/main/java/de/hsfulda/onses/App.java index fff6bd7..8a7436f 100644 --- a/src/main/java/de/hsfulda/onses/App.java +++ b/src/main/java/de/hsfulda/onses/App.java @@ -20,8 +20,8 @@ public class App extends Application { this.stage = stage; final AppController appController = new AppController(this, new GameService()); - stage.setTitle("Onses - Uno"); stage.setScene(new Scene(new Label("Loading..."))); + stage.setOnCloseRequest(e -> controller.destroy()); show(appController); 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 80d6da9..4a59ee0 100644 --- a/src/main/java/de/hsfulda/onses/controllers/AppController.java +++ b/src/main/java/de/hsfulda/onses/controllers/AppController.java @@ -8,7 +8,6 @@ import javafx.scene.Parent; import javafx.scene.control.Button; import java.io.IOException; -import java.util.ArrayList; import java.util.Objects; public class AppController implements Controller { @@ -16,16 +15,14 @@ public class AppController implements Controller { private final GameService gameService; private final App app; - private final ArrayList controllers = new ArrayList<>(); - public AppController(App app, GameService gameService) { this.app = app; this.gameService = gameService; } + @Override public Parent render() throws IOException { GameController gameController = new GameController(app, gameService); - controllers.add(gameController); final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/app.fxml"))); Button button = (Button) parent.lookup("#startGameBtn"); @@ -42,8 +39,6 @@ public class AppController implements Controller { @Override public void destroy() { - for (Controller controller : controllers) { - controller.destroy(); - } + } } diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java index 2329232..3d05811 100644 --- a/src/main/java/de/hsfulda/onses/controllers/CardController.java +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -8,6 +8,7 @@ import javafx.scene.Parent; import javafx.scene.control.Label; import javafx.scene.layout.Pane; +import java.beans.PropertyChangeListener; import java.io.IOException; import java.util.Objects; @@ -16,10 +17,13 @@ public class CardController implements Controller { private final Card card; private final Player player; + private PropertyChangeListener cardSelectedChangeListener; + public CardController(Card card, Player player) { this.card = card; this.player = player; } + @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/card.fxml"))); @@ -68,7 +72,7 @@ public class CardController implements Controller { }); } - card.listeners().addPropertyChangeListener(Card.PROPERTY_SELECTED, e -> { + cardSelectedChangeListener = e -> { boolean oldValue = (boolean) e.getOldValue(); if(oldValue) { mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-border-color: black")); @@ -76,8 +80,8 @@ public class CardController implements Controller { mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-border-color: pink")); } - }); - + }; + card.listeners().addPropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener); return parent; } @@ -93,6 +97,6 @@ public class CardController implements Controller { @Override public void destroy() { - + card.listeners().removePropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener); } } diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 1dff304..3eccd0c 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -10,7 +10,7 @@ import javafx.scene.Parent; import javafx.scene.control.Button; import javafx.scene.layout.Pane; -import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.IOException; import java.util.ArrayList; import java.util.Objects; @@ -20,7 +20,7 @@ public class GameController implements Controller { private final Game game; private final App app; - private PropertyChangeEvent lastPlayedCardPropertyChangeEvent; + private PropertyChangeListener lastPlayedCardPropertyChangeListener; private final ArrayList controllers = new ArrayList<>(); public GameController(App app, GameService gameService) { @@ -28,6 +28,7 @@ public class GameController implements Controller { 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"))); @@ -46,7 +47,7 @@ public class GameController implements Controller { controllers.add(playerController); controllers.add(enemyController); - game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> { + lastPlayedCardPropertyChangeListener = e -> { lastPlayedCardPane.getChildren().removeAll(); try { CardController tmp = new CardController((Card) e.getNewValue(), null); @@ -55,7 +56,8 @@ public class GameController implements Controller { } catch (IOException ex) { throw new RuntimeException(ex); } - }); + }; + game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); exitGameButton.setOnAction(e -> { app.show(new AppController(app, new GameService())); @@ -93,5 +95,6 @@ public class GameController implements Controller { for (Controller controller : controllers) { controller.destroy(); } + game.listeners().removePropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); } } diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java index 4815e02..67286ea 100644 --- a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -8,6 +8,7 @@ import javafx.scene.Parent; import javafx.scene.control.Label; import javafx.scene.layout.HBox; +import java.beans.PropertyChangeListener; import java.io.IOException; import java.util.ArrayList; import java.util.Objects; @@ -16,10 +17,12 @@ public class PlayerController implements Controller { private final Player player; private final ArrayList controllers = new ArrayList<>(); + private PropertyChangeListener playerDeckChangeListener; public PlayerController(Player player) { this.player = player; } + @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/player.fxml"))); @@ -32,7 +35,7 @@ public class PlayerController implements Controller { cards.getChildren().add(newCardController.render()); } - player.listeners().addPropertyChangeListener(Player.PROPERTY_PLAYER_DECK, e -> { + playerDeckChangeListener = e -> { cards.getChildren().clear(); for(Card card : player.getPlayerDeck()) { try { @@ -41,7 +44,8 @@ public class PlayerController implements Controller { throw new RuntimeException(ex); } } - }); + }; + player.listeners().addPropertyChangeListener(Player.PROPERTY_PLAYER_DECK, playerDeckChangeListener); playerNameLabel.setText(player.getPlayerName()); @@ -58,5 +62,6 @@ public class PlayerController implements Controller { for (Controller controller : controllers) { controller.destroy(); } + player.listeners().removePropertyChangeListener(Player.PROPERTY_PLAYER_DECK, playerDeckChangeListener); } } From dd3b6d8f58cddb73f920f1b58b80750a1c38d767 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 22:36:40 +0100 Subject: [PATCH 22/26] add gameOver screen --- .../onses/controllers/GameController.java | 7 ++++ .../onses/controllers/GameOverController.java | 40 +++++++++++++++++++ .../java/de/hsfulda/onses/models/Game.java | 3 ++ .../de/hsfulda/onses/views/gameOver.fxml | 22 ++++++++++ 4 files changed, 72 insertions(+) create mode 100644 src/main/java/de/hsfulda/onses/controllers/GameOverController.java create mode 100644 src/main/resources/de/hsfulda/onses/views/gameOver.fxml diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 3eccd0c..e9146bc 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -21,6 +21,7 @@ public class GameController implements Controller { private final App app; private PropertyChangeListener lastPlayedCardPropertyChangeListener; + private PropertyChangeListener gameOverListener; private final ArrayList controllers = new ArrayList<>(); public GameController(App app, GameService gameService) { @@ -59,6 +60,11 @@ public class GameController implements Controller { }; game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); + gameOverListener = e -> { + app.show(new GameOverController(app)); + }; + game.listeners().addPropertyChangeListener(Game.PROPERTY_GAME_OVER, gameOverListener); + exitGameButton.setOnAction(e -> { app.show(new AppController(app, new GameService())); }); @@ -96,5 +102,6 @@ public class GameController implements Controller { controller.destroy(); } game.listeners().removePropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); + game.listeners().removePropertyChangeListener(Game.PROPERTY_GAME_OVER, gameOverListener); } } diff --git a/src/main/java/de/hsfulda/onses/controllers/GameOverController.java b/src/main/java/de/hsfulda/onses/controllers/GameOverController.java new file mode 100644 index 0000000..5aaf6f9 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/GameOverController.java @@ -0,0 +1,40 @@ +package de.hsfulda.onses.controllers; + +import de.hsfulda.onses.App; +import de.hsfulda.onses.Main; +import de.hsfulda.onses.services.GameService; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.control.Button; + +import java.io.IOException; +import java.util.Objects; + +public class GameOverController implements Controller { + + private final App app; + + public GameOverController(App app) { + this.app = app; + } + @Override + public Parent render() throws IOException { + final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/gameOver.fxml"))); + final Button newGameButton = (Button) parent.lookup("#newGameBtn"); + + newGameButton.setOnAction(e -> { + app.show(new GameController(app, new GameService())); + }); + return parent; + } + + @Override + public void destroy() { + + } + + @Override + public String getTitle() { + return null; + } +} diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 6a9c67a..1b14ddd 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -10,6 +10,7 @@ public class Game { public final static String PROPERTY_LAST_PLAYED_CARD = "lastPlayedCard"; public final static String PROPERTY_DRAW_CARD_DECK = "drawCardDeck"; + public final static String PROPERTY_GAME_OVER = "gameOver"; protected PropertyChangeSupport listeners; @@ -70,7 +71,9 @@ public class Game { } public void setGameOver(boolean gameOver) { + final boolean oldValue = gameOver; this.gameOver = gameOver; + this.firePropertyChange(PROPERTY_GAME_OVER, oldValue, gameOver); } public boolean getGameOver() { diff --git a/src/main/resources/de/hsfulda/onses/views/gameOver.fxml b/src/main/resources/de/hsfulda/onses/views/gameOver.fxml new file mode 100644 index 0000000..9c3b6d7 --- /dev/null +++ b/src/main/resources/de/hsfulda/onses/views/gameOver.fxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + From a39735c62712d65535583521e3ec54f5c929ccc6 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Thu, 8 Feb 2024 22:49:25 +0100 Subject: [PATCH 23/26] fix that wish card works in GUI --- .../onses/controllers/CardController.java | 13 ++++++++ .../onses/controllers/GameController.java | 33 ++++++++++++++++++- .../de/hsfulda/onses/views/game.fxml | 4 +-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java index 3d05811..f8ed28a 100644 --- a/src/main/java/de/hsfulda/onses/controllers/CardController.java +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -18,6 +18,7 @@ public class CardController implements Controller { private final Player player; private PropertyChangeListener cardSelectedChangeListener; + private PropertyChangeListener cardColorChangeListener; public CardController(Card card, Player player) { this.card = card; @@ -83,6 +84,17 @@ public class CardController implements Controller { }; card.listeners().addPropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener); + cardColorChangeListener = e -> { + switch((Card.Color)e.getNewValue()) { + 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")); + } + }; + card.listeners().addPropertyChangeListener(Card.PROPERTY_COLOR, cardColorChangeListener); + return parent; } @@ -98,5 +110,6 @@ public class CardController implements Controller { @Override public void destroy() { card.listeners().removePropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener); + card.listeners().removePropertyChangeListener(Card.PROPERTY_COLOR, cardColorChangeListener); } } diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index e9146bc..3246d95 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -39,6 +39,10 @@ public class GameController implements Controller { final Button playButton = (Button) parent.lookup("#playCardBtn"); final Button drawCardButton = (Button) parent.lookup("#drawCardBtn"); final Button exitGameButton = (Button) parent.lookup("#exitBtn"); + final Button wishRedButton = (Button) parent.lookup("#btnWishRed"); + final Button wishBlueButton = (Button) parent.lookup("#btnWishBlue"); + final Button wishGreenButton = (Button) parent.lookup("#btnWishGreen"); + final Button wishYellowButton = (Button) parent.lookup("#btnWishYellow"); CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null); PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst()); @@ -48,6 +52,26 @@ public class GameController implements Controller { controllers.add(playerController); controllers.add(enemyController); + wishRedButton.setOnAction(e -> { + Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); + currentSelectedCard.setColor(Card.Color.RED); + }); + + wishBlueButton.setOnAction(e -> { + Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); + currentSelectedCard.setColor(Card.Color.BLUE); + }); + + wishGreenButton.setOnAction(e -> { + Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); + currentSelectedCard.setColor(Card.Color.GREEN); + }); + + wishYellowButton.setOnAction(e -> { + Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); + currentSelectedCard.setColor(Card.Color.YELLOW); + }); + lastPlayedCardPropertyChangeListener = e -> { lastPlayedCardPane.getChildren().removeAll(); try { @@ -71,7 +95,14 @@ public class GameController implements Controller { playButton.setOnAction(e -> { Card cardToPlay = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); - if(gameService.legalMove(cardToPlay)) { + if(cardToPlay.getValue().equals(Card.Value.CHOOSE) || cardToPlay.getValue().equals(Card.Value.CHOOSEDRAW)) { + if(!cardToPlay.getColor().equals(Card.Color.BLACK)) { + if(cardToPlay.getPlayer() != null) { + cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay); + gameService.playCard(cardToPlay); + } + } + } else if(gameService.legalMove(cardToPlay)){ if(cardToPlay.getPlayer() != null) { cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay); gameService.playCard(cardToPlay); diff --git a/src/main/resources/de/hsfulda/onses/views/game.fxml b/src/main/resources/de/hsfulda/onses/views/game.fxml index 8ec0469..c7f1d37 100644 --- a/src/main/resources/de/hsfulda/onses/views/game.fxml +++ b/src/main/resources/de/hsfulda/onses/views/game.fxml @@ -13,12 +13,12 @@ - -