mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 16:07:08 +02:00
open buy popups
This commit is contained in:
@@ -7,6 +7,7 @@ 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;
|
||||
@@ -30,6 +31,7 @@ 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;
|
||||
@@ -329,4 +331,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
notifyListeners(new ButtonStatusEvent(true));
|
||||
setState(new ActiveState(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg) {
|
||||
notifyListeners(new PopUpEvent());
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ 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;
|
||||
@@ -40,7 +41,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
private String name;
|
||||
private int accountBalance = 15000;
|
||||
private Figure figure;
|
||||
private List<PropertyField> properties = new ArrayList<>();
|
||||
private transient List<PropertyField> properties = new ArrayList<>();
|
||||
private int getOutOfJailCard;
|
||||
private int fieldID;
|
||||
private DiceResult rollResult;
|
||||
@@ -162,11 +163,14 @@ 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;
|
||||
}
|
||||
@@ -299,30 +303,41 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
@Override
|
||||
public Void visit(BuildingProperty field) {
|
||||
int rent = field.calcRent();
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
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);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(FoodField field) {
|
||||
int factor = 4;
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
factor = 10;
|
||||
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);
|
||||
}
|
||||
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
|
||||
pay(rollResult.calcTotal()*factor);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GateField field) {
|
||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else {
|
||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -375,6 +390,7 @@ 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++;
|
||||
@@ -476,6 +492,8 @@ 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.BuyPropertyRequest;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.client.EndTurn;
|
||||
import pp.monopoly.message.client.PlayerReady;
|
||||
@@ -144,19 +144,14 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg, int from) {
|
||||
public void received(BuyPropertyResponse msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.move(0)); // Assuming player position for property
|
||||
if (player != null) {
|
||||
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.getFieldID()); // Assuming player position for property
|
||||
|
||||
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());
|
||||
}
|
||||
player.buyProperty(property);
|
||||
System.out.println("Properties:" +player.getProperties().toString());
|
||||
LOGGER.log(Level.INFO, "Player {0} bought 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 BuyPropertyRequest extends ClientMessage{
|
||||
public class BuyPropertyResponse extends ClientMessage{
|
||||
|
||||
/**
|
||||
* Constructs a BuyPropertyRequest with the specified property ID.
|
||||
*
|
||||
* @param propertyId the ID of the property to buy
|
||||
*/
|
||||
public BuyPropertyRequest() {}
|
||||
public BuyPropertyResponse() {}
|
||||
|
||||
|
||||
@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(BuyPropertyRequest msg, int from);
|
||||
void received(BuyPropertyResponse msg, int from);
|
||||
|
||||
/**
|
||||
* Processes a received EndTurn.
|
||||
|
@@ -0,0 +1,21 @@
|
||||
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,4 +89,11 @@ 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,4 +73,11 @@ 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 */}
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record PopUpEvent() implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user