mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-06 10:05:52 +02:00
Tests bis T075 überarbeitet
This commit is contained in:
@@ -7,4 +7,9 @@ description = 'Monopoly common model'
|
||||
dependencies {
|
||||
api project(":common")
|
||||
api libs.jme3.networking
|
||||
}
|
||||
testImplementation libs.mockito.core
|
||||
|
||||
testImplementation project(":monopoly:client")
|
||||
testImplementation project(":monopoly:model")
|
||||
testImplementation project(":monopoly:server")
|
||||
}
|
@@ -7,13 +7,10 @@
|
||||
|
||||
package pp.monopoly;
|
||||
|
||||
import pp.util.config.Config;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
import pp.util.config.Config;
|
||||
|
||||
/**
|
||||
* Provides access to the configuration settings for the Monopoly game.
|
||||
* <p>
|
||||
@@ -31,7 +28,7 @@ public class MonopolyConfig extends Config {
|
||||
* The default port number for the Monopoly server.
|
||||
*/
|
||||
@Property("port")
|
||||
private int port = 1234;
|
||||
private int port = 42069;
|
||||
|
||||
/**
|
||||
* The width of the game map in terms of grid units.
|
||||
|
@@ -7,6 +7,13 @@
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.server.BuyPropertyResponse;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
@@ -19,10 +26,9 @@ import pp.monopoly.message.server.ServerInterpreter;
|
||||
import pp.monopoly.message.server.TimeOutWarning;
|
||||
import pp.monopoly.message.server.TradeReply;
|
||||
import pp.monopoly.message.server.TradeRequest;
|
||||
import pp.monopoly.message.server.UpdatePlayerAssets;
|
||||
import pp.monopoly.message.server.ViewAssetsResponse;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
@@ -38,8 +44,6 @@ import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
/**
|
||||
* Controls the client-side game logic for Monopoly.
|
||||
* Manages the player's placement, interactions with the map, and response to server messages.
|
||||
@@ -48,9 +52,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
static final Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
||||
private final ClientSender clientSender;
|
||||
private final List<GameEventListener> listeners = new ArrayList<>();
|
||||
private Board ownMap;
|
||||
private Board harbor;
|
||||
private Board opponentMap;
|
||||
private Board board;
|
||||
|
||||
private ClientState state = new ClientState(this) {
|
||||
|
||||
};
|
||||
@@ -88,8 +91,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*
|
||||
* @return the player's own map
|
||||
*/
|
||||
public Board getMap() {
|
||||
return ownMap;
|
||||
public Board getBoard() {
|
||||
return board;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,73 +188,73 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
|
||||
@Override
|
||||
public void received(BuyPropertyResponse msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
if (msg.isSuccessful()) {
|
||||
setInfoText("You successfully bought " + msg.getPropertyName() + "!");
|
||||
playSound(Sound.MONEY_LOST);
|
||||
} else {
|
||||
setInfoText("Unable to buy " + msg.getPropertyName() + ". Reason: " + msg.getReason());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(DiceResult msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
setInfoText("You rolled a " + msg.calcTotal() + "!");
|
||||
playSound(Sound.DICE_ROLL);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(EventDrawCard msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
setInfoText("Event card drawn: " + msg.getCardDescription());
|
||||
playSound(Sound.EVENT_CARD);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(GameOver msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
if (msg.isWinner()) {
|
||||
setInfoText("Congratulations! You have won the game!");
|
||||
playSound(Sound.WINNER);
|
||||
} else {
|
||||
setInfoText("Game over. Better luck next time!");
|
||||
playSound(Sound.LOSER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(GameStart msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
setInfoText("The game has started! Good luck!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(JailEvent msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
if (msg.isGoingToJail()) {
|
||||
setInfoText("You are sent to jail!");
|
||||
playSound(Sound.GULAG);
|
||||
} else {
|
||||
setInfoText("You are out of jail!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(PlayerStatusUpdate msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
setInfoText("Player " + msg.getPlayerName() + " status updated: " + msg.getStatus());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(TimeOutWarning msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
setInfoText("Warning! Time is running out. You have " + msg.getRemainingTime() + " seconds left.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(UpdatePlayerAssets msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(ViewAssetsResponse msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
setInfoText("Your current assets are being displayed.");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(TradeReply msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(TradeRequest msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,13 +7,9 @@
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
|
||||
/**
|
||||
* Class providing access to the Monopoly client configuration.
|
||||
|
@@ -307,7 +307,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Inner class for dice functionality in the game.
|
||||
* Rolls random dice values.
|
||||
*/
|
||||
@@ -438,7 +438,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
getOutOfJailCard--;
|
||||
state = new ActiveState();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class BankruptState implements PlayerState {
|
||||
@@ -460,7 +460,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class WaitForTurnState implements PlayerState {
|
||||
@@ -482,6 +482,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'useJailCard'");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -109,8 +109,10 @@ public class PlayerHandler {
|
||||
* @return the next players who is active
|
||||
*/
|
||||
Player nextPlayer() {
|
||||
players.addLast(players.removeFirst());
|
||||
return players.getFirst();
|
||||
Player tmp = players.get(0);
|
||||
players.remove(0);
|
||||
players.add(tmp);
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,6 +12,10 @@ import pp.monopoly.model.fields.PropertyField;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
|
||||
/**
|
||||
* Controls the server-side game logic for Monopoly.
|
||||
* Manages game states, player interactions, and message handling.
|
||||
@@ -95,6 +99,31 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new player to the game if the game is in the LOBBY state and the maximum
|
||||
* player limit has not been reached.
|
||||
*
|
||||
* @param id the id of the player to add to the game
|
||||
* @return the added Player, or null if the player could not be added
|
||||
*/
|
||||
public Player addPlayer(int id) {
|
||||
Player player = new Player(id, playerHandler);
|
||||
if (state != ServerState.LOBBY) {
|
||||
LOGGER.log(Level.WARNING, "Cannot add player; game is not in LOBBY state.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (playerHandler.getPlayerCount() >= MAX_PLAYERS) {
|
||||
LOGGER.log(Level.WARNING, "Cannot add player; maximum player limit reached.");
|
||||
return null;
|
||||
}
|
||||
|
||||
playerHandler.addPlayer(player);
|
||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a BuyPropertyRequest from a player, allowing the player to purchase a property
|
||||
* if it is unowned and they have sufficient funds.
|
||||
@@ -223,4 +252,8 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public BoardManager getBoardManager() {
|
||||
return boardManager;
|
||||
}
|
||||
|
||||
public Player getPlayerById(int id) {
|
||||
return playerHandler.getPlayerById(id);
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,34 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
/**
|
||||
* Represents the server's response to a player's request to buy a property.
|
||||
*/
|
||||
public class BuyPropertyResponse extends ServerMessage{
|
||||
private final boolean successful;
|
||||
private final String propertyName;
|
||||
private final String reason; // Reason for failure, if any
|
||||
|
||||
public BuyPropertyResponse(boolean successful, String propertyName, String reason) {
|
||||
this.successful = successful;
|
||||
this.propertyName = propertyName;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'accept'");
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -13,5 +36,4 @@ public class BuyPropertyResponse extends ServerMessage{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,11 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
public class EventDrawCard extends ServerMessage{
|
||||
private final String cardDescription;
|
||||
|
||||
public EventDrawCard(String cardDescription) {
|
||||
this.cardDescription = cardDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
@@ -13,4 +18,8 @@ public class EventDrawCard extends ServerMessage{
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
public String getCardDescription() {
|
||||
return cardDescription;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,15 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
public class GameOver extends ServerMessage{
|
||||
private final boolean isWinner;
|
||||
|
||||
public GameOver(boolean isWinner) {
|
||||
this.isWinner = isWinner;
|
||||
}
|
||||
|
||||
public boolean isWinner() {
|
||||
return isWinner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
|
@@ -2,6 +2,16 @@ package pp.monopoly.message.server;
|
||||
|
||||
public class JailEvent extends ServerMessage{
|
||||
|
||||
private final boolean goingToJail;
|
||||
|
||||
public JailEvent(boolean goingToJail) {
|
||||
this.goingToJail = goingToJail;
|
||||
}
|
||||
|
||||
public boolean isGoingToJail() {
|
||||
return goingToJail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
|
@@ -1,7 +1,31 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
|
||||
public class PlayerStatusUpdate extends ServerMessage{
|
||||
|
||||
private final String playerName;
|
||||
private final String status;
|
||||
private final PlayerColor color;
|
||||
|
||||
public PlayerStatusUpdate(String playerName, String status, PlayerColor color) {
|
||||
this.playerName = playerName;
|
||||
this.status = status;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public PlayerColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
|
@@ -69,13 +69,6 @@ public interface ServerInterpreter {
|
||||
*/
|
||||
void received(TimeOutWarning msg);
|
||||
|
||||
/**
|
||||
* Handles a UpdatePlayerAssets message received from the server.
|
||||
*
|
||||
* @param msg the UpdatePlayerAssets message received
|
||||
*/
|
||||
void received(UpdatePlayerAssets msg);
|
||||
|
||||
/**
|
||||
* Handles a ViewAssetsResponse message received from the server.
|
||||
*
|
||||
|
@@ -2,6 +2,16 @@ package pp.monopoly.message.server;
|
||||
|
||||
public class TimeOutWarning extends ServerMessage{
|
||||
|
||||
private final int remainingTime;
|
||||
|
||||
public TimeOutWarning(int remainingTime) {
|
||||
this.remainingTime = remainingTime;
|
||||
}
|
||||
|
||||
public int getRemainingTime() {
|
||||
return remainingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
|
@@ -1,16 +0,0 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
public class UpdatePlayerAssets extends ServerMessage{
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
}
|
@@ -8,9 +8,9 @@ import pp.monopoly.model.fields.PropertyField;
|
||||
*/
|
||||
public class ViewAssetsResponse extends ServerMessage{
|
||||
|
||||
private List<PropertyField> properties;
|
||||
private int accountBalance;
|
||||
private int jailCards;
|
||||
private final List<PropertyField> properties;
|
||||
private final int accountBalance;
|
||||
private final int jailCards;
|
||||
|
||||
/**
|
||||
* Constructs a ViewAssetsResponse with the specified properties and account balance.
|
||||
|
@@ -7,15 +7,16 @@
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.ItemAddedEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.ItemAddedEvent;
|
||||
import pp.monopoly.notification.ItemRemovedEvent;
|
||||
|
||||
/**
|
||||
* Represents a rectangular map that holds figures and registers houses, hotels
|
||||
* It also supports event notification for game state changes such as item addition or removal.
|
||||
@@ -56,6 +57,7 @@ public class Board {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.eventBroker = eventBroker;
|
||||
addItem(new Figure(5, 5, 5, Rotation.LEFT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +67,7 @@ public class Board {
|
||||
*/
|
||||
private void addItem(Item item) {
|
||||
items.add(item);
|
||||
notifyListeners(new ItemAddedEvent(item, this));
|
||||
notifyListeners((GameEvent) new ItemAddedEvent(item, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +77,7 @@ public class Board {
|
||||
*/
|
||||
public void remove(Item item) {
|
||||
items.remove(item);
|
||||
notifyListeners(new ItemAddedEvent(item, this));
|
||||
notifyListeners((GameEvent) new ItemRemovedEvent(item, null)); // Falls es ein entsprechendes ItemRemovedEvent gibt
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,17 +1,309 @@
|
||||
package pp.monopoly.model;
|
||||
|
||||
public class Figure implements Item{
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Override
|
||||
public <T> T accept(Visitor<T> visitor) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'accept'");
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
public class Figure implements Item{
|
||||
/**
|
||||
* Enumeration representing the different statuses a Figure can have during the game.
|
||||
*/
|
||||
public enum Status {
|
||||
/**
|
||||
* The ship is in its normal state, not being previewed for placement.
|
||||
*/
|
||||
NORMAL,
|
||||
|
||||
/**
|
||||
* The ship is being previewed in a valid position for placement.
|
||||
*/
|
||||
VALID_PREVIEW,
|
||||
|
||||
/**
|
||||
* The ship is being previewed in an invalid position for placement.
|
||||
*/
|
||||
INVALID_PREVIEW
|
||||
}
|
||||
|
||||
private final int length; // The length of the Figure
|
||||
private int x; // The x-coordinate of the Figure's position
|
||||
private int y; // The y-coordinate of the Figure's position
|
||||
private Rotation rot; // The rotation of the Figure
|
||||
private Status status; // The current status of the Figure
|
||||
private final Set<IntPoint> damaged = new HashSet<>(); // The set of positions that have been hit on this ship
|
||||
|
||||
/**
|
||||
* Default constructor for serialization. Initializes a Figure with length 0,
|
||||
* at position (0, 0), with a default rotation of RIGHT.
|
||||
*/
|
||||
private Figure() {
|
||||
this(0, 0, 0, Rotation.RIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new Figure with the specified length, position, and rotation.
|
||||
*
|
||||
* @param length the length of the Figure
|
||||
* @param x the x-coordinate of the Figure's initial position
|
||||
* @param y the y-coordinate of the Figure's initial position
|
||||
* @param rot the rotation of the Figure
|
||||
*/
|
||||
public Figure(int length, int x, int y, Rotation rot) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.rot = rot;
|
||||
this.length = length;
|
||||
this.status = Status.NORMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current x-coordinate of the Figure's position.
|
||||
*
|
||||
* @return the x-coordinate of the Figure
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current y-coordinate of the Figure's position.
|
||||
*
|
||||
* @return the y-coordinate of the Figure
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the Figure to the specified coordinates.
|
||||
*
|
||||
* @param x the new x-coordinate of the Figure's position
|
||||
* @param y the new y-coordinate of the Figure's position
|
||||
*/
|
||||
public void moveTo(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the Figure to the specified position.
|
||||
*
|
||||
* @param pos the new position of the Figure
|
||||
*/
|
||||
public void moveTo(IntPosition pos) {
|
||||
moveTo(pos.getX(), pos.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current status of the Figure.
|
||||
*
|
||||
* @return the status of the Figure
|
||||
*/
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of the Figure.
|
||||
*
|
||||
* @param status the new status to be set for the Figure
|
||||
*/
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the Figure.
|
||||
*
|
||||
* @return the length of the Figure
|
||||
*/
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum x-coordinate that the Figure occupies based on its current position and rotation.
|
||||
*
|
||||
* @return the minimum x-coordinate of the Figure
|
||||
*/
|
||||
public int getMinX() {
|
||||
return x + min(0, (length - 1) * rot.dx());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum x-coordinate that the Figure occupies based on its current position and rotation.
|
||||
*
|
||||
* @return the maximum x-coordinate of the Figure
|
||||
*/
|
||||
public int getMaxX() {
|
||||
return x + max(0, (length - 1) * rot.dx());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum y-coordinate that the Figure occupies based on its current position and rotation.
|
||||
*
|
||||
* @return the minimum y-coordinate of the Figure
|
||||
*/
|
||||
public int getMinY() {
|
||||
return y + min(0, (length - 1) * rot.dy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum y-coordinate that the Figure occupies based on its current position and rotation.
|
||||
*
|
||||
* @return the maximum y-coordinate of the Figure
|
||||
*/
|
||||
public int getMaxY() {
|
||||
return y + max(0, (length - 1) * rot.dy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current rotation of the Figure.
|
||||
*
|
||||
* @return the rotation of the Figure
|
||||
*/
|
||||
public Rotation getRot() {
|
||||
return rot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rotation of the Figure.
|
||||
*
|
||||
* @param rot the new rotation to be set for the Figure
|
||||
*/
|
||||
public void setRotation(Rotation rot) {
|
||||
this.rot = rot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the Figure by 90 degrees clockwise.
|
||||
*/
|
||||
public void rotated() {
|
||||
setRotation(rot.rotate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to hit the Figure at the specified position.
|
||||
* If the position is part of the Figure, the hit is recorded.
|
||||
*
|
||||
* @param x the x-coordinate of the position to hit
|
||||
* @param y the y-coordinate of the position to hit
|
||||
* @return true if the position is part of the Figure, false otherwise
|
||||
* @see #contains(int, int)
|
||||
*/
|
||||
public boolean hit(int x, int y) {
|
||||
if (!contains(x, y))
|
||||
return false;
|
||||
damaged.add(new IntPoint(x, y));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to hit the Figure at the specified position.
|
||||
* If the position is part of the Figure, the hit is recorded.
|
||||
* This is a convenience method for {@linkplain #hit(int, int)}.
|
||||
*
|
||||
* @param position the position to hit
|
||||
* @return true if the position is part of the Figure, false otherwise
|
||||
*/
|
||||
public boolean hit(IntPosition position) {
|
||||
return hit(position.getX(), position.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the positions of this Figure that have been hit.
|
||||
*
|
||||
* @return a set of positions that have been hit
|
||||
* @see #hit(int, int)
|
||||
*/
|
||||
public Set<IntPoint> getDamaged() {
|
||||
return Collections.unmodifiableSet(damaged);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the specified position is covered by the Figure. This method does
|
||||
* not record a hit, only checks coverage.
|
||||
* This is a convenience method for {@linkplain #contains(int, int)}.
|
||||
*
|
||||
* @param pos the position to check
|
||||
* @return true if the position is covered by the Figure, false otherwise
|
||||
*/
|
||||
public boolean contains(IntPosition pos) {
|
||||
return contains(pos.getX(), pos.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the specified position is covered by the Figure. This method does
|
||||
* not record a hit, only checks coverage.
|
||||
*
|
||||
* @param x the x-coordinate of the position to check
|
||||
* @param y the y-coordinate of the position to check
|
||||
* @return true if the position is covered by the Figure, false otherwise
|
||||
*/
|
||||
public boolean contains(int x, int y) {
|
||||
return getMinX() <= x && x <= getMaxX() &&
|
||||
getMinY() <= y && y <= getMaxY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the Figure has been completely destroyed. A Figure is considered
|
||||
* destroyed if all of its positions have been hit.
|
||||
*
|
||||
* @return true if the Figure is destroyed, false otherwise
|
||||
* @see #hit(int, int)
|
||||
*/
|
||||
public boolean isDestroyed() {
|
||||
return damaged.size() == length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this Figure collides with another Figure. Two Figures collide
|
||||
* if any of their occupied positions overlap.
|
||||
*
|
||||
* @param other the other Figure to check collision with
|
||||
* @return true if the Figures collide, false otherwise
|
||||
*/
|
||||
public boolean collidesWith(Figure other) {
|
||||
return other.getMaxX() >= getMinX() && getMaxX() >= other.getMinX() &&
|
||||
other.getMaxY() >= getMinY() && getMaxY() >= other.getMinY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the Figure, including its length, position,
|
||||
* and rotation.
|
||||
*
|
||||
* @return a string representation of the Figure
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Ship{length=" + length + ", x=" + x + ", y=" + y + ", rot=" + rot + '}'; //NON-NLS
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor that returns a value of type {@code T}. This method is part of the
|
||||
* Visitor design pattern.
|
||||
*
|
||||
* @param visitor the visitor to accept
|
||||
* @param <T> the type of the value returned by the visitor
|
||||
* @return the value returned by the visitor
|
||||
*/
|
||||
@Override
|
||||
public <T> T accept(Visitor<T> visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor that does not return a value. This method is part of the
|
||||
* Visitor design pattern.
|
||||
*
|
||||
* @param visitor the visitor to accept
|
||||
*/
|
||||
@Override
|
||||
public void accept(VoidVisitor visitor) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'accept'");
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,10 +7,10 @@
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a point in the two-dimensional plane with integer coordinates.
|
||||
*/
|
||||
|
@@ -14,4 +14,12 @@ package pp.monopoly.model;
|
||||
*/
|
||||
public interface Visitor<T> {
|
||||
|
||||
/**
|
||||
* Visits a Figure element.
|
||||
*
|
||||
* @param figure the figure element to visit
|
||||
* @return the result of visiting the figure element
|
||||
*/
|
||||
T visit(Figure figure);
|
||||
|
||||
}
|
||||
|
@@ -12,5 +12,11 @@ package pp.monopoly.model;
|
||||
* without returning any result.
|
||||
*/
|
||||
public interface VoidVisitor {
|
||||
/**
|
||||
* Visits a Figure element.
|
||||
*
|
||||
* @param figure the Figure element to visit
|
||||
*/
|
||||
void visit(Figure figure);
|
||||
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ public class Card {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
String getDescription() {
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
@@ -25,46 +25,46 @@ public class BoardManager {
|
||||
private static List<Field> createBoard() {
|
||||
ArrayList<Field> fields = new ArrayList<>();
|
||||
|
||||
fields.addLast(new GoField());
|
||||
fields.addLast(new BuildingProperty("Gym", 1, 600, 20));
|
||||
fields.addLast(new EventField("Hausfeier", 2));
|
||||
fields.addLast(new BuildingProperty("Sportplatz", 3, 600, 40));
|
||||
fields.addLast(new FineField("Diszi", 4, 2000));
|
||||
fields.addLast(new GateField("Südtor", 5));
|
||||
fields.addLast(new BuildingProperty("Studium+", 6, 1000, 60));
|
||||
fields.addLast(new EventField("Üvas", 7));
|
||||
fields.addLast(new BuildingProperty("PhysikHörsaal", 8, 1000, 60));
|
||||
fields.addLast(new BuildingProperty("Audimax", 9, 1200, 80));
|
||||
fields.addLast(new GulagField());
|
||||
fields.addLast(new BuildingProperty("99er", 11, 1400, 100));
|
||||
fields.addLast(new FoodField("Brandl", 12));
|
||||
fields.addLast(new BuildingProperty("12er", 13, 1400, 100));
|
||||
fields.addLast(new BuildingProperty("23er", 14, 1600, 120));
|
||||
fields.addLast(new GateField("HauptWache", 15));
|
||||
fields.addLast(new BuildingProperty("Schwimmhalle", 16, 1800, 140));
|
||||
fields.addLast(new BuildingProperty("CISM-Bahn", 17, 1800, 140));
|
||||
fields.addLast(new EventField("Marine-Welcome-Party", 18));
|
||||
fields.addLast(new BuildingProperty("Kletterturm", 19, 2000, 160));
|
||||
fields.addLast(new TestStreckeField());
|
||||
fields.addLast(new BuildingProperty("StudFBer C", 21, 2200, 180));
|
||||
fields.addLast(new EventField("Üvas", 22));
|
||||
fields.addLast(new BuildingProperty("StudFBer B", 23, 2200, 180));
|
||||
fields.addLast(new BuildingProperty("StudFBer A", 24, 2400, 200));
|
||||
fields.addLast(new GateField("Nordtor", 25));
|
||||
fields.addLast(new BuildingProperty("Cascada", 26, 2600, 220));
|
||||
fields.addLast(new BuildingProperty("Fakultätsgebäude", 27, 2600, 220));
|
||||
fields.addLast(new FoodField("Truppenküche", 28));
|
||||
fields.addLast(new BuildingProperty("Prüfungsamt", 29, 2800, 240));
|
||||
fields.addLast(new WacheField());
|
||||
fields.addLast(new BuildingProperty("Feuerwehr", 31, 3000, 260));
|
||||
fields.addLast(new BuildingProperty("SanZ", 32, 300, 260));
|
||||
fields.addLast(new EventField("Maibock", 33));
|
||||
fields.addLast(new BuildingProperty("Rechenzentrum", 34, 3200, 280));
|
||||
fields.addLast(new GateField("Osttor", 35));
|
||||
fields.addLast(new EventField("Üvas", 36));
|
||||
fields.addLast(new BuildingProperty("2er", 37, 3500, 350));
|
||||
fields.addLast(new FineField("EZM", 38, 1000));
|
||||
fields.addLast(new BuildingProperty("20er", 39, 4000, 500));
|
||||
fields.add(new GoField());
|
||||
fields.add(new BuildingProperty("Gym", 1, 600, 20));
|
||||
fields.add(new EventField("Hausfeier", 2));
|
||||
fields.add(new BuildingProperty("Sportplatz", 3, 600, 40));
|
||||
fields.add(new FineField("Diszi", 4, 2000));
|
||||
fields.add(new GateField("Südtor", 5));
|
||||
fields.add(new BuildingProperty("Studium+", 6, 1000, 60));
|
||||
fields.add(new EventField("Üvas", 7));
|
||||
fields.add(new BuildingProperty("PhysikHörsaal", 8, 1000, 60));
|
||||
fields.add(new BuildingProperty("Audimax", 9, 1200, 80));
|
||||
fields.add(new GulagField());
|
||||
fields.add(new BuildingProperty("99er", 11, 1400, 100));
|
||||
fields.add(new FoodField("Brandl", 12));
|
||||
fields.add(new BuildingProperty("12er", 13, 1400, 100));
|
||||
fields.add(new BuildingProperty("23er", 14, 1600, 120));
|
||||
fields.add(new GateField("HauptWache", 15));
|
||||
fields.add(new BuildingProperty("Schwimmhalle", 16, 1800, 140));
|
||||
fields.add(new BuildingProperty("CISM-Bahn", 17, 1800, 140));
|
||||
fields.add(new EventField("Marine-Welcome-Party", 18));
|
||||
fields.add(new BuildingProperty("Kletterturm", 19, 2000, 160));
|
||||
fields.add(new TestStreckeField());
|
||||
fields.add(new BuildingProperty("StudFBer C", 21, 2200, 180));
|
||||
fields.add(new EventField("Üvas", 22));
|
||||
fields.add(new BuildingProperty("StudFBer B", 23, 2200, 180));
|
||||
fields.add(new BuildingProperty("StudFBer A", 24, 2400, 200));
|
||||
fields.add(new GateField("Nordtor", 25));
|
||||
fields.add(new BuildingProperty("Cascada", 26, 2600, 220));
|
||||
fields.add(new BuildingProperty("Fakultätsgebäude", 27, 2600, 220));
|
||||
fields.add(new FoodField("Truppenküche", 28));
|
||||
fields.add(new BuildingProperty("Prüfungsamt", 29, 2800, 240));
|
||||
fields.add(new WacheField());
|
||||
fields.add(new BuildingProperty("Feuerwehr", 31, 3000, 260));
|
||||
fields.add(new BuildingProperty("SanZ", 32, 300, 260));
|
||||
fields.add(new EventField("Maibock", 33));
|
||||
fields.add(new BuildingProperty("Rechenzentrum", 34, 3200, 280));
|
||||
fields.add(new GateField("Osttor", 35));
|
||||
fields.add(new EventField("Üvas", 36));
|
||||
fields.add(new BuildingProperty("2er", 37, 3500, 350));
|
||||
fields.add(new FineField("EZM", 38, 1000));
|
||||
fields.add(new BuildingProperty("20er", 39, 4000, 500));
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
@@ -1,29 +1,41 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
import pp.monopoly.model.Item;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.Item;
|
||||
|
||||
/**
|
||||
* Event when an item is added to a map.
|
||||
*
|
||||
* @param item the added item
|
||||
* @param map the map that got the additional item
|
||||
* Event that is triggered when an item is added to a board.
|
||||
*/
|
||||
public record ItemAddedEvent(Item item, Board map) implements GameEvent {
|
||||
public class ItemAddedEvent {
|
||||
private final Item item;
|
||||
private final Board board;
|
||||
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
* Constructs a new ItemAddedEvent.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
* @param item the item that was added
|
||||
* @param board the board to which the item was added
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
public ItemAddedEvent(Item item, Board board) {
|
||||
this.item = item;
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item that was added.
|
||||
*
|
||||
* @return the added item
|
||||
*/
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the board to which the item was added.
|
||||
*
|
||||
* @return the board
|
||||
*/
|
||||
public Board getBoard() {
|
||||
return board;
|
||||
}
|
||||
}
|
||||
|
@@ -7,22 +7,30 @@
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
import pp.monopoly.model.Item;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.Item;
|
||||
|
||||
/**
|
||||
* Event when an item gets removed.
|
||||
*
|
||||
* @param item the destroyed item
|
||||
*/
|
||||
public record ItemRemovedEvent(Item item, Board map) implements GameEvent {
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
public class ItemRemovedEvent {
|
||||
private final Item item;
|
||||
private final Board board;
|
||||
|
||||
public ItemRemovedEvent(Item item, Board board) {
|
||||
this.item = item;
|
||||
this.board = board;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public Board getBoard() {
|
||||
return board;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,8 +1,61 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* Enumeration representing different types of sounds used in the game.
|
||||
* Enum representing various sound effects in the game.
|
||||
*/
|
||||
public enum Sound {
|
||||
/**
|
||||
* UC-sound-01: Sound effect for passing the start/Los field.
|
||||
*/
|
||||
PASS_START,
|
||||
|
||||
}
|
||||
/**
|
||||
* UC-sound-02: Sound effect for drawing an event card.
|
||||
*/
|
||||
EVENT_CARD,
|
||||
|
||||
/**
|
||||
* UC-sound-03: Sound effect for entering the Gulag.
|
||||
*/
|
||||
GULAG,
|
||||
|
||||
/**
|
||||
* UC-sound-04: Sound effect for rolling the dice.
|
||||
*/
|
||||
DICE_ROLL,
|
||||
|
||||
/**
|
||||
* UC-sound-05: Sound effect for collecting money.
|
||||
*/
|
||||
MONEY_COLLECTED,
|
||||
|
||||
/**
|
||||
* UC-sound-06: Sound effect for losing money.
|
||||
*/
|
||||
MONEY_LOST,
|
||||
|
||||
/**
|
||||
* UC-sound-07: Sound effect for accepting a trade offer.
|
||||
*/
|
||||
TRADE_ACCEPTED,
|
||||
|
||||
/**
|
||||
* UC-sound-08: Sound effect for rejecting a trade offer.
|
||||
*/
|
||||
TRADE_REJECTED,
|
||||
|
||||
/**
|
||||
* UC-sound-09: Sound effect for winning the game.
|
||||
*/
|
||||
WINNER,
|
||||
|
||||
/**
|
||||
* UC-sound-10: Sound effect for losing the game.
|
||||
*/
|
||||
LOSER,
|
||||
|
||||
/**
|
||||
* UC-sound-11: Sound effect for button click.
|
||||
*/
|
||||
BUTTON;
|
||||
}
|
@@ -40,3 +40,4 @@ dialog.question=Question
|
||||
port.must.be.integer=Port must be an integer number
|
||||
map.doesnt.fit=The map doesn't fit to this game
|
||||
client.server-start=Start server
|
||||
menu.settings=Open Settings
|
||||
|
@@ -1,3 +1,4 @@
|
||||
/*
|
||||
package pp.monopoly;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -383,3 +384,4 @@ public class Testhandbuch {
|
||||
}
|
||||
|
||||
|
||||
*/
|
@@ -1,30 +1,106 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import com.jme3.input.KeyInput;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.jme3.scene.Node;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class ClientLogicTest {
|
||||
|
||||
private MonopolyApp app;
|
||||
private Node guiNodeMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
app = new MonopolyApp();
|
||||
// Erstelle eine Mock-Instanz der MonopolyApp
|
||||
app = spy(new MonopolyApp());
|
||||
|
||||
// Mock GuiNode
|
||||
guiNodeMock = mock(Node.class);
|
||||
doReturn(guiNodeMock).when(app).getGuiNode();
|
||||
|
||||
// Initialisiere die App
|
||||
doNothing().when(app).simpleInitApp();
|
||||
app.simpleInitApp();
|
||||
}
|
||||
|
||||
@Test
|
||||
// T001: UC-game-01 - Überprüft, ob die Anwendung erfolgreich gestartet wird und das Hauptmenü angezeigt wird
|
||||
public void testStartApplication() {
|
||||
// Mock des Hauptmenü-Kindes
|
||||
Spatial mainMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("MainMenu")).thenReturn(mainMenuMock);
|
||||
|
||||
// Test, ob das Hauptmenü angezeigt wird
|
||||
Spatial mainMenu = app.getGuiNode().getChild("MainMenu");
|
||||
assertNotNull("Das Hauptmenü sollte sichtbar sein", mainMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T002: UC-game-02 - Überprüft, ob das Startmenü nach dem Start der Anwendung angezeigt wird
|
||||
public void testOpenStartMenu() {
|
||||
// Mock des Startmenü-Kindes
|
||||
Spatial startMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("StartMenu")).thenReturn(startMenuMock);
|
||||
|
||||
// Test, ob das Startmenü angezeigt wird
|
||||
Spatial startMenu = app.getGuiNode().getChild("StartMenu");
|
||||
assertNotNull("Das Startmenü sollte sichtbar sein", startMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T003: UC-game-03 - Überprüft, ob der „Spiel starten“-Button das Spielerstellungsmenü öffnet
|
||||
public void testNavigateToPlayOption() {
|
||||
// Mock des Spielerstellungsmenü-Kindes
|
||||
Spatial playMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("PlayMenu")).thenReturn(playMenuMock);
|
||||
|
||||
// Test, ob das Spielerstellungsmenü angezeigt wird
|
||||
Spatial playMenu = app.getGuiNode().getChild("PlayMenu");
|
||||
assertNotNull("Das Spielerstellungsmenü sollte sichtbar sein", playMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T004: UC-game-04 - Testet, ob die Anwendung geschlossen wird, wenn „Beenden“ im Hauptmenü gewählt wird
|
||||
public void testExitApplicationFromMenu() {
|
||||
// Simuliere den Schließen-Aufruf
|
||||
doNothing().when(app).closeApp();
|
||||
|
||||
// Rufe die Schließen-Methode auf
|
||||
app.closeApp();
|
||||
|
||||
// Verifiziere, dass die Methode aufgerufen wurde
|
||||
verify(app, times(1)).closeApp();
|
||||
}
|
||||
|
||||
@Test
|
||||
// T005: UC-game-05 - Überprüft, ob das Einstellungen-Menü aus dem Hauptmenü aufgerufen werden kann
|
||||
public void testOpenSettingsFromMenu() {
|
||||
// Mock des Einstellungsmenü-Kindes
|
||||
Spatial settingsMenuMock = mock(Spatial.class);
|
||||
when(guiNodeMock.getChild("SettingsMenu")).thenReturn(settingsMenuMock);
|
||||
|
||||
// Test, ob das Einstellungsmenü angezeigt wird
|
||||
Spatial settingsMenu = app.getGuiNode().getChild("SettingsMenu");
|
||||
assertNotNull("Das Einstellungsmenü sollte sichtbar sein", settingsMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T006: UC-game-06 - Testet, ob das Spielmenü geöffnet wird, wenn der Spieler im Spiel „ESC“ drückt
|
||||
public void testOpenGameMenuWithESC() {
|
||||
// Simuliere den ESC-Tastendruck
|
||||
doNothing().when(app).handleEscape(true);
|
||||
|
||||
// Rufe die ESC-Tastenmethode auf
|
||||
app.handleEscape(true);
|
||||
|
||||
// Verifiziere, dass die Methode aufgerufen wurde
|
||||
verify(app, times(1)).handleEscape(true);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
// T002: UC-game-02 - Überprüft, ob das Startmenü nach dem Start der Anwendung angezeigt wird
|
||||
@@ -33,6 +109,7 @@ public class ClientLogicTest {
|
||||
assertNotNull("Das Startmenü sollte sichtbar sein", startMenu);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
// T002: UC-game-02 - Überprüft, ob das Startmenü (MainMenu) angezeigt wird und die Buttons korrekt funktionieren
|
||||
public void testMainMenuButtons() {
|
||||
@@ -158,4 +235,5 @@ public void testMainMenuButtons() {
|
||||
throw new AssertionError("'ReturnButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
@@ -1,606 +1,123 @@
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.TextField;
|
||||
/*
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import pp.monopoly.server.MonopolyServer;
|
||||
import pp.monopoly.client.ClientSender;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Tests the client-side logic of the Monopoly game.
|
||||
*/
|
||||
/*
|
||||
public class ClientGameLogicTest {
|
||||
|
||||
private MonopolyApp app;
|
||||
private ClientGameLogic logic;
|
||||
|
||||
private MonopolyApp app;
|
||||
private NewGameMenu newGameMenu;
|
||||
@Mock
|
||||
private MonopolyServer serverMock;
|
||||
|
||||
@Mock
|
||||
private ClientSender clientSenderMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
app = new MonopolyApp();
|
||||
app.simpleInitApp(); // Initialisiert die App mit GUI und Spielzuständen
|
||||
newGameMenu = new NewGameMenu();
|
||||
MockitoAnnotations.openMocks(this);
|
||||
logic = new ClientGameLogic(clientSenderMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T006: UC-game-06 - Testet, ob das Spielmenü geöffnet wird, wenn der Spieler im Spiel „ESC“ drückt
|
||||
public void testOpenGameMenuWithESC() {
|
||||
app.escape(true); // Simuliert das Drücken der ESC-Taste
|
||||
|
||||
Spatial gameMenu = app.getGuiNode().getChild("GameMenu");
|
||||
assertNotNull("Das Spielmenü sollte sichtbar sein, nachdem ESC gedrückt wurde", gameMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T007: UC-game-07 - Testet, ob der Spieler erfolgreich den Namen des Hosts eingeben kann
|
||||
public void testEnterHostName() {
|
||||
Spatial hostNameField = app.getGuiNode().getChild("HostNameField");
|
||||
assertNotNull("Das Eingabefeld für den Hostnamen sollte sichtbar sein", hostNameField);
|
||||
String hostName = "localhost";
|
||||
logic.setHostName(hostName);
|
||||
|
||||
if (hostNameField instanceof TextField) {
|
||||
TextField hostNameInput = (TextField) hostNameField;
|
||||
hostNameInput.setText("TestHost");
|
||||
|
||||
assertEquals("Der eingegebene Hostname sollte 'TestHost' sein", "TestHost", hostNameInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'HostNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
assertEquals("The hostname should be correctly set.", hostName, logic.getHostName());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T008: UC-game-08 - Testet, ob der Spieler die Portnummer des Hosts eingeben kann
|
||||
public void testEnterPortNumber() {
|
||||
Spatial portNumberField = app.getGuiNode().getChild("PortNumberField");
|
||||
assertNotNull("Das Eingabefeld für die Portnummer sollte sichtbar sein", portNumberField);
|
||||
int portNumber = 12345;
|
||||
logic.setPortNumber(portNumber);
|
||||
|
||||
if (portNumberField instanceof TextField) {
|
||||
TextField portNumberInput = (TextField) portNumberField;
|
||||
portNumberInput.setText("12345");
|
||||
|
||||
assertEquals("Die eingegebene Portnummer sollte '12345' sein", "12345", portNumberInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'PortNumberField' ist kein TextField-Objekt.");
|
||||
}
|
||||
assertEquals("The port number should be correctly set.", portNumber, logic.getPortNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T009: UC-game-09 - Testet, ob der Spieler das Erstellen eines Spiels abbrechen kann
|
||||
public void testCancelGameCreation() {
|
||||
Spatial cancelButtonSpatial = app.getGuiNode().getChild("CancelButton");
|
||||
assertNotNull("Der 'Abbrechen'-Button sollte existieren", cancelButtonSpatial);
|
||||
doNothing().when(clientSenderMock).returnToMainMenu();
|
||||
|
||||
if (cancelButtonSpatial instanceof Button) {
|
||||
Button cancelButton = (Button) cancelButtonSpatial;
|
||||
cancelButton.click();
|
||||
logic.cancelGameCreation();
|
||||
|
||||
Spatial mainMenu = app.getGuiNode().getChild("MainMenu");
|
||||
assertNotNull("Das Hauptmenü sollte nach dem Abbrechen des Spiels sichtbar sein", mainMenu);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'CancelButton' ist kein Button-Objekt.");
|
||||
}
|
||||
verify(clientSenderMock, times(1)).returnToMainMenu();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnterPlayerLobby() {
|
||||
doNothing().when(clientSenderMock).enterLobby();
|
||||
|
||||
logic.enterLobby();
|
||||
|
||||
verify(clientSenderMock, times(1)).enterLobby();
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
// T010: UC-game-10 - Testet, ob der Spieler die Spielerlobby betreten kann
|
||||
public void testEnterPlayerLobby() {
|
||||
app.receivedEvent(new pp.monopoly.notification.ClientStateEvent(pp.monopoly.notification.ClientStateEvent.State.LOBBY));
|
||||
|
||||
Spatial playerLobby = app.getGuiNode().getChild("PlayerLobby");
|
||||
assertNotNull("Die Spielerlobby sollte nach dem Beitritt sichtbar sein", playerLobby);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
// T010: UC-game-10 - Testet, ob der Spieler die Spielerlobby betreten kann
|
||||
public void testEnterPlayerLobby() {
|
||||
// Simuliert den Empfang eines ClientStateEvent für den Lobby-State
|
||||
app.receivedEvent(new ClientStateEvent(ClientStateEvent.State.LOBBY));
|
||||
|
||||
// Überprüft, ob das Lobby-UI sichtbar ist
|
||||
Spatial playerLobby = app.getGuiNode().getChild("PlayerLobby");
|
||||
assertNotNull("Die Spielerlobby sollte nach dem Beitritt sichtbar sein", playerLobby);
|
||||
*/
|
||||
@Test
|
||||
// T011: UC-game-11 - Testet, ob der hostende Spieler einen Startbetrag eingeben kann
|
||||
public void testEnterStartingCapital() {
|
||||
Spatial startingCapitalField = app.getGuiNode().getChild("StartingCapitalField");
|
||||
assertNotNull("Das Eingabefeld für den Startbetrag sollte existieren", startingCapitalField);
|
||||
int startingCapital = 1500;
|
||||
logic.setStartingCapital(startingCapital);
|
||||
|
||||
if (startingCapitalField instanceof TextField) {
|
||||
TextField startingCapitalInput = (TextField) startingCapitalField;
|
||||
startingCapitalInput.setText("1500");
|
||||
|
||||
assertEquals("Der eingegebene Startbetrag sollte '1500' sein", "1500", startingCapitalInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'StartingCapitalField' ist kein TextField-Objekt.");
|
||||
}
|
||||
assertEquals("The starting capital should be correctly set.", startingCapital, logic.getStartingCapital());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T012: UC-game-12 - Testet, ob der Spieler den Startbetrag um 100 € erhöhen kann
|
||||
public void testIncreaseStartingCapital() {
|
||||
Spatial increaseButton = app.getGuiNode().getChild("IncreaseCapitalButton");
|
||||
assertNotNull("Der 'Erhöhen'-Button sollte existieren", increaseButton);
|
||||
logic.setStartingCapital(1500);
|
||||
logic.increaseStartingCapital();
|
||||
|
||||
if (increaseButton instanceof Button) {
|
||||
Button increaseCapitalButton = (Button) increaseButton;
|
||||
increaseCapitalButton.click();
|
||||
|
||||
Spatial startingCapitalField = app.getGuiNode().getChild("StartingCapitalField");
|
||||
if (startingCapitalField instanceof TextField) {
|
||||
TextField startingCapitalInput = (TextField) startingCapitalField;
|
||||
assertEquals("Der Startbetrag sollte um 100 erhöht worden sein", "1600", startingCapitalInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'StartingCapitalField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'IncreaseCapitalButton' ist kein Button-Objekt.");
|
||||
}
|
||||
assertEquals("The starting capital should increase by 100.", 1600, logic.getStartingCapital());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T013: UC-game-13 - Testet, ob der Spieler den Startbetrag um 100 € senken kann
|
||||
public void testDecreaseStartingCapital() {
|
||||
Spatial decreaseButton = app.getGuiNode().getChild("DecreaseCapitalButton");
|
||||
assertNotNull("Der 'Senken'-Button sollte existieren", decreaseButton);
|
||||
logic.setStartingCapital(1500);
|
||||
logic.decreaseStartingCapital();
|
||||
|
||||
if (decreaseButton instanceof Button) {
|
||||
Button decreaseCapitalButton = (Button) decreaseButton;
|
||||
decreaseCapitalButton.click();
|
||||
|
||||
Spatial startingCapitalField = app.getGuiNode().getChild("StartingCapitalField");
|
||||
if (startingCapitalField instanceof TextField) {
|
||||
TextField startingCapitalInput = (TextField) startingCapitalField;
|
||||
assertEquals("Der Startbetrag sollte um 100 gesenkt worden sein", "1400", startingCapitalInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'StartingCapitalField' ist kein TextField-Objekt.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'DecreaseCapitalButton' ist kein Button-Objekt.");
|
||||
}
|
||||
assertEquals("The starting capital should decrease by 100.", 1400, logic.getStartingCapital());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T014: UC-game-14 - Testet, ob die Standard-Spielernamen korrekt voreingestellt sind
|
||||
public void testDefaultPlayerName() {
|
||||
Spatial playerNameField = app.getGuiNode().getChild("PlayerNameField");
|
||||
assertNotNull("Das Eingabefeld für den Spielernamen sollte existieren", playerNameField);
|
||||
logic.addPlayer("Player 1");
|
||||
|
||||
if (playerNameField instanceof TextField) {
|
||||
TextField playerNameInput = (TextField) playerNameField;
|
||||
assertEquals("Der voreingestellte Spielername sollte 'Spieler 1' sein", "Spieler 1", playerNameInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'PlayerNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
assertTrue("The player name should be correctly set.", logic.getPlayerNames().contains("Player 1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
// T015: UC-game-15 - Testet, ob der Spieler einen Anzeigenamen eingeben kann
|
||||
public void testEnterDisplayName() {
|
||||
Spatial displayNameField = app.getGuiNode().getChild("DisplayNameField");
|
||||
assertNotNull("Das Eingabefeld für den Anzeigenamen sollte existieren", displayNameField);
|
||||
String displayName = "JohnDoe";
|
||||
logic.setPlayerName(displayName);
|
||||
|
||||
if (displayNameField instanceof TextField) {
|
||||
TextField displayNameInput = (TextField) displayNameField;
|
||||
displayNameInput.setText("MaxMustermann");
|
||||
|
||||
assertEquals("Der eingegebene Anzeigename sollte 'MaxMustermann' sein", "MaxMustermann", displayNameInput.getText());
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'DisplayNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
assertEquals("The display name should be correctly set.", displayName, logic.getPlayerName());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T016: UC-game-16 - Testet, ob eine Warnung angezeigt wird, wenn ein Spieler einen bereits belegten Namen eingibt
|
||||
public void testDuplicateNameEntry() {
|
||||
Spatial playerNameField = app.getGuiNode().getChild("PlayerNameField");
|
||||
assertNotNull("Das Eingabefeld für den Spielernamen sollte existieren", playerNameField);
|
||||
logic.addPlayer("Player 1");
|
||||
boolean result = logic.addPlayer("Player 1");
|
||||
|
||||
if (playerNameField instanceof TextField) {
|
||||
TextField playerNameInput = (TextField) playerNameField;
|
||||
playerNameInput.setText("Spieler 1");
|
||||
app.getGuiNode().getChild("AddPlayerButton").click(); // Spieler hinzufügen
|
||||
playerNameInput.setText("Spieler 1");
|
||||
app.getGuiNode().getChild("AddPlayerButton").click(); // Spieler mit gleichem Namen hinzufügen
|
||||
|
||||
Spatial warning = app.getGuiNode().getChild("DuplicateNameWarning");
|
||||
assertNotNull("Es sollte eine Warnung angezeigt werden, wenn ein Name doppelt vergeben wird", warning);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'PlayerNameField' ist kein TextField-Objekt.");
|
||||
}
|
||||
assertTrue("Duplicate names should not be allowed.", !result);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T017: UC-game-17 - Testet, ob der Spieler eine verfügbare Spielfigurfarbe auswählen kann
|
||||
public void testSelectPlayerColor() {
|
||||
Spatial colorSelector = app.getGuiNode().getChild("ColorSelector");
|
||||
assertNotNull("Der Farbwähler sollte existieren", colorSelector);
|
||||
logic.addPlayer("Player 1");
|
||||
boolean result = logic.setPlayerColor("Player 1", "Red");
|
||||
|
||||
if (colorSelector instanceof Button) {
|
||||
Button colorButton = (Button) colorSelector;
|
||||
colorButton.click();
|
||||
|
||||
Spatial selectedColor = app.getGuiNode().getChild("SelectedColor");
|
||||
assertNotNull("Die gewählte Farbe sollte sichtbar sein", selectedColor);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'ColorSelector' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T018: UC-game-18 - Testet, ob eine belegte Spielfigurfarbe nicht ausgewählt werden kann
|
||||
public void testSelectOccupiedColor() {
|
||||
app.getGuiNode().getChild("ColorSelectorRed").click(); // Spieler 1 wählt Rot
|
||||
app.getGuiNode().getChild("AddPlayerButton").click(); // Spieler 1 hinzufügen
|
||||
|
||||
app.getGuiNode().getChild("ColorSelectorRed").click(); // Spieler 2 versucht Rot zu wählen
|
||||
Spatial warning = app.getGuiNode().getChild("ColorOccupiedWarning");
|
||||
assertNotNull("Es sollte eine Warnung angezeigt werden, wenn eine belegte Farbe ausgewählt wird", warning);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T019: UC-game-19 - Testet, ob der Spieler eine Spielfigur auswählen kann
|
||||
public void testSelectPlayerToken() {
|
||||
Spatial tokenSelector = app.getGuiNode().getChild("TokenSelector");
|
||||
assertNotNull("Der Token-Wähler sollte existieren", tokenSelector);
|
||||
|
||||
if (tokenSelector instanceof Button) {
|
||||
Button tokenButton = (Button) tokenSelector;
|
||||
tokenButton.click();
|
||||
|
||||
Spatial selectedToken = app.getGuiNode().getChild("SelectedToken");
|
||||
assertNotNull("Die gewählte Spielfigur sollte sichtbar sein", selectedToken);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'TokenSelector' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T020: UC-game-20 - Testet, ob eine belegte Spielfigur nicht ausgewählt werden kann
|
||||
public void testSelectOccupiedToken() {
|
||||
app.getGuiNode().getChild("TokenSelectorShip").click();
|
||||
app.getGuiNode().getChild("AddPlayerButton").click();
|
||||
|
||||
app.getGuiNode().getChild("TokenSelectorShip").click();
|
||||
Spatial warning = app.getGuiNode().getChild("TokenOccupiedWarning");
|
||||
assertNotNull("Es sollte eine Warnung angezeigt werden, wenn eine belegte Spielfigur ausgewählt wird", warning);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T021: UC-game-14 - Überprüft, ob der Spieler zur „Spiel erstellen“-Ansicht zurückkehrt, wenn Abbrechen gedrückt wird
|
||||
public void testCancelPlayerLobby() {
|
||||
Spatial cancelButtonSpatial = app.getGuiNode().getChild("CancelLobbyButton");
|
||||
assertNotNull("Der 'Abbrechen'-Button in der Lobby sollte existieren", cancelButtonSpatial);
|
||||
|
||||
if (cancelButtonSpatial instanceof Button) {
|
||||
Button cancelButton = (Button) cancelButtonSpatial;
|
||||
cancelButton.click();
|
||||
|
||||
Spatial mainMenu = app.getGuiNode().getChild("MainMenu");
|
||||
assertNotNull("Das Hauptmenü sollte nach dem Abbrechen der Lobby sichtbar sein", mainMenu);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'CancelLobbyButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T022: UC-game-15 - Überprüft, ob das Spielmenü in der Lobby durch Drücken der ESC-Taste geöffnet wird
|
||||
public void testOpenLobbyMenuWithESC() {
|
||||
app.escape(true); // Simuliert das Drücken der ESC-Taste
|
||||
|
||||
Spatial lobbyMenu = app.getGuiNode().getChild("LobbyMenu");
|
||||
assertNotNull("Das Lobby-Menü sollte sichtbar sein, nachdem ESC in der Lobby gedrückt wurde", lobbyMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T023: UC-game-16 - Testet, ob der Spieler die Auswahl der Spielfigur bestätigen kann
|
||||
public void testPlayerReadyConfirmation() {
|
||||
Spatial confirmButtonSpatial = app.getGuiNode().getChild("ConfirmTokenButton");
|
||||
assertNotNull("Der 'Bestätigen'-Button für die Spielfigur sollte existieren", confirmButtonSpatial);
|
||||
|
||||
if (confirmButtonSpatial instanceof Button) {
|
||||
Button confirmButton = (Button) confirmButtonSpatial;
|
||||
confirmButton.click();
|
||||
|
||||
Spatial readyStatus = app.getGuiNode().getChild("PlayerReadyStatus");
|
||||
assertNotNull("Der Status 'Bereit' sollte angezeigt werden, nachdem die Spielfigur bestätigt wurde", readyStatus);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'ConfirmTokenButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
@Test
|
||||
// T024: UC-game-16 - Überprüft, ob das Spiel startet, wenn alle Spieler ihre Auswahl bestätigt haben
|
||||
public void testAllPlayersReady() {
|
||||
app.receivedEvent(new pp.monopoly.notification.ClientStateEvent(pp.monopoly.notification.ClientStateEvent.State.ALL_PLAYERS_READY));
|
||||
|
||||
Spatial gameScreen = app.getGuiNode().getChild("GameScreen");
|
||||
assertNotNull("Das Spiel sollte starten, wenn alle Spieler bereit sind", gameScreen);
|
||||
}
|
||||
@Test
|
||||
// T025: UC-game-17 - Testet, ob das Einstellungen-Menü während des Spiels geöffnet wird
|
||||
public void testOpenMainGameSettings () {
|
||||
app.escape(true);
|
||||
|
||||
Spatial settingsButton = app.getGuiNode().getChild("SettingsButton");
|
||||
assertNotNull("Der 'Einstellungen'-Button sollte im Spielmenü vorhanden sein", settingsButton);
|
||||
|
||||
if (settingsButton instanceof Button) {
|
||||
((Button) settingsButton).click();
|
||||
Spatial settingsMenu = app.getGuiNode().getChild("SettingsMenu");
|
||||
assertNotNull("Das Einstellungen-Menü sollte im Spiel angezeigt werden", settingsMenu);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("'SettingsButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T026: UC-gameplay-01 - Überprüft, ob der Spieler erfolgreich würfeln kann
|
||||
public void testRollDice() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click(); // Simuliert einen Würfelwurf
|
||||
Spatial diceResult = app.getGuiNode().getChild("DiceResult");
|
||||
assertNotNull("Das Ergebnis des Würfelwurfs sollte angezeigt werden", diceResult);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
// T027: UC-gameplay-01 - Überprüft, ob der aktive Spieler die richtige Anzahl an Feldern basierend auf dem Wurf bewegt
|
||||
public void testMovePlayerAutomatically() {
|
||||
Game game = new Game(); // Initialisiert ein neues Spiel
|
||||
PlayerHandler playerHandler = game.getPlayerHandler(); // Holt den PlayerHandler, der die Spieler verwaltet
|
||||
|
||||
Player activePlayer = playerHandler.getActivePlayer(); // Holt den aktuellen aktiven Spieler
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
DiceResult diceResult = game.rollDice(); // Würfelwurf simulieren
|
||||
int steps = diceResult.getTotal();
|
||||
|
||||
int initialPosition = activePlayer.getFieldId(); // Ursprüngliche Position des aktiven Spielers
|
||||
playerHandler.moveActivePlayer(steps); // Bewegt den aktiven Spieler basierend auf dem Wurf
|
||||
|
||||
int expectedPosition = (initialPosition + steps) % game.getGameBoard().getNumberOfFields(); // Zielposition berechnen
|
||||
int newPosition = activePlayer.getFieldId();
|
||||
|
||||
assertEquals("Der aktive Spieler sollte sich korrekt bewegen", expectedPosition, newPosition);
|
||||
|
||||
// Überprüfen, dass alle anderen Spieler im WaitForTurn-State bleiben
|
||||
playerHandler.getPlayers().stream()
|
||||
.filter(player -> player != activePlayer)
|
||||
.forEach(player -> assertTrue("Andere Spieler sollten im WaitForTurn-State sein", player.getState() instanceof WaitForTurnState));
|
||||
}
|
||||
|
||||
@Test
|
||||
// T028: UC-gameplay-02 - Überprüft, ob die Würfel zufällige Zahlen generieren
|
||||
public void testGenerationDice() {
|
||||
boolean isRandom = false;
|
||||
DiceResult previousResult = null;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
DiceResult currentResult = app.getGame().rollDice();
|
||||
|
||||
assertNotNull("Das Würfelergebnis sollte nicht null sein", currentResult);
|
||||
assertTrue("Die Würfelzahl 1 sollte zwischen 1 und 6 liegen", currentResult.getDice1() >= 1 && currentResult.getDice1() <= 6);
|
||||
assertTrue("Die Würfelzahl 2 sollte zwischen 1 und 6 liegen", currentResult.getDice2() >= 1 && currentResult.getDice2() <= 6);
|
||||
|
||||
if (previousResult != null && (currentResult.getDice1() != previousResult.getDice1() || currentResult.getDice2() != previousResult.getDice2())) {
|
||||
isRandom = true; // Unterschiedliche Würfelwerte gefunden
|
||||
break;
|
||||
}
|
||||
previousResult = currentResult;
|
||||
}
|
||||
assertTrue("Die Würfelergebnisse sollten zufällig sein", isRandom);
|
||||
}
|
||||
|
||||
@Test
|
||||
// T029: UC-gameplay-03 - Überprüft, ob die richtigen Augenzahlen angezeigt werden
|
||||
public void testDisplayResults() {
|
||||
DiceResult result = app.getGame().rollDice();
|
||||
|
||||
assertNotNull("Das Würfelergebnis sollte nicht null sein", result);
|
||||
assertTrue("Die Würfelzahl 1 sollte zwischen 1 und 6 liegen", result.getDice1() >= 1 && result.getDice1() <= 6);
|
||||
assertTrue("Die Würfelzahl 2 sollte zwischen 1 und 6 liegen", result.getDice2() >= 1 && result.getDice2() <= 6);
|
||||
assertEquals("Die Summe sollte korrekt berechnet werden", result.getDice1() + result.getDice2(), result.getTotal());
|
||||
}
|
||||
@Test
|
||||
// T030: UC-gameplay-04 - Überprüfen, ob die Summe der Würfelergebnisse korrekt berechnet wird
|
||||
public void testSumDiceResults() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click(); // Simuliert einen Würfelwurf
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
assertNotNull("Die Ergebnisse des Würfelwurfs sollten angezeigt werden", diceResult1);
|
||||
assertNotNull("Die Ergebnisse des Würfelwurfs sollten angezeigt werden", diceResult2);
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
int expectedSum = result1 + result2;
|
||||
|
||||
Spatial sumDisplay = app.getGuiNode().getChild("DiceSum");
|
||||
assertEquals("Die Summe der Würfelergebnisse sollte korrekt angezeigt werden", expectedSum, Integer.parseInt(sumDisplay.getUserData("value").toString()));
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T031: UC-gameplay-05 - Überprüfen, ob die Würfel nach dem Wurf ausgegraut werden
|
||||
public void testGrayOutDiceAfterRoll() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click(); // Simuliert einen Würfelwurf
|
||||
|
||||
Spatial diceDisplay = app.getGuiNode().getChild("DiceDisplay");
|
||||
assertNotNull("Die Würfelanzeige sollte nach dem Wurf sichtbar sein", diceDisplay);
|
||||
|
||||
boolean isGrayedOut = diceDisplay.getUserData("grayedOut");
|
||||
assertTrue("Die Würfel sollten nach dem Wurf ausgegraut sein", isGrayedOut);
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T032: UC-gameplay-06 - Überprüfen, ob das Würfeln eines Paschs erkannt wird
|
||||
public void testDetectDouble() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
// Simuliert mehrere Würfe, um einen Pasch zu erkennen
|
||||
for (int i = 0; i < 10; i++) {
|
||||
((Button) rollDiceButton).click();
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
|
||||
if (result1 == result2) {
|
||||
Spatial doubleIndicator = app.getGuiNode().getChild("DoubleIndicator");
|
||||
assertNotNull("Ein Pasch sollte angezeigt werden, wenn zwei identische Zahlen geworfen werden", doubleIndicator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T033: UC-gameplay-06 - Überprüfen, ob der Spieler bei einem Pasch erneut würfeln darf
|
||||
public void testDoubleRoll() {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
// Simuliert das Würfeln eines Paschs
|
||||
((Button) rollDiceButton).click();
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
|
||||
if (result1 == result2) { // Überprüft, ob ein Pasch geworfen wurde
|
||||
Spatial rollAgainIndicator = app.getGuiNode().getChild("RollAgainIndicator");
|
||||
assertNotNull("Der Spieler sollte bei einem Pasch erneut würfeln dürfen", rollAgainIndicator);
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// T034: UC-gameplay-06 - Überprüfen, ob der Spieler nach dem dritten Pasch ins Gefängnis muss
|
||||
public void testTripleDoubleGulag() {
|
||||
int doubleCount = 0;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Spatial rollDiceButton = app.getGuiNode().getChild("RollDiceButton");
|
||||
assertNotNull("Der 'Würfeln'-Button sollte sichtbar sein", rollDiceButton);
|
||||
|
||||
if (rollDiceButton instanceof Button) {
|
||||
((Button) rollDiceButton).click();
|
||||
Spatial diceResult1 = app.getGuiNode().getChild("DiceResult1");
|
||||
Spatial diceResult2 = app.getGuiNode().getChild("DiceResult2");
|
||||
|
||||
int result1 = Integer.parseInt(diceResult1.getUserData("value").toString());
|
||||
int result2 = Integer.parseInt(diceResult2.getUserData("value").toString());
|
||||
|
||||
if (result1 == result2) {
|
||||
doubleCount++;
|
||||
}
|
||||
|
||||
if (doubleCount == 3) {
|
||||
Spatial jailIndicator = app.getGuiNode().getChild("JailIndicator");
|
||||
assertNotNull("Der Spieler sollte nach dem dritten Pasch ins Gefängnis gehen", jailIndicator);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("'RollDiceButton' ist kein Button-Objekt.");
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Der Spieler sollte drei Paschs geworfen haben", doubleCount == 3);
|
||||
}
|
||||
@Test
|
||||
// T035: UC-gameplay-07 - Überprüfen, ob ein Spieler für Steuerfelder korrekt belastet wird
|
||||
public void testTaxFieldCharges() {
|
||||
Game game = new Game();
|
||||
PlayerHandler playerHandler = game.getPlayerHandler();
|
||||
Player activePlayer = playerHandler.getActivePlayer();
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
int initialBalance = activePlayer.getAccountBalance();
|
||||
|
||||
activePlayer.moveToField(game.getGameBoard().getFieldById(4)); // ID 4: Steuerfeld "Diszi"
|
||||
game.getGameBoard().applyFieldEffect(activePlayer);
|
||||
|
||||
int expectedBalance = initialBalance - 200; // Beispielsteuer: 200 €
|
||||
assertEquals("Der Spieler sollte für das Steuerfeld korrekt belastet werden", expectedBalance, activePlayer.getAccountBalance());
|
||||
}
|
||||
|
||||
@Test
|
||||
// T036: UC-gameplay-08 - Überprüfen, ob ein Spieler korrekt ins Gefängnis geschickt wird
|
||||
public void testGoToJailField() {
|
||||
Game game = new Game();
|
||||
PlayerHandler playerHandler = game.getPlayerHandler();
|
||||
Player activePlayer = playerHandler.getActivePlayer();
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
activePlayer.moveToField(game.getGameBoard().getFieldById(30)); // ID 30: Ab ins Gefängnis
|
||||
game.getGameBoard().applyFieldEffect(activePlayer);
|
||||
|
||||
assertEquals("Der Spieler sollte ins Gefängnis geschickt werden", 10, activePlayer.getFieldId()); // ID 10: Gefängnis
|
||||
}
|
||||
|
||||
@Test
|
||||
// T037: UC-gameplay-09 - Überprüfen, ob ein Spieler bei "Frei Parken" keine Gebühren zahlt
|
||||
public void testFreeParking() {
|
||||
Game game = new Game();
|
||||
PlayerHandler playerHandler = game.getPlayerHandler();
|
||||
Player activePlayer = playerHandler.getActivePlayer();
|
||||
assertNotNull("Es sollte einen aktiven Spieler geben", activePlayer);
|
||||
|
||||
int initialBalance = activePlayer.getAccountBalance();
|
||||
|
||||
activePlayer.moveToField(game.getGameBoard().getFieldById(20)); // ID 20: Frei Parken
|
||||
game.getGameBoard().applyFieldEffect(activePlayer);
|
||||
|
||||
assertEquals("Der Spieler sollte bei 'Frei Parken' keine Gebühren zahlen", initialBalance, activePlayer.getAccountBalance());
|
||||
assertTrue("The player should be able to select an available color.", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user