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. "9bf9e8406b4f9e764a8fa8606d220f4194c27ef3" and "5143e21ba69e7c0c6527498f5bfe32296a7391c2" have entirely different histories.
9bf9e8406b
...
5143e21ba6
@ -54,8 +54,9 @@ public class StartMenu extends Dialog {
|
||||
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
|
||||
|
||||
startButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
this.close(); // Close the StartMenu dialog
|
||||
app.connect(); // Perform the connection logic
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
centerMenu.addChild(startButton);
|
||||
|
||||
|
@ -25,7 +25,6 @@ import pp.monopoly.model.fields.GateField;
|
||||
import pp.monopoly.notification.EventCardEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.PopUpEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.notification.UpdatePlayerView;
|
||||
|
||||
/**
|
||||
@ -48,7 +47,7 @@ public class TestWorld implements GameEventListener {
|
||||
this.app = app;
|
||||
this.playerHandler = app.getGameLogic().getPlayerHandler(); // Hole den PlayerHandler
|
||||
app.getGameLogic().addListener(this);
|
||||
cameraController = new CameraController(app.getCamera()); // Übergebe PlayerHandler
|
||||
cameraController = new CameraController(app.getCamera(), playerHandler); // Übergebe PlayerHandler
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +110,7 @@ public class TestWorld implements GameEventListener {
|
||||
Player player = playerHandler.getPlayers().get(i);
|
||||
try {
|
||||
com.jme3.scene.Spatial model = app.getAssetManager().loadModel(
|
||||
"models/" + player.getFigure().getType() + "/" + player.getFigure().getType() + ".j3o"
|
||||
"Models/" + player.getFigure().getType() + "/" + player.getFigure().getType() + ".j3o"
|
||||
);
|
||||
model.setLocalScale(0.5f);
|
||||
|
||||
@ -289,7 +288,7 @@ public class TestWorld implements GameEventListener {
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 2500); // Verzögerung in Millisekunden
|
||||
}, 5000); // Verzögerung in Millisekunden
|
||||
} else if (event.msg().equals("Winner")) {
|
||||
new WinnerPopUp(app).open();
|
||||
} else if (event.msg().equals("Looser")) {
|
||||
@ -305,12 +304,9 @@ public class TestWorld implements GameEventListener {
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
app.enqueue(() -> {
|
||||
app.getGameLogic().playSound(Sound.EVENT_CARD);
|
||||
new EventCardPopup(app, event.description()).open();
|
||||
});
|
||||
app.enqueue(() -> new EventCardPopup(app, event.description()).open());
|
||||
}
|
||||
}, 2500); // 5 Sekunden Verzögerung für Event-Popups
|
||||
}, 5000); // 5 Sekunden Verzögerung für Event-Popups
|
||||
}
|
||||
|
||||
|
||||
|
@ -222,6 +222,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(EventDrawCard msg) {
|
||||
playSound(Sound.EVENT_CARD);
|
||||
notifyListeners(new EventCardEvent(msg.getCardDescription()));
|
||||
}
|
||||
|
||||
@ -264,7 +265,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
|
||||
playSound(Sound.GULAG);
|
||||
} else {
|
||||
System.out.println("NO MORE JAIL");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,9 @@ import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.client.WaitForTurnState;
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.JailEvent;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
@ -52,6 +50,8 @@ public class Player implements FieldVisitor<Void>{
|
||||
private DiceResult rollResult;
|
||||
private transient final PlayerHandler handler;
|
||||
private transient PlayerState state = new WaitForTurnState();
|
||||
private int doubletscounter = 0;
|
||||
private boolean mayRollDice = false;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
@ -136,17 +136,15 @@ public class Player implements FieldVisitor<Void>{
|
||||
public int getFieldID() {
|
||||
return fieldID;
|
||||
}
|
||||
|
||||
void setActive() {
|
||||
System.out.println("State: "+state.getClass().getName());
|
||||
if(!(state instanceof JailState)) {
|
||||
state = new ActiveState();
|
||||
}
|
||||
state = new ActiveState();
|
||||
doubletscounter = 0;
|
||||
mayRollDice = true;
|
||||
}
|
||||
|
||||
boolean finishTurn() {
|
||||
if(canFinishTurn()) {
|
||||
if (state instanceof ActiveState) state = new WaitForTurnState();
|
||||
state = new WaitForTurnState();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
@ -179,25 +177,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
* @return the new position
|
||||
*/
|
||||
public int setPosition(int position){
|
||||
if(position < 40 && position >= 0) {
|
||||
fieldID = position;
|
||||
figure.moveTo(fieldID);
|
||||
handler.getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
|
||||
}
|
||||
return fieldID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player to the specified Position on the board
|
||||
* @param position the position to move to
|
||||
* @return the new position
|
||||
*/
|
||||
public int setPositionWithMoney(int position){
|
||||
if(position < 40 && position >= 0) {
|
||||
if(position < fieldID) {
|
||||
earnMoney(2000);
|
||||
}
|
||||
if(position < 40 && position > 0) {
|
||||
fieldID = position;
|
||||
figure.moveTo(fieldID);
|
||||
handler.getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
@ -321,7 +301,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public Void visit(BuildingProperty field) {
|
||||
if(field.getOwner() == null) {
|
||||
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else if (field.getOwner() != this){
|
||||
int rent = field.calcRent();
|
||||
field.getOwner().earnMoney(rent);
|
||||
@ -337,7 +317,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public Void visit(FoodField field) {
|
||||
if(field.getOwner() == null) {
|
||||
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else {
|
||||
int factor = 4;
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
@ -357,7 +337,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public Void visit(GateField field) {
|
||||
if(field.getOwner() == null) {
|
||||
if (field.getPrice() <= accountBalance) getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else {
|
||||
int rent = field.calcRent() * field.getOwner().getNumProp(field);
|
||||
|
||||
@ -393,7 +373,8 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
@Override
|
||||
public Void visit(WacheField field) {
|
||||
moveToJail();
|
||||
setPosition(10);
|
||||
jail();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -422,14 +403,8 @@ public class Player implements FieldVisitor<Void>{
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the player to jail by setting position and state.
|
||||
*/
|
||||
public void moveToJail() {
|
||||
setPosition(10); // Jail position on the board
|
||||
public void jail() {
|
||||
state = new JailState();
|
||||
System.out.println("JAIL EVENT");
|
||||
handler.getLogic().send(this, new JailEvent(true));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -470,7 +445,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Inner class for dice functionality in the game.
|
||||
* Rolls random dice values.
|
||||
*/
|
||||
@ -487,15 +462,36 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolls two dice, handles movement logic, and checks for doublets.
|
||||
*
|
||||
* @return the DiceResult of the roll
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
return state.rollDice();
|
||||
/**
|
||||
* Rolls two dice, handles movement logic, and checks for doublets.
|
||||
*
|
||||
* @return the DiceResult of the roll
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
if (!mayRollDice) {
|
||||
throw new IllegalStateException("Player is not allowed to roll dice at this moment.");
|
||||
}
|
||||
|
||||
rollResult = state.rollDice();
|
||||
mayRollDice = false;
|
||||
|
||||
if (rollResult.isDoublets()) {
|
||||
doubletscounter++;
|
||||
mayRollDice = true; // Allow another roll for doublets
|
||||
|
||||
if (doubletscounter >= 3) {
|
||||
setPosition(10); // Send to jail on third doublet
|
||||
doubletscounter = 0; // Reset doublets counter
|
||||
} else {
|
||||
getHandler().getLogic().send(this, new NextPlayerTurn());
|
||||
}
|
||||
} else {
|
||||
doubletscounter = 0; // Reset counter if no doublets
|
||||
}
|
||||
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A interface representing the PlayerStates
|
||||
@ -525,39 +521,12 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
private class ActiveState implements PlayerState {
|
||||
|
||||
private int doubletscounter = 3;
|
||||
private boolean mayRollDice = true;
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
|
||||
if (!mayRollDice) {
|
||||
throw new IllegalStateException("Player is not allowed to roll dice at this moment.");
|
||||
}
|
||||
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
mayRollDice = false;
|
||||
|
||||
// Check for doublets
|
||||
if (rollResult.isDoublets()) {
|
||||
doubletscounter--; // Decrement doublets counter
|
||||
|
||||
if (doubletscounter <= 0) {
|
||||
// Player rolls third doublet -> move to jail
|
||||
moveToJail();
|
||||
doubletscounter = 3; // Reset doublets counter
|
||||
} else {
|
||||
// Player rolls doublets but can roll again
|
||||
mayRollDice = true;
|
||||
move(rollResult.calcTotal()); // Move player for this roll
|
||||
getHandler().getLogic().send(Player.this, new NextPlayerTurn());
|
||||
}
|
||||
} else {
|
||||
// No doublets -> move normally and reset doublets counter
|
||||
move(rollResult.calcTotal());
|
||||
}
|
||||
|
||||
System.out.println(rollResult.calcTotal());
|
||||
move(rollResult.calcTotal());
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
@ -578,56 +547,36 @@ public class Player implements FieldVisitor<Void>{
|
||||
* Set when in Gulag
|
||||
*/
|
||||
private class JailState implements PlayerState {
|
||||
private int remainingAttempts = 3;
|
||||
|
||||
private int DoubletsCounter = 3;
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
if (remainingAttempts <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
handler.getLogic().send(Player.this, new DiceResult (rollResult.getRollResult().get(0), rollResult.getRollResult().get(1)));
|
||||
|
||||
if (rollResult.isDoublets()) {
|
||||
handler.getLogic().send(Player.this, new JailEvent(false));
|
||||
state = new ActiveState();
|
||||
} else if (DoubletsCounter == 0) {
|
||||
|
||||
} else {
|
||||
remainingAttempts--;
|
||||
if (remainingAttempts <= 0) {
|
||||
handler.getLogic().send(Player.this, new NotificationMessage("jailpay"));
|
||||
} else {
|
||||
handler.getLogic().send(Player.this, new NotificationMessage("jailtryagain"));
|
||||
}
|
||||
DoubletsCounter--;
|
||||
}
|
||||
System.out.println("Feld:"+fieldID);
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payBail() {
|
||||
if (accountBalance >= 500) {
|
||||
pay(500);
|
||||
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||
state = new ActiveState();
|
||||
} else {
|
||||
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||
}
|
||||
pay(500);
|
||||
state = new ActiveState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useJailCard() {
|
||||
if (getOutOfJailCard > 0) {
|
||||
removeJailCard();
|
||||
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||
state = new ActiveState();
|
||||
} else {
|
||||
handler.getLogic().send(Player.this, new NotificationMessage(""));
|
||||
}
|
||||
getOutOfJailCard--;
|
||||
state = new ActiveState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class WaitForTurnState implements PlayerState {
|
||||
|
||||
@Override
|
||||
|
@ -189,7 +189,7 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void spoparty(Player player) {
|
||||
player.setPositionWithMoney(14);
|
||||
player.setPosition(14);
|
||||
}
|
||||
|
||||
private void gulakFrei(Player player) {
|
||||
@ -197,11 +197,11 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void dienstfuehrerschein(Player player) {
|
||||
player.setPositionWithMoney(20);
|
||||
player.setPosition(20);
|
||||
}
|
||||
|
||||
private void pubquiz(Player player) {
|
||||
player.setPositionWithMoney(39);
|
||||
player.setPosition(39);
|
||||
}
|
||||
|
||||
private void namensschildTruppenkueche(Player player) {
|
||||
@ -221,7 +221,7 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void naechstesMonatsgehalt(Player player) {
|
||||
player.setPositionWithMoney(0);
|
||||
player.setPosition(0);
|
||||
}
|
||||
|
||||
private void antretenVerschlafen(Player player) {
|
||||
@ -237,19 +237,21 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void dienstsportGym(Player player) {
|
||||
player.setPositionWithMoney(1);
|
||||
player.setPosition(1);
|
||||
}
|
||||
|
||||
private void schimmelGulak(Player player) {
|
||||
player.moveToJail();
|
||||
player.setPosition(10);
|
||||
player.jail();
|
||||
}
|
||||
|
||||
private void partynachtGulak(Player player) {
|
||||
player.moveToJail();
|
||||
player.setPosition(10);
|
||||
player.jail();
|
||||
}
|
||||
|
||||
private void jahresabschlussantreten(Player player) {
|
||||
player.setPositionWithMoney(17);
|
||||
player.setPosition(17);
|
||||
}
|
||||
|
||||
private void verkaufenVersicherungen(Player player) {
|
||||
|
@ -41,7 +41,6 @@ import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
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;
|
||||
@ -173,7 +172,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
Serializer.registerClass(TradeReply.class);
|
||||
Serializer.registerClass(TradeHandler.class);
|
||||
Serializer.registerClass(NotificationMessage.class);
|
||||
Serializer.registerClass(JailEvent.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
|
Loading…
Reference in New Issue
Block a user