mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 04:39:43 +01:00
Compare commits
No commits in common. "9a6ce27fe13559159a298122fd12d2de0dd48e44" and "9b4cac4e56b071ca8512862c78060973d31abf5c" have entirely different histories.
9a6ce27fe1
...
9b4cac4e56
@ -41,11 +41,6 @@ public class NetworkSupport implements MessageListener<Client>, ClientStateListe
|
||||
return app;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
if (client == null) return 0;
|
||||
return client.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a connection to the game server.
|
||||
*
|
||||
@ -85,7 +80,7 @@ public class NetworkSupport implements MessageListener<Client>, ClientStateListe
|
||||
* @param port The server's port.
|
||||
* @throws IOException If an I/O error occurs when creating the client.
|
||||
*/
|
||||
public void initNetwork(String host, int port) throws IOException {
|
||||
void initNetwork(String host, int port) throws IOException {
|
||||
if (client != null) {
|
||||
throw new IllegalStateException("Already connected to the game server.");
|
||||
}
|
||||
|
@ -23,10 +23,6 @@ import com.simsilica.lemur.core.VersionedList;
|
||||
import com.simsilica.lemur.core.VersionedReference;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.game.client.ClientGameLogic;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -38,18 +34,10 @@ public class LobbyMenu {
|
||||
private Geometry circle;
|
||||
private Container lowerLeftMenu;
|
||||
private Container lowerRightMenu;
|
||||
private ColorRGBA playerColor= ColorRGBA.Gray;
|
||||
|
||||
private PlayerHandler playerHandler; // Reference to PlayerHandler
|
||||
private TextField startingCapital; // Reference to the starting capital input field
|
||||
|
||||
|
||||
public LobbyMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
this.playerHandler = ClientGameLogic.getPlayerHandler(); // Initialize PlayerHandler
|
||||
|
||||
int playerID = app.getNetworkSupport().getId(); // Retrieve the player ID dynamically
|
||||
assignPlayerColor(playerID);
|
||||
// Entfernt das CreateGameMenu (inklusive Hintergrund)
|
||||
app.getGuiNode().detachAllChildren();
|
||||
|
||||
@ -114,7 +102,6 @@ public class LobbyMenu {
|
||||
|
||||
// Figur Dropdown
|
||||
Container figureDropdownContainer = dropdownContainer.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
|
||||
figureDropdownContainer.setPreferredSize(new Vector3f(150, 80, 0));
|
||||
figureDropdownContainer.addChild(new Label("Figur:"));
|
||||
figureDropdownContainer.setBackground(null);
|
||||
|
||||
@ -128,11 +115,7 @@ public class LobbyMenu {
|
||||
|
||||
Selector<String> figureDropdown = new Selector<>(figures, "glass");
|
||||
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
||||
figureDropdown.setPreferredSize(new Vector3f(150, 140, 0));
|
||||
Vector3f dimens = figureDropdownContainer.getPreferredSize();
|
||||
Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize();
|
||||
dimens2.setX( dimens.getX() );
|
||||
figureDropdown.getPopupContainer().setPreferredSize( dimens2 );
|
||||
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
|
||||
figureDropdownContainer.addChild(figureDropdown);
|
||||
|
||||
addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);
|
||||
@ -159,8 +142,7 @@ public class LobbyMenu {
|
||||
readyButton.setPreferredSize(new Vector3f(200, 60, 0)); // Set size to match the appearance in the image
|
||||
readyButton.setFontSize(18); // Adjust font size
|
||||
readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.Green)); // Add color to match the style
|
||||
readyButton.addClickCommands(source -> toggleReady(null));// Add functionality
|
||||
readyButton.addClickCommands(source -> applyStartingCapital(playerID));
|
||||
readyButton.addClickCommands(source -> toggleReady(null)); // Add functionality
|
||||
lowerRightMenu.addChild(readyButton);
|
||||
|
||||
// Position the container near the bottom-right corner
|
||||
@ -168,7 +150,7 @@ public class LobbyMenu {
|
||||
app.getGuiNode().attachChild(lowerRightMenu);
|
||||
|
||||
// Add a colored circle between the input field and the dropdown menu
|
||||
circle = createCircle(); // 50 is the diameter, Red is the color
|
||||
circle = createCircle( ColorRGBA.Red); // 50 is the diameter, Red is the color
|
||||
circle.setLocalTranslation(new Vector3f(
|
||||
(app.getCamera().getWidth()) / 2, // Center horizontally
|
||||
(app.getCamera().getHeight() / 2) - 90, // Adjust Y position
|
||||
@ -185,29 +167,7 @@ public class LobbyMenu {
|
||||
|
||||
app.getGuiNode().attachChild(menuContainer);
|
||||
}
|
||||
/**
|
||||
* Apply the starting capital only if the current player is the host.
|
||||
*/
|
||||
private void applyStartingCapital(int playerID) {
|
||||
Player currentPlayer = playerHandler.getPlayerById(playerID);
|
||||
|
||||
// Check if the current player is the host
|
||||
if (currentPlayer.equals(playerHandler.getHostPlayer())) {
|
||||
try {
|
||||
// Parse and validate starting capital
|
||||
int startBalance = Integer.parseInt(startingCapital.getText().replaceAll("[^\\d]", ""));
|
||||
if (startBalance < 0) throw new NumberFormatException("Starting capital must be positive.");
|
||||
|
||||
// Apply the starting balance to all players
|
||||
playerHandler.setStartBalance(startBalance);
|
||||
System.out.println("Starting balance set to: " + startBalance);
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Invalid starting capital: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
System.out.println("Only the host can set the starting balance.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
|
||||
@ -224,57 +184,18 @@ public class LobbyMenu {
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
private Geometry createCircle() {
|
||||
private Geometry createCircle(ColorRGBA color) {
|
||||
|
||||
Sphere sphere = new Sphere(90,90,60.0f);
|
||||
Geometry circleGeometry = new Geometry("Circle", sphere);
|
||||
|
||||
// Create a material with a solid color
|
||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
material.setColor("Color", playerColor); // Set the desired color
|
||||
material.setColor("Color", color); // Set the desired color
|
||||
circleGeometry.setMaterial(material);
|
||||
|
||||
return circleGeometry;
|
||||
}
|
||||
public void setPlayerColor(ColorRGBA newColor) {
|
||||
this.playerColor = newColor;
|
||||
// Update the circle's color
|
||||
if (circle != null) {
|
||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
material.setColor("Color", playerColor);
|
||||
circle.setMaterial(material);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a color to the player based on their ID.
|
||||
*
|
||||
* @param playerID the player's ID
|
||||
*/
|
||||
private void assignPlayerColor(int playerID) {
|
||||
switch (playerID) {
|
||||
case 0:
|
||||
playerColor = PlayerColor.RED.getColor();
|
||||
break;
|
||||
case 1:
|
||||
playerColor = PlayerColor.GREEN_LIGHT.getColor();
|
||||
break;
|
||||
case 2:
|
||||
playerColor = PlayerColor.BLUE.getColor();
|
||||
break;
|
||||
case 3:
|
||||
playerColor = PlayerColor.PINK.getColor();
|
||||
break;
|
||||
case 4:
|
||||
playerColor = PlayerColor.GREEN_DARK.getColor();
|
||||
break;
|
||||
case 5:
|
||||
playerColor = PlayerColor.YELLOW.getColor();
|
||||
break;
|
||||
default:
|
||||
playerColor = ColorRGBA.White; // Default color if ID is unknown
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaltet den "Bereit"-Status um.
|
||||
@ -339,22 +260,16 @@ public class LobbyMenu {
|
||||
System.out.println("Selected: " + selected);
|
||||
switch (selected) {
|
||||
case "[0]":
|
||||
System.out.println("Laptop selected");
|
||||
System.out.println("Alpha selected");
|
||||
break;
|
||||
case "[1]":
|
||||
System.out.println("Flugzeug selected");
|
||||
System.out.println("Beta selected");
|
||||
break;
|
||||
case "[2]":
|
||||
System.out.println("Jägermeister selected");
|
||||
System.out.println("Gamma selected");
|
||||
break;
|
||||
case "[3]":
|
||||
System.out.println("Katze selected");
|
||||
break;
|
||||
case "[4]":
|
||||
System.out.println("OOP selected");
|
||||
break;
|
||||
case "[5]":
|
||||
System.out.println("Handyholster selected");
|
||||
goBackToCreateGame();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unknown selection");
|
||||
|
@ -51,7 +51,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
/** The current state of the client game logic. */
|
||||
private ClientState state = new LobbyState(this);
|
||||
|
||||
private static PlayerHandler playerHandler;
|
||||
private PlayerHandler playerHandler;
|
||||
|
||||
/**
|
||||
* Constructs a ClientGameLogic with the specified sender object.
|
||||
@ -83,7 +83,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
state.entry();
|
||||
}
|
||||
|
||||
public static PlayerHandler getPlayerHandler() {
|
||||
public PlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ public class PlayerHandler {
|
||||
* @param id the id to be searched for
|
||||
* @return the player with the required id
|
||||
*/
|
||||
public Player getPlayerById(int id) {
|
||||
Player getPlayerById(int id) {
|
||||
for (Player player : players) {
|
||||
if (player.getId() == id) return player;
|
||||
}
|
||||
@ -176,7 +176,7 @@ public class PlayerHandler {
|
||||
players.get(0).setActive();
|
||||
}
|
||||
|
||||
public void setStartBalance(int amount) {
|
||||
void setStartBalance(int amount) {
|
||||
for (Player player : players) {
|
||||
player.setAccountBalance(amount);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user