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 a6e47a4..a345dcd 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 @@ -4,6 +4,7 @@ import java.lang.System.Logger; import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import com.jme3.math.Vector3f; @@ -318,10 +319,21 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { if (msg.isAdded()) { BuildingProperty property = ((BuildingProperty)boardManager.getFieldAtIndex(msg.getId())); if (property.getHotel() == 1 ) { + + for(int i = 0; i < 4; i++) { + board.remove(board.getHouse(msg.getId(), i+1)); + } + board.add(new Hotel(property.getId())); } else { board.add(new House( property.getHouses(), property.getId())); } + } else { + if( ((BuildingProperty)boardManager.getFieldAtIndex(msg.getId())).getHouses() == 4 ) { + board.remove(board.getHotel(msg.getId())); + } else { + board.remove(board.getHouse(msg.getId(), ((BuildingProperty)boardManager.getFieldAtIndex(msg.getId())).getHouses()+1)); + } } } 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 9ebf0d9..f53b154 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 @@ -454,13 +454,9 @@ public class ServerGameLogic implements ClientInterpreter { } private void generatePredefinedGameState() { - // Ensure at least two players exist - if (playerHandler.getPlayers().size() < 2) { - Player player1 = new Player(0, "Player1", playerHandler); - Player player2 = new Player(1, "Player2", playerHandler); - - playerHandler.addPlayer(player1); - playerHandler.addPlayer(player2); + + if(playerHandler.getPlayerCount() < 2) { + return; } Player p1 = playerHandler.getPlayerById(0); @@ -484,10 +480,10 @@ public class ServerGameLogic implements ClientInterpreter { assignProperties(p2, p2Properties); // Player 1 builds houses on Gym and Sportplatz - buildHouses(p1, Set.of(1, 3)); + // buildHouses(p1, Set.of(1, 3)); // Player 2 builds houses on the Red set - buildHouses(p2, Set.of(21, 23, 24)); + // buildHouses(p2, Set.of(21, 23, 24)); // Set player balances p1.setAccountBalance(12325); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Board.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Board.java index 48b037a..4650ad5 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Board.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Board.java @@ -139,6 +139,14 @@ public class Board { return getItems(House.class); } + public House getHouse(int fieldId, int stage) { + return getHouses().filter(house -> house.getFieldID() == fieldId && house.getStage() == stage).findFirst().orElse(null); + } + + public Hotel getHotel(int fieldId) { + return getHotels().filter(hotel -> hotel.getFieldID() == fieldId).findFirst().orElse(null); + } + /** * Returns a stream of all hotels currently on the map. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Hotel.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Hotel.java index b58ec25..052483f 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Hotel.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/Hotel.java @@ -96,4 +96,13 @@ public class Hotel implements Item{ // TODO return Rotation.NORTH; } + + /** + * Returns the ID of the field the hotel is on. + * + * @return the ID of the field the hotel is on + */ + public int getFieldID() { + return fieldID; + } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/House.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/House.java index 13a606e..c7ad981 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/House.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/House.java @@ -24,6 +24,15 @@ public class House implements Item{ this.fieldID = 0; } + /** + * Returns the field ID of the house. + * + * @return the field ID of the house + */ + public int getFieldID() { + return fieldID; + } + /** * Creates a new house with the given stage. * diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java index f0875a0..0caaa67 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BoardManager.java @@ -146,45 +146,47 @@ public class BoardManager { } /** - * Checks if a House can be sold on the given Property + * Checks if a House or Hotel can be sold on the given Property. + * * @param field the Property to check - * @return true if a house can be sold on the property, false otherwise + * @return true if a house or hotel can be sold on the property, false otherwise */ public boolean canSell(BuildingProperty field) { if (field == null) { return false; // Null check for safety } - + // Get the color group of the property FieldColor groupColor = field.getColor(); - + // Get all properties of the same color group List groupProperties = board.stream() .filter(f -> f instanceof BuildingProperty) .map(f -> (BuildingProperty) f) .filter(bp -> bp.getColor() == groupColor) .collect(Collectors.toList()); - + // Check if the property has houses or a hotel to sell if (field.getHouses() == 0 && field.getHotel() == 0) { return false; // No houses or hotels to sell } - + // Ensure balanced selling: You cannot sell houses unevenly in the group int currentHouses = field.getHouses(); int currentHotel = field.getHotel(); - - // If there is a hotel, selling is allowed only if all other properties have max houses + + // If there is a hotel, ensure all other properties have max houses (4) before selling it if (currentHotel > 0) { return groupProperties.stream() .allMatch(bp -> bp.getHouses() == 4 || bp.equals(field)); } - + // If there are houses, check that selling does not unbalance the group return groupProperties.stream() .allMatch(bp -> bp.getHouses() <= currentHouses); } + /** * Gibt eine Liste von BuildingProperty-Feldern zurück, auf denen Häuser oder Hotels stehen. * @return Liste von BuildingProperty-Feldern mit Gebäuden @@ -198,3 +200,10 @@ public class BoardManager { } } + +/* TODO: +- Häuser beim bau eines Hotels entfernen +- Alle texturen schwarz + + * + */