mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-02 20:17:11 +02:00
trigger rent popup
This commit is contained in:
@@ -14,6 +14,7 @@ import pp.monopoly.message.server.GameOver;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
import pp.monopoly.message.server.JailEvent;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.message.server.ServerInterpreter;
|
||||
import pp.monopoly.message.server.TimeOutWarning;
|
||||
@@ -233,10 +234,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(GameOver msg) {
|
||||
if (msg.isWinner()) {
|
||||
notifyListeners(new PopUpEvent("Winner"));
|
||||
notifyListeners(new PopUpEvent("Winner", msg));
|
||||
playSound(Sound.WINNER);
|
||||
} else {
|
||||
notifyListeners(new PopUpEvent("Looser"));
|
||||
notifyListeners(new PopUpEvent("Looser", msg));
|
||||
playSound(Sound.LOSER);
|
||||
}
|
||||
}
|
||||
@@ -287,7 +288,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(TimeOutWarning msg) {
|
||||
notifyListeners(new PopUpEvent("timeout"));
|
||||
notifyListeners(new PopUpEvent("timeout", msg));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,7 +323,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(TradeRequest msg) {
|
||||
tradeHandler = msg.getTradeHandler();
|
||||
notifyListeners(new PopUpEvent("tradeRequest"));
|
||||
notifyListeners(new PopUpEvent("tradeRequest", msg));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,6 +339,13 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg) {
|
||||
notifyListeners(new PopUpEvent("Buy"));
|
||||
notifyListeners(new PopUpEvent("Buy", msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(NotificationMessage msg) {
|
||||
if (msg.getKeyWord().equals("rent")) {
|
||||
notifyListeners(new PopUpEvent("rent", msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.model.FieldVisitor;
|
||||
import pp.monopoly.model.Figure;
|
||||
@@ -304,6 +305,10 @@ public class Player implements FieldVisitor<Void>{
|
||||
int rent = field.calcRent();
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
NotificationMessage msg = new NotificationMessage("rent");
|
||||
msg.setRentAmount(rent);
|
||||
msg.setRentOwnerId(field.getOwner().getName());
|
||||
getHandler().getLogic().send(this, msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -317,8 +322,13 @@ public class Player implements FieldVisitor<Void>{
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
factor = 10;
|
||||
}
|
||||
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
|
||||
pay(rollResult.calcTotal()*factor);
|
||||
int rent = rollResult.calcTotal()*factor;
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
NotificationMessage msg = new NotificationMessage("rent");
|
||||
msg.setRentAmount(rent);
|
||||
msg.setRentOwnerId(field.getOwner().getName());
|
||||
getHandler().getLogic().send(this, msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -332,6 +342,10 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
NotificationMessage msg = new NotificationMessage("rent");
|
||||
msg.setRentAmount(rent);
|
||||
msg.setRentOwnerId(field.getOwner().getName());
|
||||
getHandler().getLogic().send(this, msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -0,0 +1,50 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class NotificationMessage extends ServerMessage{
|
||||
|
||||
private final String keyWord;
|
||||
|
||||
private int rentAmount;
|
||||
private String rentOwner;
|
||||
|
||||
private NotificationMessage(){ keyWord = null;}
|
||||
|
||||
public NotificationMessage(String keyWord) {
|
||||
this.keyWord = keyWord;
|
||||
}
|
||||
|
||||
public int getRentAmount() {
|
||||
return rentAmount;
|
||||
}
|
||||
|
||||
public void setRentAmount(int rentAmount) {
|
||||
this.rentAmount = rentAmount;
|
||||
}
|
||||
|
||||
public void setRentOwnerId(String rentOwnerId) {
|
||||
this.rentOwner = rentOwnerId;
|
||||
}
|
||||
|
||||
public String getRentOwner() {
|
||||
return rentOwner;
|
||||
}
|
||||
|
||||
public String getKeyWord() {
|
||||
return keyWord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
}
|
@@ -96,4 +96,11 @@ public interface ServerInterpreter {
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(BuyPropertyRequest msg);
|
||||
|
||||
/**
|
||||
* Handles a NextPlayerTurn message received from the server.
|
||||
*
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(NotificationMessage msg);
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record PopUpEvent(String msg) implements GameEvent{
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
|
||||
public record PopUpEvent(String msg, ServerMessage message) implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
|
Reference in New Issue
Block a user