lobby übergibt namen

This commit is contained in:
Yvonne Schmidt 2024-11-24 18:39:32 +01:00
parent 225a8c0e08
commit f67fa4d7f0
2 changed files with 18 additions and 1 deletions

View File

@ -42,6 +42,7 @@ public class LobbyMenu {
private PlayerHandler playerHandler; // Reference to PlayerHandler
private TextField startingCapital; // Reference to the starting capital input field
private TextField playerInputField; // Reference to the player name input field
public LobbyMenu(MonopolyApp app) {
@ -161,6 +162,7 @@ public class LobbyMenu {
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 -> applyPlayerName(playerID));
lowerRightMenu.addChild(readyButton);
// Position the container near the bottom-right corner
@ -209,6 +211,21 @@ public class LobbyMenu {
}
}
/**
* Apply the player name from the input field.
*/
private void applyPlayerName(int playerID) {
Player currentPlayer = playerHandler.getPlayerById(playerID);
String playerName = playerInputField.getText().trim();
if (!playerName.isEmpty()) {
currentPlayer.setName(playerName);
System.out.println("Player name set to: " + playerName);
} else {
System.err.println("Invalid player name: Name cannot be empty.");
}
}
/**
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
*/

View File

@ -84,7 +84,7 @@ public class Player implements FieldVisitor<Void>{
* Set the name of the Player
* @param name the new name
*/
void setName(String name) {
public void setName(String name) {
this.name = name;
}