mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-07-31 09:27:42 +02:00
Merge branch 'gui' of https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02 into gui
This commit is contained in:
@@ -307,8 +307,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
public void received(TradeReply msg) {
|
||||
if (msg.isAccepted()) {
|
||||
playSound(Sound.TRADE_ACCEPTED);
|
||||
notifyListeners(new PopUpEvent("tradepos", msg));
|
||||
} else {
|
||||
playSound(Sound.TRADE_REJECTED);
|
||||
notifyListeners(new PopUpEvent("tradeneg", msg));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,6 +349,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
notifyListeners(new PopUpEvent(msg.getKeyWord(), msg));
|
||||
} else if(msg.getKeyWord().equals("NoMoneyWarning")) {
|
||||
notifyListeners(new PopUpEvent("NoMoneyWarning", msg));
|
||||
} else if (msg.getKeyWord().equals("jailpay")) {
|
||||
notifyListeners(new PopUpEvent("jailpay", msg));
|
||||
} else if (msg.getKeyWord().equals("jailtryagain")) {
|
||||
notifyListeners(new PopUpEvent("jailtryagain", msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -140,6 +140,9 @@ public class Player implements FieldVisitor<Void>{
|
||||
System.out.println("State: "+state.getClass().getName());
|
||||
if(!(state instanceof JailState)) {
|
||||
state = new ActiveState();
|
||||
} else {
|
||||
String message = (((JailState)state).remainingAttempts <= 0) ? "jailpay" : "jailtryagain";
|
||||
handler.getLogic().send(this, new NotificationMessage(message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,7 +442,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
public void moveToJail() {
|
||||
setPosition(10); // Jail position on the board
|
||||
state = new JailState();
|
||||
System.out.println("JAIL EVENT");
|
||||
handler.getLogic().send(this, new JailEvent(true));
|
||||
}
|
||||
|
||||
@@ -481,6 +483,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
return total;
|
||||
}
|
||||
|
||||
// private static int c = 0;
|
||||
/**
|
||||
* Inner class for dice functionality in the game.
|
||||
* Rolls random dice values.
|
||||
@@ -495,7 +498,13 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
private static int rollDice() {
|
||||
return random.nextInt(6) + 1;
|
||||
// return 3;
|
||||
|
||||
// c++;
|
||||
// if(c < 7) {
|
||||
// return 3;
|
||||
// } else {
|
||||
// return (c%4)+1;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,12 +621,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
state = new ActiveState();
|
||||
} else {
|
||||
remainingAttempts--;
|
||||
if (remainingAttempts <= 0) {
|
||||
handler.getLogic().send(Player.this, new NotificationMessage("jailpay"));
|
||||
if(getOutOfJailCard == 0) payBail();
|
||||
} else {
|
||||
handler.getLogic().send(Player.this, new NotificationMessage("jailtryagain"));
|
||||
}
|
||||
}
|
||||
System.out.println("Feld:"+fieldID);
|
||||
return rollResult;
|
||||
|
@@ -234,10 +234,10 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(RollDice msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null) {
|
||||
if (player != null && player == playerHandler.getPlayerAtIndex(0)) {
|
||||
send(player, player.rollDice());
|
||||
updateAllPlayers();
|
||||
}
|
||||
updateAllPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,6 +357,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
private void updateAllPlayers() {
|
||||
for (Player player : playerHandler.getPlayers()) {
|
||||
send(player, new PlayerStatusUpdate(playerHandler));
|
||||
send(player, new ViewAssetsResponse(boardManager));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,27 +382,32 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public void received(AlterProperty msg, int from) {
|
||||
Player sender = playerHandler.getPlayerById(from);
|
||||
|
||||
Set<PropertyField> properties = new HashSet<>();
|
||||
for (Integer integer : msg.getProperties()) {
|
||||
properties.add( (PropertyField)boardManager.getFieldAtIndex(integer));
|
||||
}
|
||||
|
||||
if (msg.getKeyword().equals("TakeMortage")) {
|
||||
for (PropertyField field : sender.getPropertyFields()) {
|
||||
for (PropertyField field : properties) {
|
||||
field.setMortgaged(true);
|
||||
sender.earnMoney(field.getHypo());
|
||||
}
|
||||
} else if (msg.getKeyword().equals("RepayMortage")) {
|
||||
for (PropertyField field : sender.getPropertyFields()) {
|
||||
for (PropertyField field : properties) {
|
||||
if(sender.getAccountBalance() >= field.getHypo()) {
|
||||
field.setMortgaged(false);
|
||||
sender.pay(field.getHypo());
|
||||
}
|
||||
}
|
||||
} else if(msg.getKeyword().equals("BuyHouse")) {
|
||||
for (BuildingProperty field : sender.getPropertyFields().stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
|
||||
for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
|
||||
if (boardManager.canBuild(field) && sender.getAccountBalance() >= field.getHousePrice()) {
|
||||
field.build();
|
||||
sender.pay(field.getHousePrice());
|
||||
}
|
||||
}
|
||||
} else if(msg.getKeyword().equals("SellHouse")) {
|
||||
for (BuildingProperty field : sender.getPropertyFields().stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
|
||||
for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
|
||||
if (boardManager.canSell(field)) {
|
||||
field.sell();
|
||||
sender.earnMoney(field.getHousePrice());
|
||||
@@ -414,10 +420,16 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
@Override
|
||||
public void received(NotificationAnswer msg, int from) {
|
||||
if(msg.getKeyword().equals("UseJailCard")) {
|
||||
if(msg.getA().equals("UseJailCard")) {
|
||||
playerHandler.getPlayerById(from).useJailCard();
|
||||
} else if (msg.getKeyword().equals("PayJail")) {
|
||||
} else if (msg.getA().equals("PayJail")) {
|
||||
playerHandler.getPlayerById(from).payBail();
|
||||
} else if(msg.getA().equals("hack")) {
|
||||
for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
|
||||
bp.setOwner(playerHandler.getPlayerById(0));
|
||||
playerHandler.getPlayerById(0).addProperty(bp.getId());
|
||||
}
|
||||
playerHandler.getPlayerAtIndex(0).earnMoney(20000);
|
||||
}
|
||||
|
||||
updateAllPlayers();
|
||||
|
@@ -5,16 +5,16 @@ import com.jme3.network.serializing.Serializable;
|
||||
@Serializable
|
||||
public class NotificationAnswer extends ClientMessage{
|
||||
|
||||
private String keyword;
|
||||
private String A;
|
||||
|
||||
private NotificationAnswer() {}
|
||||
|
||||
public NotificationAnswer(String keyword) {
|
||||
this.keyword = keyword;
|
||||
public NotificationAnswer(String A) {
|
||||
this.A = A;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
public String getA() {
|
||||
return A;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -130,7 +130,7 @@ public class BoardManager {
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Check if the player owns all properties in the color group
|
||||
if (!groupProperties.stream().allMatch(bp -> bp.getOwner() != null && bp.getOwner().equals(field.getOwner()))) {
|
||||
if (!groupProperties.stream().allMatch(bp -> bp.getOwner() != null && bp.getOwner().getId() == field.getOwner().getId())) {
|
||||
return false; // The player must own all properties in the color group
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import pp.monopoly.game.server.Player;
|
||||
@Serializable
|
||||
public class BuildingProperty extends PropertyField {
|
||||
|
||||
private int houses;
|
||||
private int houses = 2;
|
||||
private final int housePrice;
|
||||
private final FieldColor color;
|
||||
private final int rentFactor1 = 5;
|
||||
|
@@ -1,12 +1,10 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Enum representing eight distinct colors for properties in the game.
|
||||
*/
|
||||
// @Serializable
|
||||
public enum FieldColor {
|
||||
BROWN(new ColorRGBA(148 / 255f, 86 / 255f, 57 / 255f, 1)),
|
||||
GREEN(new ColorRGBA(30 / 255f, 179 / 255f, 90 / 255f, 1)),
|
||||
|
Reference in New Issue
Block a user