diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index fa28b52..f972be6 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -26,7 +26,6 @@ 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.Board; import pp.monopoly.model.IntPoint; @@ -38,6 +37,13 @@ import pp.monopoly.notification.InfoTextEvent; import pp.monopoly.notification.Sound; import pp.monopoly.notification.SoundEvent; +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; + /** * Controls the client-side game logic for Monopoly. * Manages the player's placement, interactions with the map, and response to server messages. @@ -46,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 listeners = new ArrayList<>(); - private Board ownMap; - private Board harbor; - private Board opponentMap; + private Board board; + private ClientState state = new ClientState(this) { }; @@ -86,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; } /** @@ -183,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'"); } + } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java index cd2b906..e926317 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/BuyPropertyResponse.java @@ -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'"); } - } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java index 7ed4938..968f2bb 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/EventDrawCard.java @@ -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; + } + } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java index 9b2cff3..e91041e 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameOver.java @@ -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) { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java index a802398..485a7fd 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/JailEvent.java @@ -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); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java index 8b51066..c876108 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/PlayerStatusUpdate.java @@ -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); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java index 3480d20..1f78ba7 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java @@ -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. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java index f9510a7..b862170 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/TimeOutWarning.java @@ -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); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/UpdatePlayerAssets.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/UpdatePlayerAssets.java deleted file mode 100644 index e37c78c..0000000 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/UpdatePlayerAssets.java +++ /dev/null @@ -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'"); - } - -} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java index 116366e..9a00833 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ViewAssetsResponse.java @@ -8,9 +8,9 @@ import pp.monopoly.model.fields.PropertyField; */ public class ViewAssetsResponse extends ServerMessage{ - private List properties; - private int accountBalance; - private int jailCards; + private final List properties; + private final int accountBalance; + private final int jailCards; /** * Constructs a ViewAssetsResponse with the specified properties and account balance. diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java index 6bbe2cb..9e0e3df 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java @@ -1,20 +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 { - CLICK("click_sound.wav"), - WIN("win_sound.wav"), - LOSE("lose_sound.wav"); + /** + * UC-sound-01: Sound effect for passing the start/Los field. + */ + PASS_START, - private final String fileName; + /** + * UC-sound-02: Sound effect for drawing an event card. + */ + EVENT_CARD, - Sound(String fileName) { - this.fileName = fileName; - } + /** + * UC-sound-03: Sound effect for entering the Gulag. + */ + GULAG, - public String getFileName() { - return fileName; - } + /** + * 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; } \ No newline at end of file