diff --git a/src/main/java/de/hsfulda/onses/App.java b/src/main/java/de/hsfulda/onses/App.java new file mode 100644 index 0000000..8712287 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/App.java @@ -0,0 +1,18 @@ +package de.hsfulda.onses; + +import de.hsfulda.onses.controllers.AppController; +import de.hsfulda.onses.models.Game; +import javafx.application.Application; +import javafx.scene.Scene; +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.setTitle("Onses - Uno Game"); + stage.setScene(new Scene(appController.render())); + stage.show(); + } +} diff --git a/src/main/java/de/hsfulda/onses/Main.java b/src/main/java/de/hsfulda/onses/Main.java index fd78049..8bf1644 100644 --- a/src/main/java/de/hsfulda/onses/Main.java +++ b/src/main/java/de/hsfulda/onses/Main.java @@ -1,10 +1,9 @@ package de.hsfulda.onses; -import de.hsfulda.onses.controllers.MainController; import javafx.application.Application; public class Main { public static void main(String[] args) { - Application.launch(MainController.class); + Application.launch(App.class); } } \ No newline at end of file diff --git a/src/main/java/de/hsfulda/onses/controllers/AppController.java b/src/main/java/de/hsfulda/onses/controllers/AppController.java new file mode 100644 index 0000000..5f8a4cc --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/AppController.java @@ -0,0 +1,29 @@ +package de.hsfulda.onses.controllers; + +import de.hsfulda.onses.Main; +import de.hsfulda.onses.models.Game; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.control.Button; + +import java.io.IOException; +import java.util.Objects; + +public class AppController implements Controller { + + private final Game game; + + public AppController(Game game) { + this.game = game; + } + @Override + public Parent render() throws IOException { + final Parent parent = FXMLLoader.load(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/java/de/hsfulda/onses/controllers/Controller.java b/src/main/java/de/hsfulda/onses/controllers/Controller.java new file mode 100644 index 0000000..3a92766 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/Controller.java @@ -0,0 +1,9 @@ +package de.hsfulda.onses.controllers; + +import javafx.scene.Parent; + +import java.io.IOException; + +public interface Controller { + Parent render() throws IOException; +} diff --git a/src/main/java/de/hsfulda/onses/controllers/MainController.java b/src/main/java/de/hsfulda/onses/controllers/MainController.java deleted file mode 100644 index ad84d77..0000000 --- a/src/main/java/de/hsfulda/onses/controllers/MainController.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.hsfulda.onses.controllers; - -import de.hsfulda.onses.Main; -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; - -import java.io.IOException; -import java.util.Objects; - -public class MainController extends Application { - @Override - public void start(Stage stage) throws IOException { - final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/main.fxml"))); - - stage.setTitle("Onses"); - stage.setScene(new Scene(parent)); - stage.show(); - } -} diff --git a/src/main/java/de/hsfulda/onses/models/.gitkeep b/src/main/java/de/hsfulda/onses/models/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/de/hsfulda/onses/models/Card.java b/src/main/java/de/hsfulda/onses/models/Card.java index 74d2393..91cab36 100644 --- a/src/main/java/de/hsfulda/onses/models/Card.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -1,7 +1,14 @@ package de.hsfulda.onses.models; +import java.beans.PropertyChangeSupport; + public class Card { - private int id; + + public final static String PROPERTY_COLOR = "color"; + public final static String PROPERTY_VALUE = "value"; + + protected PropertyChangeSupport listeners; + private Color color; private Value value; @@ -12,25 +19,20 @@ public class Card { ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAWTWO, SKIP, REVERSE, CHOOSE, CHOOSEDRAW; }; - public Card setId(int id) { - this.id = id; - return this; - } - public Card setColor(Color color) { + final Card.Color oldColor = this.color; this.color = color; + this.firePropertyChange(PROPERTY_COLOR, oldColor, color); return this; } public Card setValue(Value value) { + final Card.Value oldValue = this.value; this.value = value; + this.firePropertyChange(PROPERTY_VALUE, oldValue, value); return this; } - public int getId() { - return this.id; - } - public Color getColor() { return this.color; } @@ -38,4 +40,19 @@ public class Card { public Value getValue() { return this.value; } + + public PropertyChangeSupport listeners() { + if(this.listeners == null) { + this.listeners = new PropertyChangeSupport(this); + } + return this.listeners; + } + + public boolean firePropertyChange(String propertyName, Object oldValue, Object newValue) { + if (this.listeners != null) { + this.listeners.firePropertyChange(propertyName, oldValue, newValue); + return true; + } + return false; + } } diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 893fbb2..4683237 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -3,10 +3,16 @@ package de.hsfulda.onses.models; import de.hsfulda.onses.services.GameService; import de.hsfulda.onses.services.PlayerService; +import java.beans.PropertyChangeSupport; import java.util.ArrayList; public class Game { + public final static String PROPERTY_LAST_PLAYED_CARD = "lastPlayedCard"; + public final static String PROPERTY_DRAW_CARD_DECK = "drawCardDeck"; + + protected PropertyChangeSupport listeners; + private GameService gameService; private PlayerService playerService; @@ -24,7 +30,9 @@ public class Game { lastPlayedCard.setColor(color); } public Game setLastPlayedCard(Card lastPlayedCard) { + final Card oldLastPlayedCard = this.lastPlayedCard; this.lastPlayedCard = lastPlayedCard; + this.firePropertyChange(PROPERTY_LAST_PLAYED_CARD, oldLastPlayedCard, lastPlayedCard); return this; } @@ -33,7 +41,9 @@ public class Game { } public void addCardToDrawCardDeck(Card card) { + final ArrayList oldCards = new ArrayList<>(this.drawCardDeck); drawCardDeck.add(card); + this.firePropertyChange(PROPERTY_DRAW_CARD_DECK, oldCards, drawCardDeck); } public GameService getGameService() { @@ -66,4 +76,19 @@ public class Game { public boolean getGameOver() { return gameOver; } + + public PropertyChangeSupport listeners() { + if(this.listeners == null) { + this.listeners = new PropertyChangeSupport(this); + } + return this.listeners; + } + + public boolean firePropertyChange(String propertyName, Object oldValue, Object newValue) { + if(this.listeners != null) { + this.listeners.firePropertyChange(propertyName, oldValue, newValue); + return true; + } + return false; + } } diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 88ce707..09696bd 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -2,9 +2,13 @@ package de.hsfulda.onses.models; import de.hsfulda.onses.services.PlayerService; +import java.beans.PropertyChangeSupport; import java.util.ArrayList; public class Player { + public final static String PROPERTY_PLAYER_DECK = "playerDeck"; + + protected PropertyChangeSupport listeners; private PlayerService playerService; private Game game; @@ -15,11 +19,11 @@ public class Player { } public void addCardToPlayerDeck(Card card) { + final ArrayList oldplayerDeck = new ArrayList<>(this.playerDeck); playerDeck.add(card); + this.firePropertyChange(PROPERTY_PLAYER_DECK, oldplayerDeck, playerDeck); } - - public PlayerService getPlayerService() { return playerService; } @@ -37,4 +41,19 @@ public class Player { this.game = game; return this; } + + public PropertyChangeSupport listeners() { + if(this.listeners == null) { + this.listeners = new PropertyChangeSupport(this); + } + return this.listeners; + } + + public boolean firePropertyChange(String propertyName, Object oldValue, Object newValue) { + if (this.listeners != null) { + this.listeners.firePropertyChange(propertyName, oldValue, newValue); + return true; + } + return false; + } } diff --git a/src/main/resources/de/hsfulda/onses/views/app.fxml b/src/main/resources/de/hsfulda/onses/views/app.fxml new file mode 100644 index 0000000..7facd52 --- /dev/null +++ b/src/main/resources/de/hsfulda/onses/views/app.fxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/de/hsfulda/onses/views/main.fxml b/src/main/resources/de/hsfulda/onses/views/main.fxml deleted file mode 100644 index 150a195..0000000 --- a/src/main/resources/de/hsfulda/onses/views/main.fxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - diff --git a/src/test/java/de/hsfulda/onses/CardTest.java b/src/test/java/de/hsfulda/onses/CardTest.java index f35fa7a..a2a570a 100644 --- a/src/test/java/de/hsfulda/onses/CardTest.java +++ b/src/test/java/de/hsfulda/onses/CardTest.java @@ -9,34 +9,6 @@ import de.hsfulda.onses.models.Card; public class CardTest { - @Test - @DisplayName("CardGetID5") - public void CardTestGetID5() { - - // arrange - int expected = 5; - int ID = 5; - // act - Card testcard = new Card().setId(ID).setColor(Card.Color.BLACK).setValue(Card.Value.FIVE); - int answer = testcard.getId(); - // assert - assertEquals(expected, answer); - } - - @Test - @DisplayName("CardGetID112") - public void CardTestGetID112() { - - // arrange - int expected = 112; - int ID = 112; - // act - Card testcard = new Card().setId(ID).setColor(Card.Color.BLUE).setValue(Card.Value.CHOOSEDRAW); - int answer = testcard.getId(); - // assert - assertEquals(expected, answer); - } - @Test @DisplayName("CardGetColorBlue") @@ -46,7 +18,7 @@ public class CardTest { Card.Color expected = Card.Color.BLUE; Card.Color color = Card.Color.BLUE; // act - Card testcard = new Card().setId(9).setColor(color).setValue(Card.Value.FIVE); + Card testcard = new Card().setColor(color).setValue(Card.Value.FIVE); Card.Color answer = testcard.getColor(); // assert assertEquals(expected, answer); @@ -59,7 +31,7 @@ public class CardTest { Card.Color expected = Card.Color.BLACK; Card.Color color = Card.Color.BLACK; // act - Card testcard = new Card().setId(15).setColor(color).setValue(Card.Value.CHOOSE); + Card testcard = new Card().setColor(color).setValue(Card.Value.CHOOSE); Card.Color answer = testcard.getColor(); // assert assertEquals(expected, answer); @@ -74,7 +46,7 @@ public class CardTest { Card.Value expected = Card.Value.THREE; Card.Value value = Card.Value.THREE; // act - Card testcard = new Card().setId(2).setColor(Card.Color.BLUE).setValue(value); + Card testcard = new Card().setColor(Card.Color.BLUE).setValue(value); Card.Value answer = testcard.getValue(); // assert assertEquals(expected, answer); @@ -87,7 +59,7 @@ public class CardTest { Card.Value expected = Card.Value.SKIP; Card.Value value = Card.Value.SKIP; // act - Card testcard = new Card().setId(19).setColor(Card.Color.BLACK).setValue(value); + Card testcard = new Card().setColor(Card.Color.BLACK).setValue(value); Card.Value answer = testcard.getValue(); // assert assertEquals(expected, answer);