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. "b67379a6c3959a9744d09e9115b9407acdd4e22d" and "12e859edd54c4f900a3251d5f2968bbea34c3ec2" have entirely different histories.
b67379a6c3
...
12e859edd5
@ -10,18 +10,10 @@ import com.jme3.scene.shape.Box;
|
||||
import com.jme3.texture.Texture;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.popups.BuyCard;
|
||||
import pp.monopoly.client.gui.popups.EventCard;
|
||||
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.model.fields.FoodField;
|
||||
import pp.monopoly.model.fields.GateField;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.EventCardEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.PopUpEvent;
|
||||
|
||||
/**
|
||||
* TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat.
|
||||
@ -109,22 +101,4 @@ public class TestWorld implements GameEventListener{
|
||||
public void receivedEvent(EventCardEvent event) {
|
||||
new EventCard(app, event.description()).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(PopUpEvent event) {
|
||||
System.err.println("Trigger ?");
|
||||
// if (event.desc() == "BuyCard") {
|
||||
int field = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
|
||||
Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field);
|
||||
|
||||
if (fieldObject instanceof BuildingProperty) {
|
||||
new BuyCard(app).open();
|
||||
} else if (fieldObject instanceof GateField){
|
||||
new GateFieldCard(app).open();
|
||||
} else if (fieldObject instanceof FoodField) {
|
||||
new FoodFieldCard(app).open();
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.notification.Sound;
|
||||
@ -64,7 +64,6 @@ public class BuyCard extends Dialog {
|
||||
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
System.err.println("Button does something?");
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}));
|
||||
@ -73,8 +72,7 @@ public class BuyCard extends Dialog {
|
||||
buyButton.setFontSize(32);
|
||||
buyButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
app.getGameLogic().send(new BuyPropertyResponse());
|
||||
app.getGameLogic().send(new BuyPropertyRequest());
|
||||
}));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
|
@ -9,6 +9,7 @@ import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
@ -71,12 +72,14 @@ public class ConfirmTrade extends Dialog {
|
||||
negotiateButton.setFontSize(32);
|
||||
negotiateButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.getGameLogic().send(new BuyPropertyRequest());
|
||||
}));
|
||||
// Kaufen-Button
|
||||
Button confirmButton = confirmTradeContainer.addChild(new Button("Bestätigen", new ElementId("button"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
|
||||
confirmButton.setFontSize(32);
|
||||
confirmButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.getGameLogic().send(new BuyPropertyRequest());
|
||||
}));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
|
@ -14,7 +14,7 @@ import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.model.fields.FoodField;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
@ -83,7 +83,7 @@ public class FoodFieldCard extends Dialog {
|
||||
buyButton.setFontSize(32);
|
||||
buyButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.getGameLogic().send(new BuyPropertyResponse());
|
||||
app.getGameLogic().send(new BuyPropertyRequest());
|
||||
}));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
|
@ -13,7 +13,7 @@ import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.model.fields.GateField;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
@ -78,7 +78,7 @@ public class GateFieldCard extends Dialog {
|
||||
buyButton.setFontSize(32);
|
||||
buyButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.getGameLogic().send(new BuyPropertyResponse());
|
||||
app.getGameLogic().send(new BuyPropertyRequest());
|
||||
close();
|
||||
}));
|
||||
|
||||
|
@ -12,7 +12,7 @@ import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
@ -76,7 +76,7 @@ public class SellHouse extends Dialog {
|
||||
confirmButton.setFontSize(32);
|
||||
confirmButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
//TODO
|
||||
app.getGameLogic().send(new BuyPropertyRequest());
|
||||
}));
|
||||
|
||||
|
||||
|
@ -7,7 +7,6 @@ import java.util.List;
|
||||
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.GameOver;
|
||||
@ -31,7 +30,6 @@ import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.InfoTextEvent;
|
||||
import pp.monopoly.notification.PopUpEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.notification.SoundEvent;
|
||||
import pp.monopoly.notification.UpdatePlayerView;
|
||||
@ -331,9 +329,4 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
notifyListeners(new ButtonStatusEvent(true));
|
||||
setState(new ActiveState(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg) {
|
||||
notifyListeners(new PopUpEvent());
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import java.util.Random;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
@ -41,7 +40,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
private String name;
|
||||
private int accountBalance = 15000;
|
||||
private Figure figure;
|
||||
private transient List<PropertyField> properties = new ArrayList<>();
|
||||
private List<PropertyField> properties = new ArrayList<>();
|
||||
private int getOutOfJailCard;
|
||||
private int fieldID;
|
||||
private DiceResult rollResult;
|
||||
@ -163,14 +162,11 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
public int movePos(int position){
|
||||
fieldID = fieldID+position;
|
||||
System.out.println("Aktuelle Position" +fieldID);
|
||||
System.err.println("Würfelergebniss"+ rollResult.calcTotal());
|
||||
if(fieldID >= 40) {
|
||||
fieldID = fieldID%40;
|
||||
earnMoney(2000);
|
||||
}
|
||||
figure.moveTo(fieldID);
|
||||
getHandler().getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
|
||||
return fieldID;
|
||||
}
|
||||
@ -303,41 +299,30 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
@Override
|
||||
public Void visit(BuildingProperty field) {
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else if (field.getOwner() != this){
|
||||
int rent = field.calcRent();
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
}
|
||||
int rent = field.calcRent();
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(FoodField field) {
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else {
|
||||
int factor = 4;
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
factor = 10;
|
||||
}
|
||||
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
|
||||
pay(rollResult.calcTotal()*factor);
|
||||
int factor = 4;
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
factor = 10;
|
||||
}
|
||||
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
|
||||
pay(rollResult.calcTotal()*factor);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GateField field) {
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else {
|
||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
}
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -390,7 +375,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
public int getNumProp(PropertyField field) {
|
||||
int count = 0;
|
||||
if (properties.isEmpty()) return 0;
|
||||
for (PropertyField propertyField : properties) {
|
||||
if (propertyField.getClass() == field.getClass()) {
|
||||
count++;
|
||||
@ -492,8 +476,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
public DiceResult rollDice() {
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
System.out.println(rollResult.calcTotal());
|
||||
move(rollResult.calcTotal());
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.client.EndTurn;
|
||||
import pp.monopoly.message.client.PlayerReady;
|
||||
@ -144,14 +144,19 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@Override
|
||||
public void received(BuyPropertyResponse msg, int from) {
|
||||
public void received(BuyPropertyRequest msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null) {
|
||||
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.getFieldID()); // Assuming player position for property
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.move(0)); // Assuming player position for property
|
||||
|
||||
player.buyProperty(property);
|
||||
System.out.println("Properties:" +player.getProperties().toString());
|
||||
LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName());
|
||||
if (property.getOwner() == null && player.getAccountBalance() >= property.getPrice()) {
|
||||
player.buyProperty(property);
|
||||
property.setOwner(player);
|
||||
player.earnMoney(-property.getPrice());
|
||||
LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName());
|
||||
} else {
|
||||
LOGGER.log(Level.WARNING, "Player {0} cannot buy property {1}", player.getName(), property.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,14 @@ import com.jme3.network.serializing.Serializable;
|
||||
* Represents a request from a player to buy a property.
|
||||
*/
|
||||
@Serializable
|
||||
public class BuyPropertyResponse extends ClientMessage{
|
||||
public class BuyPropertyRequest extends ClientMessage{
|
||||
|
||||
/**
|
||||
* Constructs a BuyPropertyRequest with the specified property ID.
|
||||
*
|
||||
* @param propertyId the ID of the property to buy
|
||||
*/
|
||||
public BuyPropertyResponse() {}
|
||||
public BuyPropertyRequest() {}
|
||||
|
||||
|
||||
@Override
|
@ -17,7 +17,7 @@ public interface ClientInterpreter {
|
||||
* @param msg the BuyPropertyRequest to be processed
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
void received(BuyPropertyResponse msg, int from);
|
||||
void received(BuyPropertyRequest msg, int from);
|
||||
|
||||
/**
|
||||
* Processes a received EndTurn.
|
||||
|
@ -1,21 +0,0 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class BuyPropertyRequest extends ServerMessage{
|
||||
|
||||
public BuyPropertyRequest(){}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
}
|
@ -89,11 +89,4 @@ public interface ServerInterpreter {
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(NextPlayerTurn msg);
|
||||
|
||||
/**
|
||||
* Handles a NextPlayerTurn message received from the server.
|
||||
*
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(BuyPropertyRequest msg);
|
||||
}
|
||||
|
@ -73,11 +73,4 @@ public interface GameEventListener {
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(ButtonStatusEvent event) { /*Do nothing */}
|
||||
|
||||
/**
|
||||
* Indicates that all buttons in the toolbar should be disabled
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(PopUpEvent event) { /*Do nothing */}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record PopUpEvent() implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
|
||||
}
|
@ -29,7 +29,7 @@ import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.game.server.ServerGameLogic;
|
||||
import pp.monopoly.game.server.ServerSender;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.client.EndTurn;
|
||||
import pp.monopoly.message.client.PlayerReady;
|
||||
@ -37,7 +37,6 @@ import pp.monopoly.message.client.RollDice;
|
||||
import pp.monopoly.message.client.TradeOffer;
|
||||
import pp.monopoly.message.client.TradeResponse;
|
||||
import pp.monopoly.message.client.ViewAssetsRequest;
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
@ -121,7 +120,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
|
||||
private void initializeSerializables() {
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(BuyPropertyResponse.class);
|
||||
Serializer.registerClass(BuyPropertyRequest.class);
|
||||
Serializer.registerClass(EndTurn.class);
|
||||
Serializer.registerClass(PlayerReady.class);
|
||||
@ -141,7 +139,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, BuyPropertyResponse.class);
|
||||
myServer.addMessageListener(this, BuyPropertyRequest.class);
|
||||
myServer.addMessageListener(this, EndTurn.class);
|
||||
myServer.addMessageListener(this, PlayerReady.class);
|
||||
myServer.addMessageListener(this, RollDice.class);
|
||||
|
Loading…
Reference in New Issue
Block a user