mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 21:39:44 +01:00
Merge branch 'logic' into 'gui'
# Conflicts: # Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java # Projekte/monopoly/model/src/main/java/pp/monopoly/notification/Sound.java
This commit is contained in:
commit
12c1c97a99
@ -26,7 +26,6 @@ import pp.monopoly.message.server.ServerInterpreter;
|
|||||||
import pp.monopoly.message.server.TimeOutWarning;
|
import pp.monopoly.message.server.TimeOutWarning;
|
||||||
import pp.monopoly.message.server.TradeReply;
|
import pp.monopoly.message.server.TradeReply;
|
||||||
import pp.monopoly.message.server.TradeRequest;
|
import pp.monopoly.message.server.TradeRequest;
|
||||||
import pp.monopoly.message.server.UpdatePlayerAssets;
|
|
||||||
import pp.monopoly.message.server.ViewAssetsResponse;
|
import pp.monopoly.message.server.ViewAssetsResponse;
|
||||||
import pp.monopoly.model.Board;
|
import pp.monopoly.model.Board;
|
||||||
import pp.monopoly.model.IntPoint;
|
import pp.monopoly.model.IntPoint;
|
||||||
@ -38,6 +37,13 @@ import pp.monopoly.notification.InfoTextEvent;
|
|||||||
import pp.monopoly.notification.Sound;
|
import pp.monopoly.notification.Sound;
|
||||||
import pp.monopoly.notification.SoundEvent;
|
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.
|
* Controls the client-side game logic for Monopoly.
|
||||||
* Manages the player's placement, interactions with the map, and response to server messages.
|
* 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());
|
static final Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
||||||
private final ClientSender clientSender;
|
private final ClientSender clientSender;
|
||||||
private final List<GameEventListener> listeners = new ArrayList<>();
|
private final List<GameEventListener> listeners = new ArrayList<>();
|
||||||
private Board ownMap;
|
private Board board;
|
||||||
private Board harbor;
|
|
||||||
private Board opponentMap;
|
|
||||||
private ClientState state = new ClientState(this) {
|
private ClientState state = new ClientState(this) {
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -86,8 +91,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*
|
*
|
||||||
* @return the player's own map
|
* @return the player's own map
|
||||||
*/
|
*/
|
||||||
public Board getMap() {
|
public Board getBoard() {
|
||||||
return ownMap;
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,73 +188,73 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(BuyPropertyResponse msg) {
|
public void received(BuyPropertyResponse msg) {
|
||||||
// TODO Auto-generated method stub
|
if (msg.isSuccessful()) {
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
setInfoText("You successfully bought " + msg.getPropertyName() + "!");
|
||||||
|
playSound(Sound.MONEY_LOST);
|
||||||
|
} else {
|
||||||
|
setInfoText("Unable to buy " + msg.getPropertyName() + ". Reason: " + msg.getReason());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(DiceResult msg) {
|
public void received(DiceResult msg) {
|
||||||
// TODO Auto-generated method stub
|
setInfoText("You rolled a " + msg.calcTotal() + "!");
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
playSound(Sound.DICE_ROLL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(EventDrawCard msg) {
|
public void received(EventDrawCard msg) {
|
||||||
// TODO Auto-generated method stub
|
setInfoText("Event card drawn: " + msg.getCardDescription());
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
playSound(Sound.EVENT_CARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(GameOver msg) {
|
public void received(GameOver msg) {
|
||||||
// TODO Auto-generated method stub
|
if (msg.isWinner()) {
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
setInfoText("Congratulations! You have won the game!");
|
||||||
|
playSound(Sound.WINNER);
|
||||||
|
} else {
|
||||||
|
setInfoText("Game over. Better luck next time!");
|
||||||
|
playSound(Sound.LOSER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(GameStart msg) {
|
public void received(GameStart msg) {
|
||||||
// TODO Auto-generated method stub
|
setInfoText("The game has started! Good luck!");
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(JailEvent msg) {
|
public void received(JailEvent msg) {
|
||||||
// TODO Auto-generated method stub
|
if (msg.isGoingToJail()) {
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
setInfoText("You are sent to jail!");
|
||||||
|
playSound(Sound.GULAG);
|
||||||
|
} else {
|
||||||
|
setInfoText("You are out of jail!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(PlayerStatusUpdate msg) {
|
public void received(PlayerStatusUpdate msg) {
|
||||||
// TODO Auto-generated method stub
|
setInfoText("Player " + msg.getPlayerName() + " status updated: " + msg.getStatus());
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(TimeOutWarning msg) {
|
public void received(TimeOutWarning msg) {
|
||||||
// TODO Auto-generated method stub
|
setInfoText("Warning! Time is running out. You have " + msg.getRemainingTime() + " seconds left.");
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void received(UpdatePlayerAssets msg) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(ViewAssetsResponse msg) {
|
public void received(ViewAssetsResponse msg) {
|
||||||
// TODO Auto-generated method stub
|
setInfoText("Your current assets are being displayed.");
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(TradeReply msg) {
|
public void received(TradeReply msg) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(TradeRequest msg) {
|
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;
|
package pp.monopoly.message.server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the server's response to a player's request to buy a property.
|
||||||
|
*/
|
||||||
public class BuyPropertyResponse extends ServerMessage{
|
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
|
@Override
|
||||||
public void accept(ServerInterpreter interpreter) {
|
public void accept(ServerInterpreter interpreter) {
|
||||||
// TODO Auto-generated method stub
|
interpreter.received(this);
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'accept'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -13,5 +36,4 @@ public class BuyPropertyResponse extends ServerMessage{
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package pp.monopoly.message.server;
|
package pp.monopoly.message.server;
|
||||||
|
|
||||||
public class EventDrawCard extends ServerMessage{
|
public class EventDrawCard extends ServerMessage{
|
||||||
|
private final String cardDescription;
|
||||||
|
|
||||||
|
public EventDrawCard(String cardDescription) {
|
||||||
|
this.cardDescription = cardDescription;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ServerInterpreter interpreter) {
|
public void accept(ServerInterpreter interpreter) {
|
||||||
@ -13,4 +18,8 @@ public class EventDrawCard extends ServerMessage{
|
|||||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCardDescription() {
|
||||||
|
return cardDescription;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
package pp.monopoly.message.server;
|
package pp.monopoly.message.server;
|
||||||
|
|
||||||
public class GameOver extends ServerMessage{
|
public class GameOver extends ServerMessage{
|
||||||
|
private final boolean isWinner;
|
||||||
|
|
||||||
|
public GameOver(boolean isWinner) {
|
||||||
|
this.isWinner = isWinner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWinner() {
|
||||||
|
return isWinner;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ServerInterpreter interpreter) {
|
public void accept(ServerInterpreter interpreter) {
|
||||||
|
@ -2,6 +2,16 @@ package pp.monopoly.message.server;
|
|||||||
|
|
||||||
public class JailEvent extends ServerMessage{
|
public class JailEvent extends ServerMessage{
|
||||||
|
|
||||||
|
private final boolean goingToJail;
|
||||||
|
|
||||||
|
public JailEvent(boolean goingToJail) {
|
||||||
|
this.goingToJail = goingToJail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGoingToJail() {
|
||||||
|
return goingToJail;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ServerInterpreter interpreter) {
|
public void accept(ServerInterpreter interpreter) {
|
||||||
interpreter.received(this);
|
interpreter.received(this);
|
||||||
|
@ -1,7 +1,31 @@
|
|||||||
package pp.monopoly.message.server;
|
package pp.monopoly.message.server;
|
||||||
|
|
||||||
|
import pp.monopoly.game.server.PlayerColor;
|
||||||
|
|
||||||
public class PlayerStatusUpdate extends ServerMessage{
|
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
|
@Override
|
||||||
public void accept(ServerInterpreter interpreter) {
|
public void accept(ServerInterpreter interpreter) {
|
||||||
interpreter.received(this);
|
interpreter.received(this);
|
||||||
|
@ -69,13 +69,6 @@ public interface ServerInterpreter {
|
|||||||
*/
|
*/
|
||||||
void received(TimeOutWarning msg);
|
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.
|
* Handles a ViewAssetsResponse message received from the server.
|
||||||
*
|
*
|
||||||
|
@ -2,6 +2,16 @@ package pp.monopoly.message.server;
|
|||||||
|
|
||||||
public class TimeOutWarning extends ServerMessage{
|
public class TimeOutWarning extends ServerMessage{
|
||||||
|
|
||||||
|
private final int remainingTime;
|
||||||
|
|
||||||
|
public TimeOutWarning(int remainingTime) {
|
||||||
|
this.remainingTime = remainingTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRemainingTime() {
|
||||||
|
return remainingTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ServerInterpreter interpreter) {
|
public void accept(ServerInterpreter interpreter) {
|
||||||
interpreter.received(this);
|
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{
|
public class ViewAssetsResponse extends ServerMessage{
|
||||||
|
|
||||||
private List<PropertyField> properties;
|
private final List<PropertyField> properties;
|
||||||
private int accountBalance;
|
private final int accountBalance;
|
||||||
private int jailCards;
|
private final int jailCards;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ViewAssetsResponse with the specified properties and account balance.
|
* Constructs a ViewAssetsResponse with the specified properties and account balance.
|
||||||
|
@ -1,20 +1,61 @@
|
|||||||
package pp.monopoly.notification;
|
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 {
|
public enum Sound {
|
||||||
CLICK("click_sound.wav"),
|
/**
|
||||||
WIN("win_sound.wav"),
|
* UC-sound-01: Sound effect for passing the start/Los field.
|
||||||
LOSE("lose_sound.wav");
|
*/
|
||||||
|
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;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user