From d582c59a7dec74db9c8ea78050f219a70a7de5c3 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 24 Nov 2024 00:29:48 +0100 Subject: [PATCH] added playerState changes --- .../java/pp/monopoly/game/server/Player.java | 46 +++++++------------ .../monopoly/game/server/PlayerHandler.java | 7 ++- .../monopoly/game/server/ServerGameLogic.java | 9 ++-- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java index c32ebeb..7dc6fab 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java @@ -14,7 +14,6 @@ import pp.monopoly.message.server.DiceResult; import pp.monopoly.model.FieldVisitor; import pp.monopoly.model.Figure; import pp.monopoly.model.card.Card; -import pp.monopoly.model.card.DeckHelper; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.EventField; import pp.monopoly.model.fields.FineField; @@ -112,6 +111,21 @@ public class Player implements FieldVisitor{ public int getFieldID() { return fieldID; } + void setActive() { + state = new ActiveState(); + } + + boolean finishTurn() { + if(canFinishTurn()) { + state = new WaitForTurnState(); + return true; + } + else return false; + } + + boolean canFinishTurn() { + return accountBalance >= 0; + } /** * Moves by the specified amount of steps @@ -489,47 +503,19 @@ public class Player implements FieldVisitor{ } } - - private class BankruptState implements PlayerState { - - @Override - public DiceResult rollDice() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'rollDice'"); - } - - @Override - public void payBail() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'payBail'"); - } - - @Override - public void useJailCard() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'useJailCard'"); - } - - } - private class WaitForTurnState implements PlayerState { @Override public DiceResult rollDice() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'rollDice'"); + throw new UnsupportedOperationException("not allowed"); } @Override public void payBail() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'payBail'"); } @Override public void useJailCard() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'useJailCard'"); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index 95f4b8f..2005fc9 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -165,10 +165,15 @@ public class PlayerHandler { } /** - * Arranges the players turns in a random order + * Arranges the players turns in a random order. + * Shuffles the players and sets their state to WaitForNextTurn, the first one will be active */ void randomOrder() { Collections.shuffle(players); + for (Player player : players) { + player.finishTurn(); + } + players.get(0).setActive(); } void setStartBalance(int amount) { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index 3c5f81a..a901fac 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -171,9 +171,12 @@ public class ServerGameLogic implements ClientInterpreter { public void received(EndTurn msg, int from) { Player player = playerHandler.getPlayerById(from); if (player != null && state == ServerState.INGAME) { - LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName()); - Player next = playerHandler.nextPlayer(); - send(next, new NextPlayerTurn(next)); + if (player.finishTurn()) { + LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName()); + Player next = playerHandler.nextPlayer(); + next.setActive(); + send(next, new NextPlayerTurn(next)); + } } }