Compare commits

..

No commits in common. "e780513b3506b9b82af681e377197004dfbb4c10" and "75d5a15bdb78c6d70016596458deb08458170ca3" have entirely different histories.

9 changed files with 66 additions and 408 deletions

View File

@ -5,7 +5,6 @@ import java.lang.System.Logger.Level;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import pp.monopoly.game.server.Player;
import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.server.BuyPropertyResponse; import pp.monopoly.message.server.BuyPropertyResponse;
import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.DiceResult;
@ -51,8 +50,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
/** The current state of the client game logic. */ /** The current state of the client game logic. */
private ClientState state = new LobbyState(this); private ClientState state = new LobbyState(this);
private List<Player> players;
/** /**
* Constructs a ClientGameLogic with the specified sender object. * Constructs a ClientGameLogic with the specified sender object.
* *
@ -83,10 +80,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
state.entry(); state.entry();
} }
public List<Player> getPlayers() {
return players;
}
/** /**
* Returns the player's game board. * Returns the player's game board.
* *
@ -243,7 +236,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
*/ */
@Override @Override
public void received(GameStart msg) { public void received(GameStart msg) {
players = msg.getPlayers();
setInfoText("The game has started! Good luck!"); setInfoText("The game has started! Good luck!");
setState(new WaitForTurnState(this)); setState(new WaitForTurnState(this));
} }

View File

@ -13,7 +13,8 @@ import java.util.Random;
import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.DiceResult;
import pp.monopoly.model.FieldVisitor; import pp.monopoly.model.FieldVisitor;
import pp.monopoly.model.Figure; import pp.monopoly.model.Figure;
import pp.monopoly.model.card.Card; import pp.monopoly.model.IntPoint;
import pp.monopoly.model.card.DeckHelper;
import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.EventField; import pp.monopoly.model.fields.EventField;
import pp.monopoly.model.fields.FineField; import pp.monopoly.model.fields.FineField;
@ -88,14 +89,6 @@ public class Player implements FieldVisitor<Void>{
this.name = name; this.name = name;
} }
/**
* Retuns the Playerhandler
* @return the Playerhandler
*/
public PlayerHandler getHandler() {
return handler;
}
/** /**
* Returns this players id * Returns this players id
* @return th eid of this player * @return th eid of this player
@ -111,21 +104,6 @@ public class Player implements FieldVisitor<Void>{
public int getFieldID() { public int getFieldID() {
return fieldID; 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 * Moves by the specified amount of steps
@ -306,8 +284,7 @@ public class Player implements FieldVisitor<Void>{
@Override @Override
public Void visit(EventField field) { public Void visit(EventField field) {
Card c = getHandler().getLogic().getDeckHelper().drawCard(); DeckHelper.drawCard();
getHandler().getLogic().getDeckHelper().visit(c, this);
return null; return null;
} }
@ -350,26 +327,6 @@ public class Player implements FieldVisitor<Void>{
return count; return count;
} }
public int getNumHouses() {
int total = 0;
for (PropertyField field : properties) {
if (field.getClass() == BuildingProperty.class) {
total += ((BuildingProperty) field).getHouses();
}
}
return total;
}
public int getNumHotels() {
int total = 0;
for (PropertyField field : properties) {
if (field.getClass() == BuildingProperty.class) {
total += ((BuildingProperty) field).getHotel();
}
}
return total;
}
/** /**
* Inner class for dice functionality in the game. * Inner class for dice functionality in the game.
* Rolls random dice values. * Rolls random dice values.
@ -503,19 +460,47 @@ public class Player implements FieldVisitor<Void>{
} }
} }
private class WaitForTurnState implements PlayerState {
private class BankruptState implements PlayerState {
@Override @Override
public DiceResult rollDice() { public DiceResult rollDice() {
throw new UnsupportedOperationException("not allowed"); // TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'rollDice'");
} }
@Override @Override
public void payBail() { public void payBail() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'payBail'");
} }
@Override @Override
public void useJailCard() { 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'");
}
@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'");
} }
} }

View File

@ -17,7 +17,6 @@ public class PlayerHandler {
private Set<Player> readyPlayers = new HashSet<>(); private Set<Player> readyPlayers = new HashSet<>();
private ServerGameLogic logic; private ServerGameLogic logic;
private Player hostPlayer; private Player hostPlayer;
private Player extra = null;
/** /**
* Contructs a PlayerHandler * Contructs a PlayerHandler
@ -132,13 +131,8 @@ public class PlayerHandler {
* Completes a player turn and return the next player * Completes a player turn and return the next player
* @return the next players who is active * @return the next players who is active
*/ */
public Player nextPlayer() { Player nextPlayer() {
Player tmp = players.get(0); Player tmp = players.get(0);
if (extra != null) {
tmp = extra;
extra = null;
return tmp;
}
players.remove(0); players.remove(0);
players.add(tmp); players.add(tmp);
return players.get(0); return players.get(0);
@ -148,7 +142,7 @@ public class PlayerHandler {
* Returns the {@link ServerGameLogic} of this PlayerHandler * Returns the {@link ServerGameLogic} of this PlayerHandler
* @return the {@link ServerGameLogic} of this PlayerHandler * @return the {@link ServerGameLogic} of this PlayerHandler
*/ */
public ServerGameLogic getLogic() { ServerGameLogic getLogic() {
return logic; return logic;
} }
@ -165,15 +159,10 @@ 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() { void randomOrder() {
Collections.shuffle(players); Collections.shuffle(players);
for (Player player : players) {
player.finishTurn();
}
players.get(0).setActive();
} }
void setStartBalance(int amount) { void setStartBalance(int amount) {
@ -181,8 +170,4 @@ public class PlayerHandler {
player.setAccountBalance(amount); player.setAccountBalance(amount);
} }
} }
public void extraTurn(Player player) {
if (players.contains(player)) extra = player;
}
} }

View File

@ -22,7 +22,6 @@ import pp.monopoly.message.server.ViewAssetsResponse;
import pp.monopoly.model.Board; import pp.monopoly.model.Board;
import pp.monopoly.model.Figure; import pp.monopoly.model.Figure;
import pp.monopoly.model.Rotation; import pp.monopoly.model.Rotation;
import pp.monopoly.model.card.DeckHelper;
import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.PropertyField; import pp.monopoly.model.fields.PropertyField;
@ -39,7 +38,6 @@ public class ServerGameLogic implements ClientInterpreter {
private ServerState state = ServerState.LOBBY; private ServerState state = ServerState.LOBBY;
private static final int MAX_PLAYERS = 6; private static final int MAX_PLAYERS = 6;
private BoardManager boardManager = new BoardManager(); private BoardManager boardManager = new BoardManager();
private final DeckHelper deckHelper = new DeckHelper();
private int startMoney; private int startMoney;
/** /**
@ -171,12 +169,9 @@ public class ServerGameLogic implements ClientInterpreter {
public void received(EndTurn msg, int from) { public void received(EndTurn msg, int from) {
Player player = playerHandler.getPlayerById(from); Player player = playerHandler.getPlayerById(from);
if (player != null && state == ServerState.INGAME) { if (player != null && state == ServerState.INGAME) {
if (player.finishTurn()) { LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName()); Player next = playerHandler.nextPlayer();
Player next = playerHandler.nextPlayer(); send(next, new NextPlayerTurn(next));
next.setActive();
send(next, new NextPlayerTurn(next));
}
} }
} }
@ -288,8 +283,4 @@ public class ServerGameLogic implements ClientInterpreter {
public Player getPlayerById(int id) { public Player getPlayerById(int id) {
return playerHandler.getPlayerById(id); return playerHandler.getPlayerById(id);
} }
public DeckHelper getDeckHelper() {
return deckHelper;
}
} }

View File

@ -0,0 +1,7 @@
package pp.monopoly.model;
import pp.monopoly.model.card.Card;
public interface CardVisitor<T> {
T visit(Card c);
}

View File

@ -1,7 +1,5 @@
package pp.monopoly.model.card; package pp.monopoly.model.card;
import pp.monopoly.game.server.Player;
public class Card { public class Card {
private final String description; private final String description;
private final String keyword; private final String keyword;
@ -11,8 +9,8 @@ public class Card {
this.keyword = keyword; this.keyword = keyword;
} }
public void accept(DeckHelper visitor, Player player) { public void accept(DeckHelper visitor) {
visitor.visit(this, player); visitor.visit(this);
} }
String getDescription() { String getDescription() {

View File

@ -2,318 +2,25 @@ package pp.monopoly.model.card;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import pp.monopoly.game.server.Player; import pp.monopoly.model.CardVisitor;
import pp.monopoly.message.client.EndTurn;
public class DeckHelper{ public class DeckHelper implements CardVisitor<Void>{
private Queue<Card> cards; private static Queue<Card> cards;
private List<Card> drawn = new ArrayList<>();
private DeckHelper() {
public DeckHelper() {
cards = new LinkedList<Card>();
cards.add(new Card("Du wurdest mit einem Dienst KFZ geblitzt. Zahle: 800€", "dienst-kfz-blitzer"));
cards.add(new Card("Die erste Spoparty steht bevor. Ziehe vor zum 23er.", "spoparty"));
cards.add(new Card("Du kommst aus dem Gulak frei.", "gulak-frei-1"));
cards.add(new Card("Du kommst aus dem Gulak frei.", "gulak-frei-2"));
cards.add(new Card("Du hast den Dienstführerschein bestanden. Ziehe vor bis Teststrecke.", "dienstfuehrerschein"));
cards.add(new Card("Malkmus läd zum Pubquiz ein. Rücke vor bis zum 20er.", "pubquiz"));
cards.add(new Card("Du warst ohne Namensschild in der Truppenküche. Rücke vor zum 10er. Gehe nicht über Monatsgehalt. Ziehe keine 2000x€ ein.", "namensschild-truppenkueche"));
cards.add(new Card("Du hast heute die Spendierhosen an und gibst eine Runde in der Unibar. Zahle jedem Spieler: 400€", "spendierhosen-unibar"));
cards.add(new Card("Du warst in der Prüfungsphase krank. Gehe 3 Felder zurück.", "pruefungsphase-krank"));
cards.add(new Card("Ziehe vor bis zum nächsten Monatsgehalt.", "naechstes-monatsgehalt"));
cards.add(new Card("Du hast ein Antreten verschlafen. Zahle: 500€", "antreten-verschlafen-1"));
cards.add(new Card("Du hast den Maibock organisiert. Du erhältst: 3000€", "maibock-organisiert"));
cards.add(new Card("Der Spieß macht eine unangekündigte Inventur. Zahle für jedes Haus: 400€ und jedes Hotel: 2800€", "inventur-haeuser-hotels"));
cards.add(new Card("Es gab keine Mozzarella Bällchen mehr für Thoma. Alle Spieler ziehen vor auf Gym.", "dienstsport-gym"));
cards.add(new Card("Auf deiner Stube wurde Schimmel gefunden. Gehe ins Gulak. Begib Dich direkt dorthin. Gehe nicht über Monatsgehalt. Ziehe nicht ein.", "schimmel-gulak"));
cards.add(new Card("Deine Stube ist nach einer Partynacht nicht mehr bewohnbar. Du ziehst ins Gulak. Begib Dich direkt dorthin. Gehe nicht über Monatsgehalt. Ziehe nicht ein.", "partynacht-gulak"));
cards.add(new Card("Das Jahresabschlussantreten steht an. Ziehe vor bis Schwimmhalle.", "jahresabschlussantreten"));
cards.add(new Card("Du wurdest beim Verkaufen von Versicherungen erwischt. Zahle: 4000€", "verkaufen-versicherungen"));
cards.add(new Card("Du musstest einen Rückstuferantrag stellen. Setze eine Runde aus.", "rueckstuferantrag"));
cards.add(new Card("Auf einer Hausfeier bist du betrunken auf der Treppe gestürzt und dabei auf einen Kameraden gefallen. Zahle: 800€ und gehe zurück zu SanZ.", "hausfeier-sturz"));
cards.add(new Card("Beförderung. Beim nächsten Monatsgehalt ziehst du ein: 3000€", "befoerderung"));
cards.add(new Card("Du entscheidest dich für eine Dienstreise nach Lourd. Zahle: 1000€ und setze eine Runde aus.", "dienstreise-lourd"));
cards.add(new Card("Du warst fleißig Blutspenden und erhältst einen Tag Sonderurlaub. Du bist nochmal an der Reihe.", "blutspenden-sonderurlaub"));
cards.add(new Card("Dir wurde auf dem Oktoberfest dein Geldbeutel geklaut. Gebe 10% deines Vermögens ab.", "geldbeutel-oktoberfest"));
cards.add(new Card("Du wirst von deinem Chef für vorbildliches Verhalten gelobt. Du erhältst: 4000€", "lob-chef"));
cards.add(new Card("Deine Bekanntschaft von letzter Nacht war eine Spo. Lasse dich testen und zahle: 200€", "spo-testen"));
cards.add(new Card("Du wurdest von Kranz geexmattet. Gehe zurück zu Prüfungsamt.", "kranz-exmatrikulation"));
cards.add(new Card("Die letzte Party ist ein wenig eskaliert. Setze eine Runde aus.", "party-eskaliert"));
cards.add(new Card("Du wurdest zur VP gewählt und schmeißt eine Einstandsparty. Zahle: 800€", "vp-einstandsparty"));
cards.add(new Card("Du hast eine Party veranstaltet und dick Gewinn gemacht. Ziehe ein: 1500€", "party-gewinn"));
cards.add(new Card("Zur falschen Zeit am falschen Ort. Du musst einen Bergmarsch planen und setzt eine Runde aus.", "bergmarsch"));
cards.add(new Card("Dein Jodel eines Eispenis mit Unterhodenbeleuchtung geht viral. Ziehe ein: 1000€", "jodel-eispenis"));
} }
public void visit(Card card, Player player) { @Override
switch (card.getKeyword()) { public Void visit(Card c) {
case "dienst-kfz-blitzer": // TODO Auto-generated method stub
dienstKfzBlitzer(player); throw new UnsupportedOperationException("Unimplemented method 'visit'");
break;
case "spoparty":
spoparty(player);
break;
case "gulak-frei-1":
case "gulak-frei-2":
gulakFrei(player);
break;
case "dienstfuehrerschein":
dienstfuehrerschein(player);
break;
case "pubquiz":
pubquiz(player);
break;
case "namensschild-truppenkueche":
namensschildTruppenkueche(player);
break;
case "spendierhosen-unibar":
spendierhosenUnibar(player);
break;
case "pruefungsphase-krank":
pruefungsphaseKrank(player);
break;
case "naechstes-monatsgehalt":
naechstesMonatsgehalt(player);
break;
case "antreten-verschlafen-1":
antretenVerschlafen(player);
break;
case "maibock-organisiert":
maibockOrganisiert(player);
break;
case "inventur-haeuser-hotels":
inventurHaeuserHotels(player);
break;
case "dienstsport-gym":
dienstsportGym(player);
break;
case "schimmel-gulak":
schimmelGulak(player);
break;
case "partynacht-gulak":
partynachtGulak(player);
break;
case "jahresabschlussantreten":
jahresabschlussantreten(player);
break;
case "verkaufen-versicherungen":
verkaufenVersicherungen(player);
break;
case "rueckstuferantrag":
rueckstuferantrag(player);
break;
case "hausfeier-sturz":
hausfeierSturz(player);
break;
case "befoerderung":
befoerderung(player);
break;
case "dienstreise-lourd":
dienstreiseLourd(player);
break;
case "blutspenden-sonderurlaub":
blutspendenSonderurlaub(player);
break;
case "geldbeutel-oktoberfest":
geldbeutelOktoberfest(player);
break;
case "lob-chef":
lobChef(player);
break;
case "spo-testen":
spoTesten(player);
break;
case "kranz-exmatrikulation":
kranzExmatrikulation(player);
break;
case "party-eskaliert":
partyEskaliert(player);
break;
case "vp-einstandsparty":
vpEinstandsparty(player);
break;
case "party-gewinn":
partyGewinn(player);
break;
case "bergmarsch":
bergmarsch(player);
break;
case "jodel-eispenis":
jodelEispenis(player);
break;
default:
break;
}
} }
private void dienstKfzBlitzer(Player player) {
player.pay(800);
}
private void spoparty(Player player) {
player.movePos(14);
}
private void gulakFrei(Player player) {
player.addJailCard();
}
private void dienstfuehrerschein(Player player) {
player.movePos(20);
}
private void pubquiz(Player player) {
player.movePos(39);
}
private void namensschildTruppenkueche(Player player) {
//TODO
}
private void spendierhosenUnibar(Player player) {
for (Player p : player.getHandler().getPlayers()) {
p.earnMoney(400);
}
player.pay(player.getHandler().getPlayerCount()*400 - 400);
}
private void pruefungsphaseKrank(Player player) {
player.movePos(player.getFieldID() - 3);
}
private void naechstesMonatsgehalt(Player player) {
player.movePos(0);
}
private void antretenVerschlafen(Player player) {
player.pay(500);
}
private void maibockOrganisiert(Player player) {
player.earnMoney(3000);
}
private void inventurHaeuserHotels(Player player) {
player.pay(player.getNumHouses() * 400 + player.getNumHotels() * 2800);
}
private void dienstsportGym(Player player) {
for (Player p : player.getHandler().getPlayers()) {
p.movePos(1);
}
}
private void schimmelGulak(Player player) {
player.movePos(10);
}
private void partynachtGulak(Player player) {
player.movePos(10);
}
private void jahresabschlussantreten(Player player) {
player.movePos(17);
}
private void verkaufenVersicherungen(Player player) {
player.pay(4000);
}
private void rueckstuferantrag(Player player) {
player.getHandler().getLogic().received(new EndTurn(), player.getId());
}
private void hausfeierSturz(Player player) {
player.pay(800);
player.movePos(32);
}
private void befoerderung(Player player) {
player.earnMoney(3000);
}
private void dienstreiseLourd(Player player) {
player.pay(1000);
player.getHandler().getLogic().received(new EndTurn(), player.getId());
}
private void blutspendenSonderurlaub(Player player) {
player.getHandler().extraTurn(player);
}
private void geldbeutelOktoberfest(Player player) {
player.pay(player.getAccountBalance() / 10);
}
private void lobChef(Player player) {
player.earnMoney( 4000);
}
private void spoTesten(Player player) {
player.pay( 200);
}
private void kranzExmatrikulation(Player player) {
player.movePos(5);
}
private void partyEskaliert(Player player) {
player.getHandler().getLogic().received(new EndTurn(), player.getId());
}
private void vpEinstandsparty(Player player) {
player.pay( 800);
}
private void partyGewinn(Player player) {
player.earnMoney( 1500);
}
private void bergmarsch(Player player) {
player.getHandler().getLogic().received(new EndTurn(), player.getId());
}
private void jodelEispenis(Player player) {
player.earnMoney(1000);
}
private void shuffle() { private void shuffle() {
List<Card> cardList = new ArrayList<>(cards); List<Card> cardList = new ArrayList<>(cards);
Collections.shuffle(cardList); Collections.shuffle(cardList);
@ -321,13 +28,7 @@ public class DeckHelper{
cards.addAll(cardList); cards.addAll(cardList);
} }
public Card drawCard() { public static Card drawCard() {
if (cards.isEmpty()) { return cards != null ? cards.poll() : null;
drawn.forEach(cards::add);
shuffle();
}
Card card = cards.poll();
drawn.add(card);
return card;
} }
} }

View File

@ -98,12 +98,4 @@ public class BuildingProperty extends PropertyField {
public int getHousePrice() { public int getHousePrice() {
return housePrice; return housePrice;
} }
public int getHouses() {
return houses;
}
public int getHotel() {
return hotel ? 1:0;
}
} }

View File

@ -2,6 +2,8 @@ package pp.monopoly.model.fields;
import pp.monopoly.game.server.Player; import pp.monopoly.game.server.Player;
import pp.monopoly.model.card.Card;
import pp.monopoly.model.card.DeckHelper;
public class EventField extends Field{ public class EventField extends Field{
@ -13,4 +15,9 @@ public class EventField extends Field{
public void accept(Player player) { public void accept(Player player) {
player.visit(this); player.visit(this);
} }
public Card drawCard() {
return DeckHelper.drawCard();
}
} }