Browse Source

Merge branch 'main' into 'addGameOver'

# Conflicts:
#   src/main/java/de/hsfulda/onses/models/Game.java
main
fdai7793 11 months ago
parent
commit
ea09a167d9
  1. 18
      src/main/java/de/hsfulda/onses/App.java
  2. 3
      src/main/java/de/hsfulda/onses/Main.java
  3. 29
      src/main/java/de/hsfulda/onses/controllers/AppController.java
  4. 9
      src/main/java/de/hsfulda/onses/controllers/Controller.java
  5. 22
      src/main/java/de/hsfulda/onses/controllers/MainController.java
  6. 0
      src/main/java/de/hsfulda/onses/models/.gitkeep
  7. 37
      src/main/java/de/hsfulda/onses/models/Card.java
  8. 25
      src/main/java/de/hsfulda/onses/models/Game.java
  9. 23
      src/main/java/de/hsfulda/onses/models/Player.java
  10. 22
      src/main/resources/de/hsfulda/onses/views/app.fxml
  11. 14
      src/main/resources/de/hsfulda/onses/views/main.fxml
  12. 36
      src/test/java/de/hsfulda/onses/CardTest.java

18
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();
}
}

3
src/main/java/de/hsfulda/onses/Main.java

@ -1,10 +1,9 @@
package de.hsfulda.onses; package de.hsfulda.onses;
import de.hsfulda.onses.controllers.MainController;
import javafx.application.Application; import javafx.application.Application;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Application.launch(MainController.class);
Application.launch(App.class);
} }
} }

29
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;
}
}

9
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;
}

22
src/main/java/de/hsfulda/onses/controllers/MainController.java

@ -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();
}
}

0
src/main/java/de/hsfulda/onses/models/.gitkeep

37
src/main/java/de/hsfulda/onses/models/Card.java

@ -1,7 +1,14 @@
package de.hsfulda.onses.models; package de.hsfulda.onses.models;
import java.beans.PropertyChangeSupport;
public class Card { 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 Color color;
private Value value; 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; 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) { public Card setColor(Color color) {
final Card.Color oldColor = this.color;
this.color = color; this.color = color;
this.firePropertyChange(PROPERTY_COLOR, oldColor, color);
return this; return this;
} }
public Card setValue(Value value) { public Card setValue(Value value) {
final Card.Value oldValue = this.value;
this.value = value; this.value = value;
this.firePropertyChange(PROPERTY_VALUE, oldValue, value);
return this; return this;
} }
public int getId() {
return this.id;
}
public Color getColor() { public Color getColor() {
return this.color; return this.color;
} }
@ -38,4 +40,19 @@ public class Card {
public Value getValue() { public Value getValue() {
return this.value; 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;
}
} }

25
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.GameService;
import de.hsfulda.onses.services.PlayerService; import de.hsfulda.onses.services.PlayerService;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList; import java.util.ArrayList;
public class Game { 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 GameService gameService;
private PlayerService playerService; private PlayerService playerService;
@ -24,7 +30,9 @@ public class Game {
lastPlayedCard.setColor(color); lastPlayedCard.setColor(color);
} }
public Game setLastPlayedCard(Card lastPlayedCard) { public Game setLastPlayedCard(Card lastPlayedCard) {
final Card oldLastPlayedCard = this.lastPlayedCard;
this.lastPlayedCard = lastPlayedCard; this.lastPlayedCard = lastPlayedCard;
this.firePropertyChange(PROPERTY_LAST_PLAYED_CARD, oldLastPlayedCard, lastPlayedCard);
return this; return this;
} }
@ -33,7 +41,9 @@ public class Game {
} }
public void addCardToDrawCardDeck(Card card) { public void addCardToDrawCardDeck(Card card) {
final ArrayList<Card> oldCards = new ArrayList<>(this.drawCardDeck);
drawCardDeck.add(card); drawCardDeck.add(card);
this.firePropertyChange(PROPERTY_DRAW_CARD_DECK, oldCards, drawCardDeck);
} }
public GameService getGameService() { public GameService getGameService() {
@ -66,4 +76,19 @@ public class Game {
public boolean getGameOver() { public boolean getGameOver() {
return gameOver; 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;
}
} }

23
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 de.hsfulda.onses.services.PlayerService;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList; import java.util.ArrayList;
public class Player { public class Player {
public final static String PROPERTY_PLAYER_DECK = "playerDeck";
protected PropertyChangeSupport listeners;
private PlayerService playerService; private PlayerService playerService;
private Game game; private Game game;
@ -15,11 +19,11 @@ public class Player {
} }
public void addCardToPlayerDeck(Card card) { public void addCardToPlayerDeck(Card card) {
final ArrayList<Card> oldplayerDeck = new ArrayList<>(this.playerDeck);
playerDeck.add(card); playerDeck.add(card);
this.firePropertyChange(PROPERTY_PLAYER_DECK, oldplayerDeck, playerDeck);
} }
public PlayerService getPlayerService() { public PlayerService getPlayerService() {
return playerService; return playerService;
} }
@ -37,4 +41,19 @@ public class Player {
this.game = game; this.game = game;
return this; 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;
}
} }

22
src/main/resources/de/hsfulda/onses/views/app.fxml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="585.0" prefWidth="1125.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="473.0" layoutY="121.0" text="Uno Game" AnchorPane.leftAnchor="473.0" AnchorPane.topAnchor="121.0">
<font>
<Font size="34.0" />
</font>
</Label>
<Button fx:id="startGameBtn" layoutX="495.0" layoutY="275.0" mnemonicParsing="false" text="Start Game" AnchorPane.leftAnchor="495.0" AnchorPane.topAnchor="275.0">
<font>
<Font size="19.0" />
</font>
</Button>
</children>
</AnchorPane>

14
src/main/resources/de/hsfulda/onses/views/main.fxml

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="de.hsfulda.onses.controllers.MainController"
prefHeight="400.0" prefWidth="600.0">
</AnchorPane>

36
src/test/java/de/hsfulda/onses/CardTest.java

@ -9,34 +9,6 @@ import de.hsfulda.onses.models.Card;
public class CardTest { 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 @Test
@DisplayName("CardGetColorBlue") @DisplayName("CardGetColorBlue")
@ -46,7 +18,7 @@ public class CardTest {
Card.Color expected = Card.Color.BLUE; Card.Color expected = Card.Color.BLUE;
Card.Color color = Card.Color.BLUE; Card.Color color = Card.Color.BLUE;
// act // 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(); Card.Color answer = testcard.getColor();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -59,7 +31,7 @@ public class CardTest {
Card.Color expected = Card.Color.BLACK; Card.Color expected = Card.Color.BLACK;
Card.Color color = Card.Color.BLACK; Card.Color color = Card.Color.BLACK;
// act // 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(); Card.Color answer = testcard.getColor();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -74,7 +46,7 @@ public class CardTest {
Card.Value expected = Card.Value.THREE; Card.Value expected = Card.Value.THREE;
Card.Value value = Card.Value.THREE; Card.Value value = Card.Value.THREE;
// act // 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(); Card.Value answer = testcard.getValue();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -87,7 +59,7 @@ public class CardTest {
Card.Value expected = Card.Value.SKIP; Card.Value expected = Card.Value.SKIP;
Card.Value value = Card.Value.SKIP; Card.Value value = Card.Value.SKIP;
// act // 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(); Card.Value answer = testcard.getValue();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);

Loading…
Cancel
Save