fdai7736
11 months ago
14 changed files with 264 additions and 62 deletions
-
35.gitlab-ci.yml
-
2build-project.sh
-
8pom.xml
-
6src/main/java/de/hsfulda/onses/App.java
-
21src/main/java/de/hsfulda/onses/controllers/AppController.java
-
57src/main/java/de/hsfulda/onses/controllers/CardController.java
-
48src/main/java/de/hsfulda/onses/controllers/GameController.java
-
17src/main/java/de/hsfulda/onses/controllers/PlayerController.java
-
7src/main/resources/de/hsfulda/onses/views/app.fxml
-
19src/main/resources/de/hsfulda/onses/views/card.fxml
-
45src/main/resources/de/hsfulda/onses/views/game.fxml
-
13src/main/resources/de/hsfulda/onses/views/player.fxml
-
14src/test/java/de/hsfulda/onses/ExampleTest.java
-
32src/test/java/de/hsfulda/onses/GuiTest.java
@ -1,35 +0,0 @@ |
|||||
include: |
|
||||
- template: SAST.gitlab-ci.yml |
|
||||
|
|
||||
default: |
|
||||
tags: ['docker-exec'] |
|
||||
|
|
||||
|
|
||||
image: maven:3.9.6-eclipse-temurin-21-jammy |
|
||||
variables: |
|
||||
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode" |
|
||||
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dmaven.artifact.threads=50" |
|
||||
cache: |
|
||||
paths: |
|
||||
- .m2/repository/ |
|
||||
junit tests: |
|
||||
stage: test |
|
||||
script: |
|
||||
- mvn test |
|
||||
allow_failure: false |
|
||||
artifacts: |
|
||||
expire_in: 1 week |
|
||||
reports: |
|
||||
junit: |
|
||||
- target/surefire-reports/TEST-*.xml |
|
||||
|
|
||||
script tests: |
|
||||
stage: test |
|
||||
script: |
|
||||
- ./build-project.sh |
|
||||
allow_failure: false |
|
||||
artifacts: |
|
||||
expire_in: 1 week |
|
||||
reports: |
|
||||
junit: |
|
||||
- target/surefire-reports/TEST-*.xml |
|
@ -1,3 +1,5 @@ |
|||||
#!/bin/bash |
#!/bin/bash |
||||
|
echo "Build" |
||||
|
mvn clean compile |
||||
echo "RUN JUnit Tests" |
echo "RUN JUnit Tests" |
||||
mvn clean test |
mvn clean test |
@ -0,0 +1,57 @@ |
|||||
|
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"))); |
||||
|
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")); |
||||
|
} |
||||
|
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
private String addStyle(String oldStyle, String newStyle) { |
||||
|
return oldStyle + "; " + newStyle; |
||||
|
} |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
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; |
||||
|
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)); |
||||
|
|
||||
|
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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
|
||||
|
<?import javafx.scene.Cursor?> |
||||
|
<?import javafx.scene.control.Label?> |
||||
|
<?import javafx.scene.layout.AnchorPane?> |
||||
|
<?import javafx.scene.text.Font?> |
||||
|
|
||||
|
<AnchorPane fx:id="cardPane" prefHeight="200.0" prefWidth="130.0" style="-fx-border-color: black; -fx-border-width: 3px;" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1"> |
||||
|
<children> |
||||
|
<Label fx:id="labelName" alignment="CENTER" layoutX="45.0" layoutY="91.0" text="1" textAlignment="CENTER" textFill="#da36d2" wrapText="true" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="80.0"> |
||||
|
<font> |
||||
|
<Font name="System Bold" size="19.0" /> |
||||
|
</font> |
||||
|
</Label> |
||||
|
</children> |
||||
|
<cursor> |
||||
|
<Cursor fx:constant="HAND" /> |
||||
|
</cursor> |
||||
|
</AnchorPane> |
@ -0,0 +1,45 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
|
||||
|
<?import javafx.scene.Cursor?> |
||||
|
<?import javafx.scene.control.Button?> |
||||
|
<?import javafx.scene.layout.AnchorPane?> |
||||
|
<?import javafx.scene.layout.Pane?> |
||||
|
<?import javafx.scene.text.Font?> |
||||
|
|
||||
|
<AnchorPane prefHeight="690.0" prefWidth="1254.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1"> |
||||
|
<children> |
||||
|
<Button fx:id="btnWishBlue" layoutX="891.0" layoutY="558.0" mnemonicParsing="false" style="-fx-background-color: blue; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="280.0"> |
||||
|
<cursor> |
||||
|
<Cursor fx:constant="HAND" /> |
||||
|
</cursor> |
||||
|
</Button> |
||||
|
<Button fx:id="btnWishRed" layoutX="931.0" layoutY="558.0" mnemonicParsing="false" style="-fx-background-color: red; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="240.0"> |
||||
|
<cursor> |
||||
|
<Cursor fx:constant="HAND" /> |
||||
|
</cursor> |
||||
|
</Button> |
||||
|
<Button fx:id="btnWishGreen" layoutX="891.0" layoutY="602.0" mnemonicParsing="false" style="-fx-background-color: green; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="58.0" AnchorPane.rightAnchor="240.0"> |
||||
|
<cursor> |
||||
|
<Cursor fx:constant="HAND" /> |
||||
|
</cursor> |
||||
|
</Button> |
||||
|
<Button fx:id="btnWishYellow" layoutX="891.0" layoutY="602.0" mnemonicParsing="false" style="-fx-background-color: yellow; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="58.0" AnchorPane.rightAnchor="280.0"> |
||||
|
<cursor> |
||||
|
<Cursor fx:constant="HAND" /> |
||||
|
</cursor> |
||||
|
</Button> |
||||
|
<Button fx:id="playCardBtn" layoutX="1085.0" layoutY="586.0" mnemonicParsing="false" text="Play Card"> |
||||
|
<font> |
||||
|
<Font size="18.0" /> |
||||
|
</font> |
||||
|
</Button> |
||||
|
<Pane fx:id="playerPane" layoutX="18.0" layoutY="460.0" prefHeight="217.0" prefWidth="891.0" style="-fx-border-color: red;" AnchorPane.bottomAnchor="13.0" AnchorPane.leftAnchor="18.0" AnchorPane.rightAnchor="345.0" /> |
||||
|
<Pane fx:id="enemyPane" layoutX="18.0" layoutY="14.0" prefHeight="217.0" prefWidth="891.0" style="-fx-border-color: red;" /> |
||||
|
<Pane fx:id="lastPlayedCardPane" layoutX="112.0" layoutY="245.0" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="200.0" prefWidth="130.0" AnchorPane.leftAnchor="112.0" AnchorPane.topAnchor="245.0" /> |
||||
|
<Button layoutX="404.0" layoutY="329.0" mnemonicParsing="false" text="Draw Card" AnchorPane.leftAnchor="404.0" AnchorPane.topAnchor="329.0"> |
||||
|
<font> |
||||
|
<Font size="18.0" /> |
||||
|
</font> |
||||
|
</Button> |
||||
|
</children> |
||||
|
</AnchorPane> |
@ -0,0 +1,13 @@ |
|||||
|
<?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" |
||||
|
prefHeight="400.0" prefWidth="600.0"> |
||||
|
|
||||
|
</AnchorPane> |
@ -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); |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,32 @@ |
|||||
|
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()); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
@DisplayName("Check if window Switch is working") |
||||
|
void checkSceneSwitch() { |
||||
|
clickOn("#startGameBtn"); |
||||
|
assertEquals("Onses - Uno Game", stage.getTitle()); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue