mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 21:39:44 +01:00
client recieve message logic
This commit is contained in:
parent
951b4c198c
commit
b37a5095f0
@ -19,7 +19,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.IntPoint;
|
||||
import pp.monopoly.model.Board;
|
||||
@ -38,8 +37,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 +45,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 +84,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 +181,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'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user