diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java index 44a6c726..76767434 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java @@ -2,6 +2,7 @@ import pp.mdga.client.view.GameView; import pp.mdga.client.view.LobbyView; +import pp.mdga.notification.*; import java.util.ArrayList; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java index b1b488ae..5c504d27 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/server/MdgaServer.java @@ -1,10 +1,17 @@ package pp.mdga.client.server; -import com.jme3.network.*; +import com.jme3.network.ConnectionListener; +import com.jme3.network.HostedConnection; +import com.jme3.network.Message; +import com.jme3.network.MessageListener; +import com.jme3.network.Network; +import com.jme3.network.Server; import com.jme3.network.serializing.Serializer; import pp.mdga.game.Game; import pp.mdga.game.Player; import pp.mdga.message.client.*; +import pp.mdga.message.client.ClientMessage; +import pp.mdga.message.server.*; import pp.mdga.message.server.ServerMessage; import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerSender; @@ -13,7 +20,6 @@ import java.io.IOException; import java.lang.System.Logger; import java.lang.System.Logger.Level; -import java.util.Map; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.logging.LogManager; @@ -51,7 +57,7 @@ public static void main(String[] args) { */ public MdgaServer() { LOGGER.log(Level.INFO, "Creating MdgaServer"); //NON-NLS - logic = new ServerGameLogic(this, new Game()); + logic = null;//new ServerGameLogic(new Game(), this); } public void run() { @@ -90,14 +96,14 @@ private void initializeSerializables() { Serializer.registerClass(ClientStartGame.class); Serializer.registerClass(DeselectTSK.class); Serializer.registerClass(ForceContinueGame.class); - Serializer.registerClass(StartGame.class); + Serializer.registerClass(ForceStartGame.class); Serializer.registerClass(JoinServer.class); Serializer.registerClass(LeaveGame.class); Serializer.registerClass(LobbyNotReady.class); Serializer.registerClass(LobbyReady.class); Serializer.registerClass(NoPowerCard.class); Serializer.registerClass(RequestBriefing.class); - Serializer.registerClass(RequestDie.class); + Serializer.registerClass(RequestDice.class); Serializer.registerClass(RequestMove.class); Serializer.registerClass(RequestPlayCard.class); Serializer.registerClass(SelectCard.class); @@ -145,7 +151,7 @@ private void registerListeners() { myServer.addMessageListener(this, LobbyReady.class); myServer.addMessageListener(this, NoPowerCard.class); myServer.addMessageListener(this, RequestBriefing.class); - myServer.addMessageListener(this, RequestDie.class); + myServer.addMessageListener(this, RequestDice.class); myServer.addMessageListener(this, RequestMove.class); myServer.addMessageListener(this, RequestPlayCard.class); myServer.addMessageListener(this, SelectCard.class); @@ -154,42 +160,32 @@ private void registerListeners() { myServer.addConnectionListener(this); } - - public void messageReceived(HostedConnection source, ClientMessage message) { + @Override + public void messageReceived(HostedConnection source, Message message) { LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS - pendingMessages.add(new ReceivedMessage(message, source.getId())); + if (message instanceof ClientMessage clientMessage) + pendingMessages.add(new ReceivedMessage(clientMessage, source.getId())); } @Override public void connectionAdded(Server server, HostedConnection hostedConnection) { LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS - // ToDo: Synchronize data between server and client. - logic.getGame().addPlayer(hostedConnection.getId(), new Player()); + //logic.addPlayer(hostedConnection.getId()); } @Override public void connectionRemoved(Server server, HostedConnection hostedConnection) { LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS - final Player player = logic.getGame().getPlayerById(hostedConnection.getId()); + final Player player = null;// = logic.getPlayerById(hostedConnection.getId()); if (player == null) LOGGER.log(Level.INFO, "closed connection does not belong to an active player"); //NON-NLS else { //NON-NLS LOGGER.log(Level.INFO, "closed connection belongs to {0}", player); //NON-NLS - // exit(0); - this.handleDisconnect(hostedConnection.getId()); + exit(0); } } - /** - * This method will be used to handle unintentional disconnections from players. - * - * @param id as the id of the disconnected player. - */ - public void handleDisconnect(int id) { - this.logic.received(new Disconnected(), id); - } - - public void exit(int exitValue) { //NON-NLS + private void exit(int exitValue) { //NON-NLS LOGGER.log(Level.INFO, "close request"); //NON-NLS if (myServer != null) for (HostedConnection client : myServer.getConnections()) //NON-NLS @@ -214,16 +210,4 @@ public void send(int id, ServerMessage message) { else LOGGER.log(Level.ERROR, "there is no connection with id={0}", id); //NON-NLS } - - /** - * This method will be used to send the given message parameter to all connected players which are saved inside the - * players attribute of Game class. - * - * @param message as the message which will be sent to all players as a ServerMessage. - */ - public void broadcast(ServerMessage message) { - for (Map.Entry entry: this.logic.getGame().getPlayers().entrySet()) { - this.send(entry.getValue().getId(), message); - } - } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java index d197c0d4..9ec3bca9 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientGameLogic.java @@ -1,33 +1,20 @@ package pp.mdga.client; -import pp.mdga.game.BonusCard; -import pp.mdga.game.Color; import pp.mdga.game.Game; -import pp.mdga.game.Piece; import pp.mdga.message.client.ClientMessage; import pp.mdga.message.server.*; -import java.util.Map; -import java.util.UUID; - public class ClientGameLogic implements ServerInterpreter { static final System.Logger LOGGER = System.getLogger(ClientGameLogic.class.getName()); private Game game; private final ClientSender clientSender; private ClientState state; - private Map pieces; - private Map cards; - - private Dialogs dialogs = new Dialogs(null, this); - private GameState gameState = new GameState(null, this); - private Ceremony ceremony = new Ceremony(null, this); - private Interrupt interrupt = new Interrupt(null, this); public ClientGameLogic(Game game, ClientSender clientSender) { this.game = game; this.clientSender = clientSender; - state = dialogs; + state = new ClientAutomaton(this); } public void send(ClientMessage msg){ @@ -49,197 +36,136 @@ public ClientState getState(){ @Override public void received(ActivePlayer msg) { - state.received(msg); + } @Override public void received(AnyPiece msg) { - state.received(msg); + } @Override public void received(Briefing msg) { - state.received(msg); + } @Override public void received(CeremonyMessage msg) { - state.received(msg); + } @Override - public void received(Die msg) { - state.received(msg); + public void received(Dice msg) { + } @Override public void received(DiceAgain msg) { - state.received(msg); + } @Override public void received(DiceNow msg) { - state.received(msg); + } @Override public void received(EndOfTurn msg) { - state.received(msg); + } @Override public void received(LobbyAccept msg) { - state.received(msg); + } @Override public void received(LobbyDeny msg) { - state.received(msg); + } @Override public void received(LobbyPlayerJoin msg) { - state.received(msg); + } @Override public void received(LobbyPlayerLeave msg) { - state.received(msg); + } @Override public void received(MoveMessage msg) { - state.received(msg); + } @Override public void received(NoTurn msg) { - state.received(msg); + } @Override public void received(PauseGame msg) { - state.received(msg); + } @Override public void received(PlayCard msg) { - state.received(msg); + } @Override public void received(PossibleCard msg) { - state.received(msg); + } @Override public void received(PossiblePiece msg) { - state.received(msg); + } @Override public void received(RankingResponse msg) { - state.received(msg); + } @Override public void received(RankingRollAgain msg) { - state.received(msg); + } @Override public void received(ReconnectBriefing msg) { - state.received(msg); + } @Override public void received(ResumeGame msg) { - state.received(msg); + } @Override public void received(ServerStartGame msg) { - state.received(msg); + } @Override public void received(StartPiece msg) { - state.received(msg); + } @Override public void received(UpdateReady msg) { - state.received(msg); + } @Override public void received(UpdateTSK msg) { - state.received(msg); + } @Override public void received(WaitPiece msg) { - state.received(msg); - } - public void selectPiece(UUID pieceId){ - state.selectPiece(pieceId); - } - - public void selectCard(UUID cardId){ - state.selectCard(cardId); - } - - public void selectTsk(Color color){ - state.selectTSK(color); - } - - public void selectDice(){ - state.selectDice(); - } - - public void selectName(String name){ - state.setName(name); - } - - public void selectReady(boolean ready){ - state.selectReady(); - } - - public void selectHost(){ - state.selectHost(); - } - - public void selectLeave(){ - state.selectLeave(); - } - - public void selectJoin(){ - state.selectJoin(); - } - - public void selectStart(){ - state.selectStart(); - } - - public void setState(ClientState state){ - this.state.exit(); - this.state = state; - } - - public GameState getGameState(){ - return gameState; - } - - public Ceremony getCeremony(){ - return ceremony; - } - - public Interrupt getInterrupt(){ - return interrupt; - } - - public Dialogs getDialogs(){ - return dialogs; } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayer.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayer.java index 9bfb9a6e..166f6f90 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayer.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/DetermineStartPlayer.java @@ -2,20 +2,17 @@ import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientState; +import pp.mdga.client.gameState.determineStartPlayerState.DetermineStartPlayerStateMachine; public class DetermineStartPlayer extends GameStates { + private final DetermineStartPlayerStateMachine determineStartPlayerStateMachine; public DetermineStartPlayer(ClientState parent, ClientGameLogic logic) { super(parent, logic); + this.determineStartPlayerStateMachine = new DetermineStartPlayerStateMachine(parent, logic); } - @Override - public void enter() { - - } - - @Override - public void exit() { - + public DetermineStartPlayerStateMachine getDetermineStartPlayerStateMachine() { + return determineStartPlayerStateMachine; } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/DetermineStartPlayerStateMachine.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/DetermineStartPlayerStateMachine.java new file mode 100644 index 00000000..8db2cd8a --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/determineStartPlayerState/DetermineStartPlayerStateMachine.java @@ -0,0 +1,16 @@ +package pp.mdga.client.gameState.determineStartPlayerState; + +import pp.mdga.client.ClientGameLogic; +import pp.mdga.client.ClientState; +import pp.mdga.client.ClientStateMachine; + +public class DetermineStartPlayerStateMachine extends ClientStateMachine { + public DetermineStartPlayerStateMachine(ClientState parent, ClientGameLogic logic) { + super(parent, logic); + } + + @Override + public RollRankingDice initialState() { + return new RollRankingDice(this, logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java index e76cffb6..7fe6251b 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java @@ -8,27 +8,29 @@ * The game state is updated by the game logic. */ public class Game { - /** - * Constants. - */ - public static final int AMOUNT_OF_TURBO_CARDS = 16; - public static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12; - - /** - * Attributes. - */ private int diceModifier = 1; private int diceEyes; - private Map players = new HashMap<>(); + private Map players = new EnumMap<>(Color.class); private Statistic gameStatistics; private List drawPile; private List discardPile = new ArrayList<>(); private Board board; private Color activeColor; + private List order; + private final ArrayList playerList = new ArrayList<>(4); + private final ArrayList observers = new ArrayList<>(); - private boolean allRanked = false; - private boolean movablePieces = false; - private boolean allReady = false; + private Player startPlayer; + private Boolean gameHasStarted = false; + private Boolean playerHasDisconnected = false; + private Boolean gameIsInterrupted = false; + private Boolean allRanked = false; + private Boolean movablePieces = false; + + private Boolean allReady = false; + + private static final int AMOUNT_OF_TURBO_CARDS = 16; + private static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12; /** * This constructor creates a new Game object. @@ -46,23 +48,185 @@ public Game() { board = new Board(); } + /** + * This method returns the dice modifier. + * + * @return the dice modifier + */ + public int getDiceModifier() { + return diceModifier; + } + + /** + * This method sets the dice modifier. + * + * @param diceModifier the new dice modifier + */ + public void setDiceModifier(int diceModifier) { + this.diceModifier = diceModifier; + } + + /** + * This method returns the dice eyes. + * + * @return the dice eyes + */ + public int getDiceEyes() { + return diceEyes; + } + + /** + * This method sets the dice eyes. + * + * @param diceEyes the new dice eyes + */ + public void setDiceEyes(int diceEyes) { + this.diceEyes = diceEyes; + } + + /** + * This method returns the players. + * + * @return the players + */ + public Map getPlayers() { + return players; + } + + /** + * This method sets the players. + * + * @param players the new players + */ + public void setPlayers(Map players) { + this.players = players; + } + + /** + * This method returns the game statistics. + * + * @return the game statistics + */ + public Statistic getGameStatistics() { + return gameStatistics; + } + + /** + * This method sets the game statistics. + * + * @param gameStatistics the new game statistics + */ + public void setGameStatistics(Statistic gameStatistics) { + this.gameStatistics = gameStatistics; + } + + /** + * This method returns the draw pile. + * + * @return the draw pile + */ + public List getDrawPile() { + return drawPile; + } + + /** + * This method sets the draw pile. + * + * @param drawPile the new draw pile + */ + public void setDrawPile(List drawPile) { + this.drawPile = drawPile; + } + + /** + * This method returns the discard pile. + * + * @return the discard pile + */ + public List getDiscardPile() { + return discardPile; + } + + /** + * This method sets the discard pile. + * + * @param discardPile the new discard pile + */ + public void setDiscardPile(List discardPile) { + this.discardPile = discardPile; + } + + /** + * This method returns the board. + * + * @return the board + */ + public Board getBoard() { + return board; + } + + /** + * This method sets the board. + * + * @param board the new board + */ + public void setBoard(Board board) { + this.board = board; + } + + /** + * This method returns the active color. + * + * @return the active color + */ + public Color getActiveColor() { + return activeColor; + } + + /** + * This method sets the active color. + * + * @param activeColor the new active color + */ + public void setActiveColor(Color activeColor) { + this.activeColor = activeColor; + } + + /** + * This method returns the order of the players. + * + * @return the order of the players + */ + public List getOrder() { + return order; + } + + /** + * This method sets the order of the players. + * + * @param order the new order of the players + */ + public void setOrder(List order) { + this.order = order; + } + /** * This method adds a player to the game. * - * @param id the id of the player + * @param color the color of the player * @param player the player to be added */ - public void addPlayer(int id, Player player) { - players.put(id, player); + public void addPlayer(Color color, Player player) { + players.put(color, player); } /** * This method removes a player from the game. * - * @param id the color of the player + * @param color the color of the player */ - public void removePlayer(int id) { - players.remove(id); + public void removePlayer(Color color) { + players.remove(color); } /** @@ -84,135 +248,49 @@ public void removeObserver(Observer observer) { } /** + * This method returns the game has started. * - * @param id - * @param active + * @return the game has started */ - public void updatePlayerActiveState(int id, boolean active) { - this.players.get(id).setActive(active); + public Boolean getGameHasStarted() { + return gameHasStarted; } /** - * This method will be used to return the player which has the given id parameter. + * This method sets the game has started. * - * @param id as the unique id of a player as an Integer. - * @return the player with the given id as a Player object. + * @param gameHasStarted the new game has started */ - public Player getPlayerById(int id) { - return this.players.get(id); + public void setGameHasStarted(Boolean gameHasStarted) { + this.gameHasStarted = gameHasStarted; } /** - * This method will be used to the get the player depending on the given color parameter. + * This method returns the player has disconnected. * - * @param color as the color of the player as a Color enumeration. - * @return the player with the given color as a Player object. + * @return the player has disconnected */ - public Player getPlayerByColor(Color color) { - for (Map.Entry entry : this.players.entrySet()) { - if (entry.getValue().getColor() == color) { - return entry.getValue(); - } - } - - return null; + public Boolean playerHasDisconnected() { + return playerHasDisconnected; } /** - * This method will be used to return the number of active players of this game. + * This method sets the game interruption state. * - * @return activePlayers as an Integer. + * @param gameIsInterrupted the new game interruption state */ - public int getNumberOfActivePlayers() { - int activePlayers = 0; - for (Map.Entry entry : this.players.entrySet()) { - if (entry.getValue().isActive()) { - activePlayers++; - } - } - - return activePlayers; + public void setGameIsInterrupted(Boolean gameIsInterrupted) { + this.gameIsInterrupted = gameIsInterrupted; + if (Boolean.FALSE.equals(gameIsInterrupted)) notifyObservers(); } /** - * This method notifies the observers. - */ - public void notifyObservers() { - for (Observer observer : new ArrayList<>(observers)) { - observer.update(); - } - } - - /** - * This method returns the dice modifier. + * This method returns whether the game is interrupted. * - * @return the dice modifier + * @return true if the game is interrupted, false otherwise */ - public int getDiceModifier() { - return diceModifier; - } - - /** - * This method returns the dice eyes. - * - * @return the dice eyes - */ - public int getDiceEyes() { - return diceEyes; - } - - /** - * This method returns the players. - * - * @return the players - */ - public Map getPlayers() { - return players; - } - - /** - * This method returns the game statistics. - * - * @return the game statistics - */ - public Statistic getGameStatistics() { - return gameStatistics; - } - - /** - * This method returns the draw pile. - * - * @return the draw pile - */ - public List getDrawPile() { - return drawPile; - } - - /** - * This method returns the discard pile. - * - * @return the discard pile - */ - public List getDiscardPile() { - return discardPile; - } - - /** - * This method returns the board. - * - * @return the board - */ - public Board getBoard() { - return board; - } - - /** - * This method returns the active color. - * - * @return the active color - */ - public Color getActiveColor() { - return activeColor; + public Boolean gameIsInterrupted() { + return gameIsInterrupted; } /** @@ -224,78 +302,6 @@ public Boolean getMovablePieces() { return movablePieces; } - /** - * This method sets the dice modifier. - * - * @param diceModifier the new dice modifier - */ - public void setDiceModifier(int diceModifier) { - this.diceModifier = diceModifier; - } - - /** - * This method sets the dice eyes. - * - * @param diceEyes the new dice eyes - */ - public void setDiceEyes(int diceEyes) { - this.diceEyes = diceEyes; - } - - /** - * This method sets the players. - * - * @param players the new players - */ - public void setPlayers(Map players) { - this.players = players; - } - - /** - * This method sets the game statistics. - * - * @param gameStatistics the new game statistics - */ - public void setGameStatistics(Statistic gameStatistics) { - this.gameStatistics = gameStatistics; - } - - /** - * This method sets the draw pile. - * - * @param drawPile the new draw pile - */ - public void setDrawPile(List drawPile) { - this.drawPile = drawPile; - } - - /** - * This method sets the discard pile. - * - * @param discardPile the new discard pile - */ - public void setDiscardPile(List discardPile) { - this.discardPile = discardPile; - } - - /** - * This method sets the board. - * - * @param board the new board - */ - public void setBoard(Board board) { - this.board = board; - } - - /** - * This method sets the active color. - * - * @param activeColor the new active color - */ - public void setActiveColor(Color activeColor) { - this.activeColor = activeColor; - } - /** * This method sets the game interruption state. * @@ -306,6 +312,16 @@ public void setMovablePieces(Boolean movablePieces) { if (Boolean.FALSE.equals(movablePieces)) notifyObservers(); } + /** + * This method sets the player has disconnected. + * + * @param playerHasDisconnected the new player has disconnected + */ + public void setPlayerHasDisconnected(Boolean playerHasDisconnected) { + this.playerHasDisconnected = playerHasDisconnected; + if (Boolean.TRUE.equals(playerHasDisconnected)) notifyObservers(); + } + /** * This method returns whether all players have ranked. * @@ -325,6 +341,24 @@ public void setAllRanked(Boolean allRanked) { if (Boolean.TRUE.equals(allRanked)) notifyObservers(); } + /** + * This method returns the start player. + * + * @return the start player + */ + public Player getStartPlayer() { + return startPlayer; + } + + /** + * This method sets the start player. + * + * @param startPlayer the new start player + */ + public void setStartPlayer(Player startPlayer) { + this.startPlayer = startPlayer; + } + /** * This method returns the all ready state. * @@ -337,10 +371,53 @@ public Boolean allReady() { /** * This method sets the all ready state. * - * @param allReady the new all-ready state + * @param allReady the new all ready state */ public void setAllReady(Boolean allReady) { this.allReady = allReady; if (Boolean.TRUE.equals(allReady)) notifyObservers(); } + + /** + * This method notifies the observers. + */ + public void notifyObservers() { + for (Observer observer : new ArrayList<>(observers)) { + //observer.update(); + } + } + + /** + * This method returns the piece through its identifier. + * + * @param identifier the identifier of the piece + * @return the piece + */ + public Piece getPieceThroughIdentifier(String identifier) { + String[] parts = identifier.split("-"); + Color color = Color.valueOf(parts[0]); + int index = Integer.parseInt(parts[1]); + return board.getPlayerData().get(color).getPieces()[index]; + } + + public ArrayList getPlayerList() { + return playerList; + } + + public void addPlayerToList(Player player) { + playerList.add(player); + } + + public void removePlayerFromList(Player player) { + playerList.remove(player); + } + + public Player getPlayerFromList(String name) { + for (Player player : playerList) { + if (player.getName().equals(name)) { + return player; + } + } + return null; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/DetermineStartPlayer.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/DetermineStartPlayer.java new file mode 100644 index 00000000..9f726af0 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/DetermineStartPlayer.java @@ -0,0 +1,7 @@ +package pp.mdga.server; + +public class DetermineStartPlayer extends GameState { + public DetermineStartPlayer(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/GameState.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/GameState.java new file mode 100644 index 00000000..d303db8d --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/GameState.java @@ -0,0 +1,7 @@ +package pp.mdga.server; + +public class GameState extends ServerState { + public GameState(ServerGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java index 3ea9735e..0a486a88 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/ServerGameLogic.java @@ -2,215 +2,126 @@ import pp.mdga.game.Game; import pp.mdga.message.client.*; -import pp.mdga.server.automaton.*; import java.lang.System.Logger; -/** - * - */ public class ServerGameLogic implements ClientInterpreter { - /** - * Constants. - */ private static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName()); - /** - * - */ private final ServerSender serverSender; + private final Game game; - /** - * States - */ - private ServerState currentState; - private final ServerState lobbyState; - private final ServerState gameState; - private final ServerState interruptState; - private final ServerState ceremonyState; + private final ServerState state; + + private final ServerState lobby = new Lobby(this); + private final ServerState gameState = new GameState(this); + private final ServerState interrupt = new Interrupt(this); + private final ServerState ceremony = new Ceremony(this); + private final ServerState turn = new Turn(this); + private final ServerState determineStartPlayer = new DetermineStartPlayer(this); + private final ServerState rollDice = new RollDice(this); + private final ServerState powerCard = new PowerCard(this); + private final ServerState movePiece = new MovePiece(this); + private final ServerState choosePiece = new ChoosePiece(this); + private final ServerState firstRoll = new FirstRoll(this); + private final ServerState secondRoll = new SecondRoll(this); + private final ServerState thirdRoll = new ThirdRoll(this); + private final ServerState noPiece = new NoPiece(this); + private final ServerState noTurn = new NoTurn(this); + private final ServerState waitingPiece = new WaitingPiece(this); + private final ServerState startPiece = new StartPiece(this); + private final ServerState selectPiece = new SelectPiece(this); - /** - * Constructor. - * - * @param serverSender - * @param game - */ public ServerGameLogic(ServerSender serverSender, Game game) { this.serverSender = serverSender; this.game = game; - this.lobbyState = new LobbyState(this); - this.gameState = new GameState(this); - this.interruptState = new InterruptState(this); - this.ceremonyState = new CeremonyState(this); - this.currentState = this.lobbyState; + this.state = lobby; } @Override public void received(AnimationEnd msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(DeselectTSK msg, int from) { - this.currentState.received(msg, from); + } @Override - public void received(StartGame msg, int from) { - this.currentState.received(msg, from); + public void received(ForceStartGame msg, int from) { + } @Override public void received(JoinServer msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(LeaveGame msg, int from) { - this.currentState.received(msg, from); - } - @Override - public void received(LobbyReady msg, int from) { - this.currentState.received(msg, from); } @Override public void received(LobbyNotReady msg, int from) { - this.currentState.received(msg, from); + } @Override - public void received(Disconnected msg, int from) { - this.currentState.received(msg, from); + public void received(LobbyReady msg, int from) { + } @Override public void received(RequestBriefing msg, int from) { - this.currentState.received(msg, from); + } @Override - public void received(RequestDie msg, int from) { - this.currentState.received(msg, from); + public void received(RequestDice msg, int from) { + } @Override public void received(RequestMove msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(RequestPlayCard msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(SelectCard msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(SelectTSK msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(ForceContinueGame msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(ClientStartGame msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(NoPowerCard msg, int from) { - this.currentState.received(msg, from); + } @Override public void received(SelectedPieces msg, int from) { - this.currentState.received(msg, from); - } - /** - * This method will be used to return serverSender attribute of ServerGameLogic class. - * - * @return serverSender as a ServerSender object. - */ - public ServerSender getServerSender() { - return this.serverSender; - } - - /** - * This method will be used to return game attribute of ServerGameLogic class. - * - * @return game as a Game object. - */ - public Game getGame() { - return this.game; - } - - /** - * This method will be used to return currentState attribute of ServerGameLogic class. - * - * @return currentState as a ServerState object. - */ - public ServerState getCurrentState() { - return this.currentState; - } - - /** - * This method will be used to return lobbyState attribute of ServerGameLogic class. - * - * @return lobbyState as a ServerState object. - */ - public ServerState getLobbyState() { - return this.lobbyState; - } - - /** - * This method will be used to return gameState attribute of ServerGameLogic class. - * - * @return gameState as a ServerState object. - */ - public ServerState getGameState() { - return this.gameState; - } - - /** - * This method will be used to return interruptState attribute of ServerGameLogic class. - * - * @return interruptState as a ServerState object. - */ - public ServerState getInterruptState() { - return this.interruptState; - } - - /** - * This method will be used to return ceremonyState attribute of ServerGameLogic class. - * - * @return ceremonyState as a ServerState object. - */ - public ServerState getCeremonyState() { - return this.ceremonyState; - } - - /** - * This method will be used to set currentState attribute of ServerGameLogic class to the given state parameter. - * In Addition, the currentState will be exited, changed and entered. - * - * @param state as the new currentState attribute as a ServerState object. - */ - public void setCurrentState(ServerState state) { - if (this.currentState != null) { - this.currentState.exit(); - } - this.currentState = state; - this.currentState.enter(); } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/server/Turn.java b/Projekte/mdga/model/src/main/java/pp/mdga/server/Turn.java new file mode 100644 index 00000000..e15e5bfa --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp/mdga/server/Turn.java @@ -0,0 +1,7 @@ +package pp.mdga.server; + +public class Turn extends GameState { + public Turn(ServerGameLogic logic) { + super(logic); + } +}