diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index 71708c7..40bfc50 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -322,25 +322,29 @@ public class ServerGameLogic implements ClientInterpreter { } /** - * Executes the trade by transferring requested properties from the receiver - * to the sender and offered properties from the sender to the receiver. + * Executes a trade between two players, transferring properties and money as specified. + * + * @param sender the player initiating the trade + * @param receiver the player receiving the trade offer + * @param requestedProperties the properties requested by the receiver + * @param offeredProperties the properties offered by the sender */ - public void executeTrade(Player sender, Player receiver, Set requestedProperties, Set offeredProperties) { + private void executeTrade(Player sender, Player receiver, Set requestedProperties, Set offeredProperties) { // Transfer requested properties from receiver to sender - for (PropertyField field : requestedProperties) { + for (PropertyField field : offeredProperties) { receiver.removeProperty(field.getId()); sender.addProperty(field.getId()); field.setOwner(sender); // Update ownership - System.out.printf("Property %s transferred from %s to %s.\n", + LOGGER.log(Level.DEBUG, "Property %s transferred from %s to %s.\n", field.getName(), receiver.getName(), sender.getName()); } // Transfer offered properties from sender to receiver - for (PropertyField field : offeredProperties) { + for (PropertyField field : requestedProperties) { sender.removeProperty(field.getId()); receiver.addProperty(field.getId()); field.setOwner(receiver); // Update ownership - System.out.printf("Property %s transferred from %s to %s.\n", + LOGGER.log(Level.DEBUG, "Property %s transferred from %s to %s.\n", field.getName(), sender.getName(), receiver.getName()); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java index 03b3ce8..ceef3cb 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/TradeResponse.java @@ -28,7 +28,18 @@ public class TradeResponse extends ClientMessage{ this.tradeHandler = tradeHandler; } + /** + * Returns whether the trade was accepted. + * + * @return {@code true} if the trade was accepted, {@code false} otherwise + */ public boolean isAccepted() { return status; } + + /** + * Returns the TradeHandler corresponding to the Trade. + * + * @return the TradeHandler corresponding to the Trade + */ public TradeHandler getTradeHandler() { return tradeHandler; }