mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-04-17 12:40:59 +02:00
Compare commits
No commits in common. "7f6011720ca7eac9004d34165881eecb83a16282" and "29cc73e83b11828aa57383320449254f32710e74" have entirely different histories.
7f6011720c
...
29cc73e83b
@ -68,7 +68,7 @@ public class ChoosePartner extends Dialog {
|
|||||||
// Add buttons
|
// Add buttons
|
||||||
mainContainer.addChild(createButtonContainer());
|
mainContainer.addChild(createButtonContainer());
|
||||||
|
|
||||||
addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged);
|
addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged);
|
||||||
|
|
||||||
// Attach main container to GUI node
|
// Attach main container to GUI node
|
||||||
app.getGuiNode().attachChild(mainContainer);
|
app.getGuiNode().attachChild(mainContainer);
|
||||||
@ -104,7 +104,6 @@ public class ChoosePartner extends Dialog {
|
|||||||
dimens2.setX( dimens.getX() );
|
dimens2.setX( dimens.getX() );
|
||||||
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3));
|
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3));
|
||||||
playerSelector.setLocalTranslation(0,0,5);
|
playerSelector.setLocalTranslation(0,0,5);
|
||||||
onDropdownSelectionChanged(playerOptions.get(0));
|
|
||||||
|
|
||||||
return dropdownContainer;
|
return dropdownContainer;
|
||||||
}
|
}
|
||||||
@ -205,13 +204,13 @@ public class ChoosePartner extends Dialog {
|
|||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
if (selectionRef.update()) {
|
if (selectionRef.update()) {
|
||||||
String selected = selectionRef.get().toString();
|
String selected = selectionRef.get().toString();
|
||||||
|
System.out.println(selected);
|
||||||
listener.onSelectionChanged(selected);
|
listener.onSelectionChanged(selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initialize(Application app) {
|
protected void initialize(Application app) {
|
||||||
update(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -234,6 +233,7 @@ public class ChoosePartner extends Dialog {
|
|||||||
* Callback for when the dropdown selection changes.
|
* Callback for when the dropdown selection changes.
|
||||||
*/
|
*/
|
||||||
private void onDropdownSelectionChanged(String selected) {
|
private void onDropdownSelectionChanged(String selected) {
|
||||||
|
System.out.println("Selected: " + selected);
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
int idStart = selected.indexOf("(ID: ") + 5; // Find start of the ID
|
int idStart = selected.indexOf("(ID: ") + 5; // Find start of the ID
|
||||||
int idEnd = selected.indexOf(")", idStart); // Find end of the ID
|
int idEnd = selected.indexOf(")", idStart); // Find end of the ID
|
||||||
@ -245,6 +245,9 @@ public class ChoosePartner extends Dialog {
|
|||||||
|
|
||||||
if (selectedPlayer != null) {
|
if (selectedPlayer != null) {
|
||||||
tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler
|
tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler
|
||||||
|
System.out.println("Receiver set to: " + selectedPlayer.getName() + " (ID: " + selectedPlayer.getId() + ")");
|
||||||
|
} else {
|
||||||
|
System.err.println("Player with ID " + playerId + " not found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
playerInputField = new TextField("Spieler "+(app.getId()+1));
|
playerInputField = new TextField("Spieler "+app.getId()+1);
|
||||||
// Hintergrundbild laden und hinzufügen
|
// Hintergrundbild laden und hinzufügen
|
||||||
addBackgroundImage();
|
addBackgroundImage();
|
||||||
|
|
||||||
@ -120,8 +120,6 @@ public class LobbyMenu extends Dialog {
|
|||||||
figures.add("OOP");
|
figures.add("OOP");
|
||||||
figures.add("Handyholster");
|
figures.add("Handyholster");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Selector<String> figureDropdown = new Selector<>(figures, "glass");
|
Selector<String> figureDropdown = new Selector<>(figures, "glass");
|
||||||
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
||||||
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
|
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
|
||||||
@ -130,8 +128,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize();
|
Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize();
|
||||||
dimens2.setX( dimens.getX() );
|
dimens2.setX( dimens.getX() );
|
||||||
figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5));
|
figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5));
|
||||||
figureDropdown.getSelectionModel().setSelection(0);
|
|
||||||
figure = "Laptop";
|
|
||||||
|
|
||||||
addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);
|
addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);
|
||||||
|
|
||||||
@ -163,7 +160,6 @@ public class LobbyMenu extends Dialog {
|
|||||||
readyButton.addClickCommands(s -> ifTopDialog(() -> {
|
readyButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
toggleReady();
|
toggleReady();
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
|
||||||
}));
|
}));
|
||||||
lowerRightMenu.addChild(readyButton);
|
lowerRightMenu.addChild(readyButton);
|
||||||
|
|
||||||
@ -242,6 +238,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
if (selectionRef.update()) {
|
if (selectionRef.update()) {
|
||||||
String selected = selectionRef.get().toString();
|
String selected = selectionRef.get().toString();
|
||||||
|
System.out.println(selected);
|
||||||
listener.onSelectionChanged(selected);
|
listener.onSelectionChanged(selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,6 +267,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
* Callback for when the dropdown selection changes.
|
* Callback for when the dropdown selection changes.
|
||||||
*/
|
*/
|
||||||
private void onDropdownSelectionChanged(String selected) {
|
private void onDropdownSelectionChanged(String selected) {
|
||||||
|
System.out.println("Selected: " + selected);
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
switch (selected) {
|
switch (selected) {
|
||||||
case "[0]":
|
case "[0]":
|
||||||
|
@ -223,6 +223,7 @@ public class Toolbar extends Dialog implements GameEventListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||||
|
System.out.println("pdate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -235,6 +236,7 @@ public class Toolbar extends Dialog implements GameEventListener{
|
|||||||
icon2.setIconSize(new Vector2f(100, 100));
|
icon2.setIconSize(new Vector2f(100, 100));
|
||||||
imageLabel.setIcon(icon1);
|
imageLabel.setIcon(icon1);
|
||||||
imageLabel2.setIcon(icon2);
|
imageLabel2.setIcon(icon2);
|
||||||
|
System.out.println("Dice images set");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String diceToString(int i) {
|
private String diceToString(int i) {
|
||||||
|
@ -30,10 +30,6 @@ public class TradeMenu extends Dialog {
|
|||||||
private final Button tradeButton = new Button("Handeln");
|
private final Button tradeButton = new Button("Handeln");
|
||||||
private Container lowerLeftMenu, lowerRightMenu;
|
private Container lowerLeftMenu, lowerRightMenu;
|
||||||
private TextField leftSelectionsField;
|
private TextField leftSelectionsField;
|
||||||
private TextField rightSelectionsField;
|
|
||||||
private TextField leftCurrencyInput;
|
|
||||||
private TextField rightCurrencyInput;
|
|
||||||
|
|
||||||
QuadBackgroundComponent translucentWhiteBackground =
|
QuadBackgroundComponent translucentWhiteBackground =
|
||||||
new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White));
|
new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White));
|
||||||
|
|
||||||
@ -67,7 +63,7 @@ public class TradeMenu extends Dialog {
|
|||||||
7
|
7
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
//TODO Logik
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a container for the header with a fixed size.
|
* Creates a container for the header with a fixed size.
|
||||||
@ -113,34 +109,24 @@ public class TradeMenu extends Dialog {
|
|||||||
leftSelectionsField = middleSection.addChild(new TextField(""));
|
leftSelectionsField = middleSection.addChild(new TextField(""));
|
||||||
leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); // Larger width to fit the split sections
|
leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); // Larger width to fit the split sections
|
||||||
|
|
||||||
addCustomSelectionListener(leftBuildingSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
// Add listeners to update the TextField dynamically
|
||||||
addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
addCustomSelectionListener(leftBuildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField));
|
||||||
// Add change listener for the currency input
|
addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField));
|
||||||
monitorTextFieldChanges(leftCurrencyInput, () -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Label arrows = middleSection.addChild(new Label("⇅"));
|
Label arrows = middleSection.addChild(new Label("⇅"));
|
||||||
arrows.setFontSize(40);
|
arrows.setFontSize(40);
|
||||||
|
|
||||||
// Right Column
|
|
||||||
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
|
|
||||||
|
|
||||||
|
|
||||||
// Add combined label
|
// Add combined label
|
||||||
middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
|
middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
|
||||||
middleLabel.setFontSize(24); // Adjust font size as needed
|
middleLabel.setFontSize(24); // Adjust font size as needed
|
||||||
middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label
|
middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label
|
||||||
|
|
||||||
// Add the Zielobjekte TextField
|
TextField rightSelectionsField = middleSection.addChild(new TextField("Zielobjekte..."));
|
||||||
rightSelectionsField = middleSection.addChild(new TextField(""));
|
|
||||||
rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
|
|
||||||
|
|
||||||
addCustomSelectionListener(rightBuildingSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
|
||||||
addCustomSelectionListener(rightSpecialCardSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
|
||||||
|
|
||||||
// Add change listener for the currency input
|
|
||||||
monitorTextFieldChanges(rightCurrencyInput, () -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
|
||||||
|
|
||||||
|
|
||||||
// "Bestätigen" button
|
// "Bestätigen" button
|
||||||
lowerRightMenu = new Container();
|
lowerRightMenu = new Container();
|
||||||
tradeButton.setPreferredSize(new Vector3f(200, 60, 0));
|
tradeButton.setPreferredSize(new Vector3f(200, 60, 0));
|
||||||
@ -158,6 +144,9 @@ public class TradeMenu extends Dialog {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Right Column
|
||||||
|
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
|
||||||
|
|
||||||
Label spacer = middleSection.addChild(new Label("")); // Spacer
|
Label spacer = middleSection.addChild(new Label("")); // Spacer
|
||||||
spacer.setPreferredSize(new Vector3f(1, 50, 0));
|
spacer.setPreferredSize(new Vector3f(1, 50, 0));
|
||||||
|
|
||||||
@ -200,7 +189,10 @@ public class TradeMenu extends Dialog {
|
|||||||
if (isLeft) {
|
if (isLeft) {
|
||||||
leftBuildingSelector = buildingSelector;
|
leftBuildingSelector = buildingSelector;
|
||||||
leftSpecialCardSelector = specialCardSelector;
|
leftSpecialCardSelector = specialCardSelector;
|
||||||
leftCurrencyInput = currencyInput;
|
|
||||||
|
// Add listeners for left selectors to update the middle text field
|
||||||
|
addCustomSelectionListener(buildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField));
|
||||||
|
addCustomSelectionListener(specialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField));
|
||||||
|
|
||||||
// "Abbrechen" button
|
// "Abbrechen" button
|
||||||
lowerLeftMenu = new Container();
|
lowerLeftMenu = new Container();
|
||||||
@ -208,12 +200,12 @@ public class TradeMenu extends Dialog {
|
|||||||
cancelButton.setFontSize(30);
|
cancelButton.setFontSize(30);
|
||||||
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
this.close();
|
close();
|
||||||
}));
|
}));
|
||||||
lowerLeftMenu.addChild(cancelButton);
|
lowerLeftMenu.addChild(cancelButton);
|
||||||
|
|
||||||
// Position the container near the bottom-left corner
|
// Position the container near the bottom-left corner
|
||||||
lowerLeftMenu.setLocalTranslation(new Vector3f(50, 100, 8)); // Adjust X and Y to align with the bottom-left corner
|
lowerLeftMenu.setLocalTranslation(new Vector3f(70, 100, 8)); // Adjust X and Y to align with the bottom-left corner
|
||||||
app.getGuiNode().attachChild(lowerLeftMenu);
|
app.getGuiNode().attachChild(lowerLeftMenu);
|
||||||
|
|
||||||
Label spacer = column.addChild(new Label("")); // Spacer
|
Label spacer = column.addChild(new Label("")); // Spacer
|
||||||
@ -222,7 +214,6 @@ public class TradeMenu extends Dialog {
|
|||||||
} else {
|
} else {
|
||||||
rightBuildingSelector = buildingSelector;
|
rightBuildingSelector = buildingSelector;
|
||||||
rightSpecialCardSelector = specialCardSelector;
|
rightSpecialCardSelector = specialCardSelector;
|
||||||
rightCurrencyInput = currencyInput;
|
|
||||||
|
|
||||||
Label spacer = column.addChild(new Label("")); // Spacer
|
Label spacer = column.addChild(new Label("")); // Spacer
|
||||||
spacer.setPreferredSize(new Vector3f(1, 130, 0));
|
spacer.setPreferredSize(new Vector3f(1, 130, 0));
|
||||||
@ -256,50 +247,26 @@ public class TradeMenu extends Dialog {
|
|||||||
app.getGuiNode().attachChild(background);
|
app.getGuiNode().attachChild(background);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String truncateText(String text, int maxLength) {
|
private void updateLeftSelectionsField(TextField leftSelectionsField) {
|
||||||
return text.length() > maxLength ? text.substring(0, maxLength) + "..." : text;
|
// Get all selections from the leftBuildingSelector and leftSpecialCardSelector
|
||||||
}
|
String buildingSelections = leftBuildingSelector.getSelectedItem() != null
|
||||||
|
? leftBuildingSelector.getSelectedItem()
|
||||||
private void updateSelectionsField(TextField selectionsField, Selector<String> buildingSelector, TextField currencyInput, Selector<String> specialCardSelector) {
|
: "";
|
||||||
// Get selections from the building selector
|
String specialCardSelections = leftSpecialCardSelector.getSelectedItem() != null
|
||||||
String buildingSelections = buildingSelector != null && buildingSelector.getSelectedItem() != null
|
? leftSpecialCardSelector.getSelectedItem()
|
||||||
? buildingSelector.getSelectedItem().trim()
|
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
// Get text from the currency input
|
// Get the direct input from the middle part of the TextField
|
||||||
String currencySelections = currencyInput != null
|
String manualInput = leftSelectionsField.getText();
|
||||||
? currencyInput.getText().trim()
|
|
||||||
: "";
|
|
||||||
|
|
||||||
// Get selections from the special card selector
|
// Combine all parts into one formatted string
|
||||||
String specialCardSelections = specialCardSelector != null && specialCardSelector.getSelectedItem() != null
|
String combinedText = String.format("%-30s %-30s %-30s", buildingSelections, manualInput, specialCardSelections);
|
||||||
? specialCardSelector.getSelectedItem().trim()
|
|
||||||
: "";
|
|
||||||
// Build the combined text without adding unnecessary spaces
|
|
||||||
StringBuilder combinedText = new StringBuilder();
|
|
||||||
|
|
||||||
if (!buildingSelections.isEmpty()) {
|
|
||||||
combinedText.append(buildingSelections);
|
|
||||||
}
|
|
||||||
if (!currencySelections.isEmpty()) {
|
|
||||||
if (combinedText.length() > 0) {
|
|
||||||
combinedText.append(" | "); // Add a separator if there's already text
|
|
||||||
}
|
|
||||||
combinedText.append(currencySelections);
|
|
||||||
}
|
|
||||||
if (!specialCardSelections.isEmpty()) {
|
|
||||||
if (combinedText.length() > 0) {
|
|
||||||
combinedText.append(" | "); // Add a separator if there's already text
|
|
||||||
}
|
|
||||||
combinedText.append(specialCardSelections);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the content of the TextField
|
// Update the content of the TextField
|
||||||
selectionsField.setText(combinedText.toString());
|
leftSelectionsField.setText(combinedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the escape action for the dialog.
|
* Handles the escape action for the dialog.
|
||||||
*/
|
*/
|
||||||
@ -354,29 +321,4 @@ public class TradeMenu extends Dialog {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void monitorTextFieldChanges(TextField textField, Runnable onChange) {
|
|
||||||
VersionedReference<DocumentModel> ref = textField.getDocumentModel().createReference();
|
|
||||||
|
|
||||||
app.getStateManager().attach(new BaseAppState() {
|
|
||||||
@Override
|
|
||||||
public void update(float tpf) {
|
|
||||||
if (ref.update()) {
|
|
||||||
onChange.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initialize(Application app) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cleanup(Application app) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEnable() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDisable() {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
||||||
} else {
|
} else {
|
||||||
clientSender.send(msg);
|
clientSender.send(msg);
|
||||||
|
System.out.println("Message gesendet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +216,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
@Override
|
@Override
|
||||||
public void received(DiceResult msg) {
|
public void received(DiceResult msg) {
|
||||||
playSound(Sound.DICE_ROLL);
|
playSound(Sound.DICE_ROLL);
|
||||||
|
System.out.println("Message kam an");
|
||||||
notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1)));
|
notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,6 +344,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
@Override
|
@Override
|
||||||
public void received(NextPlayerTurn msg) {
|
public void received(NextPlayerTurn msg) {
|
||||||
|
|
||||||
|
System.out.println("Du bsit am zug message empfangen");
|
||||||
setState(new ActiveState(this));
|
setState(new ActiveState(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,6 +395,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
* @return the result of a dice roll (1 to 6)
|
* @return the result of a dice roll (1 to 6)
|
||||||
*/
|
*/
|
||||||
private static int rollDice() {
|
private static int rollDice() {
|
||||||
|
System.out.println("Gewuerfelt");
|
||||||
return random.nextInt(6) + 1;
|
return random.nextInt(6) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,7 @@ public class PlayerHandler {
|
|||||||
public Player getPlayerById(int id) {
|
public Player getPlayerById(int id) {
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
if (player.getId() == id) return player;
|
if (player.getId() == id) return player;
|
||||||
|
System.out.println(player.getId());
|
||||||
}
|
}
|
||||||
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
|
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
|
|
||||||
playerHandler.addPlayer(player);
|
playerHandler.addPlayer(player);
|
||||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||||
|
System.out.println("Anzahl Spieler verbunden:"+ playerHandler.getPlayerCount());
|
||||||
|
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
@ -220,6 +221,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
public void received(RollDice msg, int from) {
|
public void received(RollDice msg, int from) {
|
||||||
Player player = playerHandler.getPlayerById(from);
|
Player player = playerHandler.getPlayerById(from);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
|
System.out.println("Ergebniss gesendet");
|
||||||
send(player, player.rollDice());
|
send(player, player.rollDice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,10 +104,10 @@ public class TradeHandler {
|
|||||||
*/
|
*/
|
||||||
public boolean initiateTrade() {
|
public boolean initiateTrade() {
|
||||||
if (!validateTrade()) {
|
if (!validateTrade()) {
|
||||||
|
System.out.println("Trade offer is invalid.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
System.out.println("Trade initiated by " + sender.getName() + " to " + receiver.getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,14 +138,14 @@ public class TradeHandler {
|
|||||||
transferJailCards(sender, receiver, offeredJailCards);
|
transferJailCards(sender, receiver, offeredJailCards);
|
||||||
transferJailCards(receiver, sender, requestedJailCards);
|
transferJailCards(receiver, sender, requestedJailCards);
|
||||||
|
|
||||||
|
System.out.println("Trade completed between " + sender.getName() + " and " + receiver.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rejects the trade.
|
* Rejects the trade.
|
||||||
*/
|
*/
|
||||||
public void rejectTrade() {
|
public void rejectTrade() {
|
||||||
|
System.out.println(receiver.getName() + " rejected the trade.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,13 +156,13 @@ public class TradeHandler {
|
|||||||
private boolean validateTrade() {
|
private boolean validateTrade() {
|
||||||
// Validate sender's ability to offer money
|
// Validate sender's ability to offer money
|
||||||
if (sender.getAccountBalance() < offeredAmount) {
|
if (sender.getAccountBalance() < offeredAmount) {
|
||||||
|
System.out.println("Sender does not have enough money to offer.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate receiver's ability to fulfill the requested amount
|
// Validate receiver's ability to fulfill the requested amount
|
||||||
if (receiver.getAccountBalance() < requestedAmount) {
|
if (receiver.getAccountBalance() < requestedAmount) {
|
||||||
|
System.out.println("Receiver does not have enough money to fulfill the request.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class TradeHandler {
|
|||||||
if (offeredProperties != null) {
|
if (offeredProperties != null) {
|
||||||
for (PropertyField property : offeredProperties) {
|
for (PropertyField property : offeredProperties) {
|
||||||
if (!sender.getProperties().contains(property)) {
|
if (!sender.getProperties().contains(property)) {
|
||||||
|
System.out.println("Sender does not own property: " + property.getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ public class TradeHandler {
|
|||||||
if (requestedProperties != null) {
|
if (requestedProperties != null) {
|
||||||
for (PropertyField property : requestedProperties) {
|
for (PropertyField property : requestedProperties) {
|
||||||
if (!receiver.getProperties().contains(property)) {
|
if (!receiver.getProperties().contains(property)) {
|
||||||
|
System.out.println("Receiver does not own property: " + property.getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,11 +186,11 @@ public class TradeHandler {
|
|||||||
|
|
||||||
// Validate jail cards
|
// Validate jail cards
|
||||||
if (sender.getNumJailCard() < offeredJailCards) {
|
if (sender.getNumJailCard() < offeredJailCards) {
|
||||||
|
System.out.println("Sender does not have enough jail cards to offer.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (receiver.getNumJailCard() < requestedJailCards) {
|
if (receiver.getNumJailCard() < requestedJailCards) {
|
||||||
|
System.out.println("Receiver does not have enough jail cards to fulfill the request.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ public class TradeHandler {
|
|||||||
from.sellProperty(property);
|
from.sellProperty(property);
|
||||||
to.buyProperty(property);
|
to.buyProperty(property);
|
||||||
property.setOwner(to);
|
property.setOwner(to);
|
||||||
|
System.out.println("Property " + property.getName() + " transferred from " + from.getName() + " to " + to.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,7 +223,7 @@ public class TradeHandler {
|
|||||||
from.removeJailCard();
|
from.removeJailCard();
|
||||||
to.addJailCard();
|
to.addJailCard();
|
||||||
}
|
}
|
||||||
|
System.out.println(numCards + " jail card(s) transferred from " + from.getName() + " to " + to.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOfferedAmount(int offeredAmount) {
|
public void setOfferedAmount(int offeredAmount) {
|
||||||
|
@ -147,6 +147,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(HostedConnection source, Message message) {
|
public void messageReceived(HostedConnection source, Message message) {
|
||||||
|
System.out.println("Message recieved");
|
||||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||||
if (message instanceof ClientMessage clientMessage)
|
if (message instanceof ClientMessage clientMessage)
|
||||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||||
@ -156,6 +157,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS
|
LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS
|
||||||
logic.addPlayer(hostedConnection.getId());
|
logic.addPlayer(hostedConnection.getId());
|
||||||
|
System.out.println("Spieler verbunden: ID = " + hostedConnection.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user