From 6b2d77553494912586a6b95f584586cab49e2e00 Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Sat, 16 Nov 2024 13:31:56 +0100 Subject: [PATCH 1/7] added 2 methods for Test usage in Board and PlayerData --- .../mdga/model/src/main/java/pp.mdga/game/Board.java | 10 ++++++++++ .../model/src/main/java/pp.mdga/game/PlayerData.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java b/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java index 8b48d6e4..2c6265c1 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java @@ -47,4 +47,14 @@ public Map getPlayerData() { public Node[] getInfield() { return infield; } + + /** + * This method sets a piece on a specific Node in the infield + * + * @param index the index of the node + * @param piece the piece to be set + */ + public void setPieceOnBoard(int index, Piece piece) { + infield[index].setOccupant(piece); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/game/PlayerData.java b/Projekte/mdga/model/src/main/java/pp.mdga/game/PlayerData.java index 77b2ab35..eac80356 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/game/PlayerData.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/game/PlayerData.java @@ -98,4 +98,14 @@ public Piece removePieceFromWaitingArea() { } return null; } + + /** + * This method sets a piece at the given index in the home area + * + * @param index the index of the node + * @param piece the piece to be set at the given index + */ + public void setPieceInHome(int index, Piece piece) { + homeNodes[index].setOccupant(piece); + } } From 44b623f9fd9c225bc616e3df8fa2335a480c1f87 Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Sat, 16 Nov 2024 18:58:33 +0100 Subject: [PATCH 2/7] added all Notifications for the model view communication added all required notifications with their content and getter methods. --- .../notification/AcquireCardNotification.java | 27 ++++++++++++ .../ActivePlayerNotification.java | 17 +++++++- .../notification/CeremonyNotification.java | 12 ++++++ .../notification/DiceNowNotification.java | 13 ++++++ .../notification/DicingNotification.java | 27 ++++++++++++ .../notification/DrawCardNotification.java | 29 ++++++++++++- .../notification/GameNotification.java | 12 ++++++ .../notification/HomeMoveNotification.java | 41 ++++++++++++++++++ .../notification/InterruptNotification.java | 18 +++++++- .../notification/LobbyDialogNotification.java | 12 ++++++ .../notification/MovePieceNotification.java | 31 +++++++++++++- .../notification/PieceInGameNotification.java | 28 ++++++++++++- .../notification/PlayCardNotification.java | 31 +++++++++++++- .../PlayerInGameNotification.java | 31 +++++++++++++- .../notification/ResumeNotification.java | 20 ++++++++- .../notification/RollDiceNotification.java | 42 ++++++++++++++++++- .../SelectableCardsNotification.java | 28 +++++++++++++ .../SelectablePiecesNotification.java | 26 ++++++++++++ .../notification/StartDialogNotification.java | 12 ++++++ .../notification/SwapPieceNotification.java | 34 ++++++++++++++- .../notification/TskSelectNotification.java | 27 ++++++++++++ .../notification/TskUnselectNotification.java | 24 +++++++++++ .../notification/WaitMoveNotification.java | 27 ++++++++++++ 23 files changed, 556 insertions(+), 13 deletions(-) create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/AcquireCardNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/CeremonyNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/DiceNowNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/DicingNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/GameNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/HomeMoveNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/LobbyDialogNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectableCardsNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectablePiecesNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/StartDialogNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/TskSelectNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/TskUnselectNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/WaitMoveNotification.java diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/AcquireCardNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/AcquireCardNotification.java new file mode 100644 index 00000000..6a214f90 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/AcquireCardNotification.java @@ -0,0 +1,27 @@ +package pp.mdga.notification; + +import java.util.UUID; + +/** + * Notification that is sent when a card is acquired. + */ +public class AcquireCardNotification extends Notification{ + + private UUID cardId; + + /** + * Constructor. + * @param cardId The id of the card that was acquired. + */ + public AcquireCardNotification(UUID cardId) { + this.cardId = cardId; + } + + /** + * Get the id of the card that was acquired. + * @return The id of the card that was acquired. + */ + public UUID getCardId() { + return cardId; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java index 8a2e0339..59ecfe47 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java @@ -2,8 +2,23 @@ import pp.mdga.game.Color; +/** + * Notification that the active player has changed + */ public class ActivePlayerNotification extends Notification { - ActivePlayerNotification(Color color) { + /** + * The color of the active player + */ + private Color color; + ActivePlayerNotification(Color color) { + this.color = color; + } + + /** + * @return the color of the active player + */ + public Color getColor() { + return color; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/CeremonyNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/CeremonyNotification.java new file mode 100644 index 00000000..3f88eb8a --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/CeremonyNotification.java @@ -0,0 +1,12 @@ +package pp.mdga.notification; + +/** + * Class CeremonyNotification + */ +public class CeremonyNotification extends Notification{ + /** + * Constructor + */ + CeremonyNotification() { + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/DiceNowNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DiceNowNotification.java new file mode 100644 index 00000000..fce8c9b1 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DiceNowNotification.java @@ -0,0 +1,13 @@ +package pp.mdga.notification; + +/** + * Notification that the dice is now. + */ +public class DiceNowNotification extends Notification { + + /** + * Constructor. + */ + DiceNowNotification() { + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/DicingNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DicingNotification.java new file mode 100644 index 00000000..5c1c7ecf --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DicingNotification.java @@ -0,0 +1,27 @@ +package pp.mdga.notification; + +import pp.mdga.game.Color; + +/** + * Notification that is sent when a player has diced. + */ +public class DicingNotification extends Notification{ + + private Color color; + + /** + * Constructor. + * @param color The color of the player that diced. + */ + DicingNotification(Color color) { + this.color = color; + } + + /** + * Get the color of the player that diced. + * @return The color of the player that diced. + */ + public Color getColor() { + return color; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java index a8c73551..c43702df 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java @@ -2,9 +2,34 @@ import pp.mdga.game.BonusCard; import pp.mdga.game.Color; - +/** + * Notification that a card has been drawn + */ public class DrawCardNotification extends Notification { - DrawCardNotification(Color color, BonusCard card) { + private Color color; + private BonusCard card; + + /** + * @param color the color of the player who drew the card + * @param card the card that was drawn + */ + DrawCardNotification(Color color, BonusCard card) { + this.color = color; + this.card = card; + } + + /** + * @return the color of the player who drew the card + */ + public Color getColor() { + return color; + } + + /** + * @return the card that was drawn + */ + public BonusCard getCard() { + return card; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/GameNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/GameNotification.java new file mode 100644 index 00000000..90c60694 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/GameNotification.java @@ -0,0 +1,12 @@ +package pp.mdga.notification; + +/** + * GameNotification class + */ +public class GameNotification extends Notification{ + /** + * Constructor + */ + GameNotification() { + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/HomeMoveNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/HomeMoveNotification.java new file mode 100644 index 00000000..48cecc52 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/HomeMoveNotification.java @@ -0,0 +1,41 @@ +package pp.mdga.notification; + +import java.util.UUID; + +/** + * Notification that a piece has moved to a home. + */ +public class HomeMoveNotification extends Notification { + + private UUID pieceId; + private int homeIndex; + + /** + * Constructor. + * + * @param pieceId the piece id + * @param homeIndex the home index + */ + HomeMoveNotification(UUID pieceId, int homeIndex) { + this.pieceId = pieceId; + this.homeIndex = homeIndex; + } + + /** + * Get the piece id. + * + * @return the piece id + */ + public UUID getPieceId() { + return pieceId; + } + + /** + * Get the home index. + * + * @return the home index + */ + public int getHomeIndex() { + return homeIndex; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java index f9459c55..acebe160 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java @@ -1,9 +1,23 @@ package pp.mdga.notification; import pp.mdga.game.Color; - +/** + * Notification that a card has been drawn + */ public class InterruptNotification extends Notification { - InterruptNotification(Color color) { + private Color color; + /** + * @param color the color of the player who drew the card + */ + InterruptNotification(Color color) { + this.color = color; + } + + /** + * @return the color of the player who drew the card + */ + public Color getColor() { + return color; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/LobbyDialogNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/LobbyDialogNotification.java new file mode 100644 index 00000000..7c1a4adf --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/LobbyDialogNotification.java @@ -0,0 +1,12 @@ +package pp.mdga.notification; + +/** + * Notification that a dialog has been started + */ +public class LobbyDialogNotification extends Notification{ + /** + * Constructor + */ + LobbyDialogNotification() { + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/MovePieceNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/MovePieceNotification.java index b35918cc..7a5ed1d1 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/MovePieceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/MovePieceNotification.java @@ -2,8 +2,37 @@ import pp.mdga.game.Color; +/** + * Notification that a piece has been moved. + */ public class MovePieceNotification extends Notification { - MovePieceNotification(Color color, int nodeIndex) { + private Color color; + private int nodeIndex; + + /** + * Constructor. + * @param color the color of the piece that has been moved. + * @param nodeIndex the index of the node the piece has been moved to. + */ + MovePieceNotification(Color color, int nodeIndex) { + this.color = color; + this.nodeIndex = nodeIndex; + } + + /** + * Get the color of the piece that has been moved. + * @return the color of the piece that has been moved. + */ + public Color getColor() { + return color; + } + + /** + * Get the index of the node the piece has been moved to. + * @return the index of the node the piece has been moved to. + */ + public int getNodeIndex() { + return nodeIndex; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/PieceInGameNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/PieceInGameNotification.java index 5e0585fd..7afce473 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/PieceInGameNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/PieceInGameNotification.java @@ -4,8 +4,34 @@ import java.util.UUID; +/** + * Notification that a piece is in the game + */ public class PieceInGameNotification extends Notification{ - PieceInGameNotification(Color color, UUID id) { + private Color color; + private UUID id; + /** + * Constructor + * @param color the color of the piece + * @param id the id of the piece + */ + PieceInGameNotification(Color color, UUID id) { + this.color = color; + this.id = id; + } + + /** + * @return the color of the piece + */ + public Color getColor() { + return null; + } + + /** + * @return the id of the piece + */ + public UUID getId() { + return null; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayCardNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayCardNotification.java index f2e73063..d554a0e6 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayCardNotification.java @@ -3,8 +3,37 @@ import pp.mdga.game.BonusCard; import pp.mdga.game.Color; +/** + * Notification that a card has been played. + */ public class PlayCardNotification extends Notification { - PlayCardNotification(Color color, BonusCard card) { + private Color color; + private BonusCard card; + + /** + * Constructor. + * @param color the color of the player that played the card. + * @param card the card that was played. + */ + PlayCardNotification(Color color, BonusCard card) { + this.color = color; + this.card = card; + } + + /** + * Get the color of the player that played the card. + * @return the color of the player that played the card. + */ + public Color getColor() { + return color; + } + + /** + * Get the card that was played. + * @return the card that was played. + */ + public BonusCard getCard() { + return card; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayerInGameNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayerInGameNotification.java index c1c77cc9..1db710c9 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayerInGameNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/PlayerInGameNotification.java @@ -2,8 +2,37 @@ import pp.mdga.game.Color; +/** + * Notification that a player is in the game. + */ public class PlayerInGameNotification extends Notification { - PlayerInGameNotification(Color color, String name) { + private Color color; + private String name; + + /** + * Constructor. + * @param color the color of the player that is in the game. + * @param name the name of the player that is in the game. + */ + PlayerInGameNotification(Color color, String name) { + this.color = color; + this.name = name; + } + + /** + * Get the color of the player that is in the game. + * @return the color of the player that is in the game. + */ + public Color getColor() { + return color; + } + + /** + * Get the name of the player that is in the game. + * @return the name of the player that is in the game. + */ + public String getName() { + return name; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ResumeNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ResumeNotification.java index 6a28137d..98533e06 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ResumeNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ResumeNotification.java @@ -2,8 +2,26 @@ import pp.mdga.game.Color; +/** + * Notification that a player is in the game. + */ public class ResumeNotification extends Notification { - ResumeNotification(Color color) { + private Color color; + + /** + * Constructor. + * @param color the color of the player that is in the game. + */ + ResumeNotification(Color color) { + this.color = color; + } + + /** + * Get the color of the player that is in the game. + * @return the color of the player that is in the game. + */ + public Color getColor() { + return color; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/RollDiceNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/RollDiceNotification.java index 48ca8192..b6bd27c3 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/RollDiceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/RollDiceNotification.java @@ -2,8 +2,48 @@ import pp.mdga.game.Color; +/** + * Notification that a die has been rolled. + */ public class RollDiceNotification extends Notification{ - RollDiceNotification(Color color, int eyes, int moveNumber) { + private Color color; + private int eyes; + private int moveNumber; + + /** + * Constructor. + * @param color the color of the player that rolled the die. + * @param eyes the number of eyes that were rolled. + * @param moveNumber the number of the move that was made. + */ + RollDiceNotification(Color color, int eyes, int moveNumber) { + this.color = color; + this.eyes = eyes; + this.moveNumber = moveNumber; + } + + /** + * Get the color of the player that rolled the die. + * @return the color of the player that rolled the die. + */ + public Color getColor() { + return color; + } + + /** + * Get the number of eyes that were rolled. + * @return the number of eyes that were rolled. + */ + public int getEyes() { + return eyes; + } + + /** + * Get the number of the move that was made. + * @return the number of the move that was made. + */ + public int getMoveNumber() { + return moveNumber; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectableCardsNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectableCardsNotification.java new file mode 100644 index 00000000..925bde75 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectableCardsNotification.java @@ -0,0 +1,28 @@ +package pp.mdga.notification; + +import pp.mdga.game.BonusCard; +import java.util.List; + +/** + * Notification that contains a list of cards that the player can choose from. + */ +public class SelectableCardsNotification extends Notification { + + private List cards; + + /** + * Constructor. + * @param cards The list of cards that the player can choose from. + */ + SelectableCardsNotification(List cards) { + this.cards = cards; + } + + /** + * Get the list of cards that the player can choose from. + * @return The list of cards that the player can choose from. + */ + public List getCards() { + return cards; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectablePiecesNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectablePiecesNotification.java new file mode 100644 index 00000000..7179a721 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/SelectablePiecesNotification.java @@ -0,0 +1,26 @@ +package pp.mdga.notification; + +import java.util.List; +import java.util.UUID; + +/** + * Notification to inform the client about the selectable pieces. + */ +public class SelectablePiecesNotification extends Notification{ + + private List selectablePieces; + + /** + * @param selectablePieces + */ + SelectablePiecesNotification(List selectablePieces){ + this.selectablePieces = selectablePieces; + } + + /** + * @return List + */ + public List getSelectablePieces(){ + return selectablePieces; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/StartDialogNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/StartDialogNotification.java new file mode 100644 index 00000000..f2458c14 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/StartDialogNotification.java @@ -0,0 +1,12 @@ +package pp.mdga.notification; + +/** + * Notification that a dialog has been started + */ +public class StartDialogNotification extends Notification{ + /** + * Constructor + */ + StartDialogNotification() { + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/SwapPieceNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/SwapPieceNotification.java index b287e403..2032f66a 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/SwapPieceNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/SwapPieceNotification.java @@ -2,8 +2,38 @@ import java.util.UUID; +/** + * Notification that two pieces have been swapped. + */ public class SwapPieceNotification extends Notification { - SwapPieceNotification(UUID a, UUID b) { - assert(!a.equals(b)); + + private UUID firstPiece; + private UUID secondPiece; + + /** + * Constructor. + * @param firstPiece the UUID of the first piece that has been swapped. + * @param secondPiece the UUID of the second piece that has been swapped. + */ + SwapPieceNotification(UUID firstPiece, UUID secondPiece) { + assert(!firstPiece.equals(secondPiece)); + this.firstPiece = firstPiece; + this.secondPiece = secondPiece; + } + + /** + * Get the UUID of the first piece that has been swapped. + * @return the UUID of the first piece that has been swapped. + */ + public UUID getFirstPiece() { + return firstPiece; + } + + /** + * Get the UUID of the second piece that has been swapped. + * @return the UUID of the second piece that has been swapped. + */ + public UUID getSecondPiece() { + return secondPiece; } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/TskSelectNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/TskSelectNotification.java new file mode 100644 index 00000000..11884267 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/TskSelectNotification.java @@ -0,0 +1,27 @@ +package pp.mdga.notification; + +import pp.mdga.game.Color; + +/** + * Class TskSelectNotification + */ +public class TskSelectNotification extends Notification{ + + private Color color; + + /** + * Constructor. + * @param color the color of the player that is in the game. + */ + TskSelectNotification(Color color) { + this.color = color; + } + + /** + * Get the color of the player that is in the game. + * @return the color of the player that is in the game. + */ + public Color getColor() { + return color; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/TskUnselectNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/TskUnselectNotification.java new file mode 100644 index 00000000..0f96beb1 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/TskUnselectNotification.java @@ -0,0 +1,24 @@ +package pp.mdga.notification; + +import pp.mdga.game.Color; + +public class TskUnselectNotification extends Notification{ + + private Color color; + + /** + * Constructor + * @param color + */ + TskUnselectNotification(Color color){ + this.color = color; + } + + /** + * Get the color + * @return color + */ + public Color getColor() { + return color; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/WaitMoveNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/WaitMoveNotification.java new file mode 100644 index 00000000..bb2e9e8a --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/WaitMoveNotification.java @@ -0,0 +1,27 @@ +package pp.mdga.notification; + +import java.util.UUID; + +/** + * Notification to inform the player that he has to wait for the other player to move. + */ +public class WaitMoveNotification extends Notification{ + + private UUID pieceId; + + /** + * Constructor. + * @param pieceId the id of the piece that has to move. + */ + public WaitMoveNotification(UUID pieceId) { + this.pieceId = pieceId; + } + + /** + * Get the id of the piece that has to move. + * @return the id of the piece that has to move. + */ + public UUID getPieceId() { + return pieceId; + } +} From 0845aa80f9bba3aa7f3d5db1232b3525081ca448 Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Sat, 16 Nov 2024 22:31:11 +0100 Subject: [PATCH 3/7] adjusted the model infield creation to represent the current view postion regarding the placement of the teams on the board --- Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java b/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java index 2c6265c1..05d4f84f 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java @@ -17,10 +17,10 @@ public Board() { for (int i = 0; i < 40; i++) { if (i % 10 == 0) { infield[i] = new StartNode( - i == 0 ? Color.ARMY : - i == 10 ? Color.AIRFORCE : - i == 20 ? Color.CYBER : - Color.NAVY + i == 0 ? Color.AIRFORCE : + i == 10 ? Color.CYBER : + i == 20 ? Color.NAVY : + Color.ARMY ); } else if (i == 4 || i == 14 || i == 24 || i == 34) { infield[i] = new BonusNode(); From 020aa92cabd0892ee1e3263989e8dbaf7ad84c3a Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Sun, 17 Nov 2024 10:39:36 +0100 Subject: [PATCH 4/7] added 4 more Notifications for Model -> View interaction --- .../MoveThrowPieceNotification.java | 64 +++++++++++++++++++ .../notification/NoShieldNotification.java | 27 ++++++++ .../ShieldActiveNotification.java | 29 +++++++++ .../ShieldSuppressedNotification.java | 29 +++++++++ 4 files changed, 149 insertions(+) create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/MoveThrowPieceNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/NoShieldNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldActiveNotification.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldSuppressedNotification.java diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/MoveThrowPieceNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/MoveThrowPieceNotification.java new file mode 100644 index 00000000..d9da6d38 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/MoveThrowPieceNotification.java @@ -0,0 +1,64 @@ +package pp.mdga.notification; + +import pp.mdga.game.Color; + +import java.util.UUID; + +public class MoveThrowPieceNotification extends Notification{ + + private UUID pieceId1; + private UUID pieceId2; + private int nodeIndex; + private Color colorPiece2; + + /** + * This constructor is used to create a new MoveThrowPieceNotification + * + * @param pieceId1 the pieceId1 + * @param pieceId2 the pieceId2 + * @param nodeIndex the nodeIndex + * @param colorPiece2 the color + */ + public MoveThrowPieceNotification(UUID pieceId1, UUID pieceId2, int nodeIndex, Color colorPiece2) { + this.pieceId1 = pieceId1; + this.pieceId2 = pieceId2; + this.nodeIndex = nodeIndex; + this.colorPiece2 = colorPiece2; + } + + /** + * This method returns the pieceId1 + * + * @return the pieceId1 + */ + public UUID getPieceId1() { + return pieceId1; + } + + /** + * This method returns the pieceId2 + * + * @return the pieceId2 + */ + public UUID getPieceId2() { + return pieceId2; + } + + /** + * This method returns the nodeIndex + * + * @return the nodeIndex + */ + public int getNodeIndex() { + return nodeIndex; + } + + /** + * This method returns the color + * + * @return the color + */ + public Color getColor() { + return colorPiece2; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/NoShieldNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/NoShieldNotification.java new file mode 100644 index 00000000..e17d0b33 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/NoShieldNotification.java @@ -0,0 +1,27 @@ +package pp.mdga.notification; + +import java.util.UUID; + +/** + * Notification that a piece has no shield. + */ +public class NoShieldNotification extends Notification{ + + private UUID pieceId; + + /** + * Constructor. + * @param pieceId the id of the piece that has no shield. + */ + public NoShieldNotification(UUID pieceId) { + this.pieceId = pieceId; + } + + /** + * Get the id of the piece that has no shield. + * @return the id of the piece that has no shield. + */ + public UUID getPieceId() { + return pieceId; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldActiveNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldActiveNotification.java new file mode 100644 index 00000000..0cb6c15b --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldActiveNotification.java @@ -0,0 +1,29 @@ +package pp.mdga.notification; + +import java.util.UUID; + +/** + * This class will be used to hold all ShieldActiveNotification relevant data. + */ +public class ShieldActiveNotification extends Notification{ + + private UUID pieceId; + + /** + * This constructor is used to create a new ShieldActiveNotification + * + * @param pieceId the pieceId + */ + public ShieldActiveNotification(UUID pieceId) { + this.pieceId = pieceId; + } + + /** + * This method returns the pieceId + * + * @return the pieceId + */ + public UUID getPieceId() { + return pieceId; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldSuppressedNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldSuppressedNotification.java new file mode 100644 index 00000000..ce7f7a8f --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ShieldSuppressedNotification.java @@ -0,0 +1,29 @@ +package pp.mdga.notification; + +import java.util.UUID; + +/** + * This class will be used to hold all ShieldSuppressedNotification relevant data. + */ +public class ShieldSuppressedNotification extends Notification { + + private UUID pieceId; + + /** + * This constructor is used to create a new ShieldSuppressedNotification + * + * @param pieceId the pieceId + */ + public ShieldSuppressedNotification(UUID pieceId) { + this.pieceId = pieceId; + } + + /** + * This method returns the pieceId + * + * @return the pieceId + */ + public UUID getPieceId() { + return pieceId; + } +} From a9265547090d3321a6738a7621d1228b02f60e31 Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Sun, 17 Nov 2024 12:01:00 +0100 Subject: [PATCH 5/7] adjusted for check style --- .../src/main/java/pp/mdga/client/Animation/Animation.java | 3 +++ .../java/pp.mdga/notification/ActivePlayerNotification.java | 1 + .../main/java/pp.mdga/notification/DrawCardNotification.java | 1 + .../main/java/pp.mdga/notification/InterruptNotification.java | 2 ++ 4 files changed, 7 insertions(+) diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Animation/Animation.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Animation/Animation.java index 0ca7adcb..4db87cec 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Animation/Animation.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Animation/Animation.java @@ -1,7 +1,10 @@ package pp.mdga.client.Animation; abstract class Animation { + abstract void play(); + abstract void stop(); + abstract boolean isOver(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java index 59ecfe47..e557e8ce 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/ActivePlayerNotification.java @@ -11,6 +11,7 @@ public class ActivePlayerNotification extends Notification { * The color of the active player */ private Color color; + ActivePlayerNotification(Color color) { this.color = color; } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java index c43702df..2de500c0 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/DrawCardNotification.java @@ -2,6 +2,7 @@ import pp.mdga.game.BonusCard; import pp.mdga.game.Color; + /** * Notification that a card has been drawn */ diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java b/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java index acebe160..e9a61de6 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/notification/InterruptNotification.java @@ -1,10 +1,12 @@ package pp.mdga.notification; import pp.mdga.game.Color; + /** * Notification that a card has been drawn */ public class InterruptNotification extends Notification { + private Color color; /** From aae7ed9a87c69205a09e6c64c92a7717d38e4853 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 17 Nov 2024 15:27:09 +0100 Subject: [PATCH 6/7] added classes for client and server state machine - a client state machine consits out of a 'ClientState' (every state of the machine) and a 'ClientStateMachine' (every state, which consists out of states), the machine starts with the ClientAutomaton - analog for server - started to implement logic for the server, transition from 'Lobby' to 'GameState' --- .../main/java/pp.mdga/client/Animation.java | 4 + .../java/pp.mdga/client/AudioSettings.java | 2 +- .../main/java/pp.mdga/client/Ceremony.java | 1 + .../pp.mdga/client/CeremonyStateMachine.java | 4 + .../main/java/pp.mdga/client/ChoosePiece.java | 3 +- .../client/ChoosePieceStateMachine.java | 4 + .../java/pp.mdga/client/ChoosePowerCard.java | 2 +- .../java/pp.mdga/client/ClientAutomaton.java | 4 + .../main/java/pp.mdga/client/ClientState.java | 2 +- .../pp.mdga/client/ClientStateMachine.java | 4 + .../pp.mdga/client/DetermineStartPlayer.java | 3 +- .../DetermineStartPlayerStateMachine.java | 4 + .../src/main/java/pp.mdga/client/Dialogs.java | 1 + .../pp.mdga/client/DialogsStateMachine.java | 4 + .../src/main/java/pp.mdga/client/Game.java | 4 - .../main/java/pp.mdga/client/GameState.java | 5 + .../java/pp.mdga/client/GameStateMachine.java | 4 + .../src/main/java/pp.mdga/client/Lobby.java | 2 +- .../java/pp.mdga/client/MainSettings.java | 2 +- .../main/java/pp.mdga/client/MovePiece.java | 2 +- .../java/pp.mdga/client/NetworkDialog.java | 2 +- .../src/main/java/pp.mdga/client/NoPiece.java | 2 +- .../java/pp.mdga/client/PlayPowerCard.java | 2 +- .../src/main/java/pp.mdga/client/Podium.java | 4 + .../main/java/pp.mdga/client/PowerCard.java | 3 +- .../pp.mdga/client/PowerCardStateMachine.java | 4 + .../main/java/pp.mdga/client/RollDice.java | 2 +- .../java/pp.mdga/client/RollRankingDice.java | 2 +- .../main/java/pp.mdga/client/SelectPiece.java | 2 +- .../main/java/pp.mdga/client/Settings.java | 3 +- .../pp.mdga/client/SettingsStateMachine.java | 4 + .../src/main/java/pp.mdga/client/Shield.java | 2 +- .../main/java/pp.mdga/client/Spectator.java | 2 +- .../main/java/pp.mdga/client/StartPiece.java | 2 +- .../main/java/pp.mdga/client/Statistics.java | 4 + .../src/main/java/pp.mdga/client/Swap.java | 4 + .../main/java/pp.mdga/client/SwitchEnemy.java | 4 - .../main/java/pp.mdga/client/SwitchOwn.java | 4 - .../src/main/java/pp.mdga/client/Turn.java | 3 +- .../java/pp.mdga/client/TurnStateMachine.java | 4 + .../java/pp.mdga/client/VideoSettings.java | 2 +- .../main/java/pp.mdga/client/WaitRanking.java | 2 +- .../src/main/java/pp.mdga/client/Waiting.java | 2 +- .../java/pp.mdga/client/WaitingPiece.java | 2 +- .../src/main/java/pp.mdga/game/Game.java | 85 +++++++++++-- .../src/main/java/pp.mdga/game/Player.java | 9 ++ .../message/client/ClientInterpreter.java | 6 + .../pp.mdga/message/client/ClientMessage.java | 1 - .../message/client/ClientStartGame.java | 13 ++ .../pp.mdga/message/client/NoPowerCard.java | 13 ++ .../message/client/SelectedPieces.java | 13 ++ .../{StartGame.java => ServerStartGame.java} | 2 +- .../main/java/pp.mdga/server/Ceremony.java | 3 + .../main/java/pp.mdga/server/ChoosePiece.java | 7 +- .../server/ChoosePieceStateMachine.java | 12 ++ .../pp.mdga/server/DetermineStartPlayer.java | 5 +- .../src/main/java/pp.mdga/server/Dialogs.java | 4 - .../main/java/pp.mdga/server/FirstRoll.java | 5 +- .../src/main/java/pp.mdga/server/Game.java | 4 - .../main/java/pp.mdga/server/GameState.java | 75 ++++++++++++ .../java/pp.mdga/server/GameStateMachine.java | 12 ++ .../main/java/pp.mdga/server/Interrupt.java | 3 + .../src/main/java/pp.mdga/server/Lobby.java | 52 ++++++++ .../main/java/pp.mdga/server/MovePiece.java | 5 +- .../src/main/java/pp.mdga/server/NoPiece.java | 5 +- .../src/main/java/pp.mdga/server/NoTurn.java | 5 +- .../main/java/pp.mdga/server/Observer.java | 5 + .../main/java/pp.mdga/server/PowerCard.java | 5 +- .../main/java/pp.mdga/server/RollDice.java | 7 +- .../java/pp.mdga/server/RollDiceMachine.java | 12 ++ .../main/java/pp.mdga/server/SecondRoll.java | 5 +- .../main/java/pp.mdga/server/SelectPiece.java | 5 +- .../java/pp.mdga/server/ServerAutomaton.java | 13 ++ .../java/pp.mdga/server/ServerGameLogic.java | 56 ++++++++- .../java/pp.mdga/server/ServerSender.java | 7 ++ .../main/java/pp.mdga/server/ServerState.java | 63 +++++++++- .../pp.mdga/server/ServerStateMachine.java | 114 ++++++++++++++++++ .../main/java/pp.mdga/server/StartPiece.java | 5 +- .../main/java/pp.mdga/server/ThirdRoll.java | 5 +- .../src/main/java/pp.mdga/server/Turn.java | 5 + .../java/pp.mdga/server/TurnStateMachine.java | 12 ++ .../java/pp.mdga/server/WaitingPiece.java | 5 +- 82 files changed, 719 insertions(+), 72 deletions(-) create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/Animation.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/CeremonyStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePieceStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/ClientAutomaton.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/ClientStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayerStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/DialogsStateMachine.java delete mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/Game.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/GameState.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/GameStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/Podium.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCardStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/SettingsStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/Statistics.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/Swap.java delete mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchEnemy.java delete mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchOwn.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/client/TurnStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientStartGame.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/message/client/NoPowerCard.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/message/client/SelectedPieces.java rename Projekte/mdga/model/src/main/java/pp.mdga/message/server/{StartGame.java => ServerStartGame.java} (78%) create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePieceStateMachine.java delete mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/Dialogs.java delete mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/Game.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/GameState.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/GameStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/Lobby.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/Observer.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/RollDiceMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/ServerAutomaton.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/ServerSender.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/ServerStateMachine.java create mode 100644 Projekte/mdga/model/src/main/java/pp.mdga/server/TurnStateMachine.java diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Animation.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Animation.java new file mode 100644 index 00000000..73f8f285 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Animation.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class Animation extends ClientState { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/AudioSettings.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/AudioSettings.java index 28fdc5e7..b1eaade6 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/AudioSettings.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/AudioSettings.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class AudioSettings extends Settings { +public class AudioSettings extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Ceremony.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Ceremony.java index cc2681b8..7be5866a 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Ceremony.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Ceremony.java @@ -1,4 +1,5 @@ package pp.mdga.client; public class Ceremony extends ClientState { + private final CeremonyStateMachine ceremonyStateMachine = new CeremonyStateMachine(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/CeremonyStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/CeremonyStateMachine.java new file mode 100644 index 00000000..0449027d --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/CeremonyStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class CeremonyStateMachine extends ClientStateMachine { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePiece.java index 053b5b1f..0b9fd192 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePiece.java @@ -1,4 +1,5 @@ package pp.mdga.client; -public class ChoosePiece extends Turn { +public class ChoosePiece extends ClientState { + private final ChoosePieceStateMachine choosePieceStateMachine = new ChoosePieceStateMachine(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePieceStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePieceStateMachine.java new file mode 100644 index 00000000..45c965b6 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePieceStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class ChoosePieceStateMachine extends ClientStateMachine{ +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePowerCard.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePowerCard.java index 2e5a7e50..72a8d3d4 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePowerCard.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/ChoosePowerCard.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class ChoosePowerCard extends PowerCard { +public class ChoosePowerCard extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientAutomaton.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientAutomaton.java new file mode 100644 index 00000000..f5261224 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientAutomaton.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class ClientAutomaton extends ClientStateMachine { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientState.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientState.java index 31a6ec61..9e7c3786 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientState.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientState.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class ClientState { +public abstract class ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientStateMachine.java new file mode 100644 index 00000000..0c8717e9 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/ClientStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public abstract class ClientStateMachine extends ClientState { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java index f0a863b7..b12b6a6d 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java @@ -1,4 +1,5 @@ package pp.mdga.client; -public class DetermineStartPlayer extends Game { +public class DetermineStartPlayer extends ClientState { + private final DetermineStartPlayerStateMachine determineStartPlayerStateMachine = new DetermineStartPlayerStateMachine(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayerStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayerStateMachine.java new file mode 100644 index 00000000..f8a2aeda --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayerStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class DetermineStartPlayerStateMachine extends ClientStateMachine{ +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Dialogs.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Dialogs.java index 3751c493..6b144ca8 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Dialogs.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Dialogs.java @@ -1,4 +1,5 @@ package pp.mdga.client; public class Dialogs extends ClientState { + private final DialogsStateMachine dialogsStateMachine = new DialogsStateMachine(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/DialogsStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/DialogsStateMachine.java new file mode 100644 index 00000000..a1097aab --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/DialogsStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class DialogsStateMachine extends ClientStateMachine { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Game.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Game.java deleted file mode 100644 index 8d30a46a..00000000 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Game.java +++ /dev/null @@ -1,4 +0,0 @@ -package pp.mdga.client; - -public class Game extends ClientState { -} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/GameState.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/GameState.java new file mode 100644 index 00000000..f4ac25fc --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/GameState.java @@ -0,0 +1,5 @@ +package pp.mdga.client; + +public class GameState extends ClientState { + private final GameStateMachine gameStateMachine = new GameStateMachine(); +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/GameStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/GameStateMachine.java new file mode 100644 index 00000000..9686b7e6 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/GameStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class GameStateMachine extends ClientStateMachine { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Lobby.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Lobby.java index a1818a79..a2f0f1c0 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Lobby.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Lobby.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class Lobby extends Dialogs { +public class Lobby extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/MainSettings.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/MainSettings.java index c0220619..67e641bd 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/MainSettings.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/MainSettings.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class MainSettings extends Settings { +public class MainSettings extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/MovePiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/MovePiece.java index 1ac11f65..e8c4c60b 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/MovePiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/MovePiece.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class MovePiece extends Turn { +public class MovePiece extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/NetworkDialog.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/NetworkDialog.java index a61f60d9..846a5a02 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/NetworkDialog.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/NetworkDialog.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class NetworkDialog extends Dialogs { +public class NetworkDialog extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/NoPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/NoPiece.java index 5724881a..a52655b3 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/NoPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/NoPiece.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class NoPiece extends ChoosePiece { +public class NoPiece extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/PlayPowerCard.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/PlayPowerCard.java index 6788cc18..1d79e516 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/PlayPowerCard.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/PlayPowerCard.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class PlayPowerCard extends PowerCard { +public class PlayPowerCard extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Podium.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Podium.java new file mode 100644 index 00000000..8819183e --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Podium.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class Podium extends ClientState { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCard.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCard.java index 7efd36f7..2ad3c2d1 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCard.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCard.java @@ -1,4 +1,5 @@ package pp.mdga.client; -public class PowerCard extends Turn { +public class PowerCard extends ClientState { + private final PowerCardStateMachine powerCardStateMachine = new PowerCardStateMachine(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCardStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCardStateMachine.java new file mode 100644 index 00000000..0bb5c60c --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/PowerCardStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class PowerCardStateMachine extends ClientStateMachine { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/RollDice.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/RollDice.java index 9c8f65c3..f1056203 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/RollDice.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/RollDice.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class RollDice extends Turn { +public class RollDice extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/RollRankingDice.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/RollRankingDice.java index 81171d9d..45871c8d 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/RollRankingDice.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/RollRankingDice.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class RollRankingDice extends DetermineStartPlayer { +public class RollRankingDice extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/SelectPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/SelectPiece.java index accebcfa..083ba28f 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/SelectPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/SelectPiece.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class SelectPiece extends ChoosePiece { +public class SelectPiece extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Settings.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Settings.java index 006da013..2c118580 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Settings.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Settings.java @@ -1,4 +1,5 @@ package pp.mdga.client; -public class Settings { +public class Settings extends ClientState { + private final SettingsStateMachine settingsStateMachine = new SettingsStateMachine(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/SettingsStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/SettingsStateMachine.java new file mode 100644 index 00000000..e45870dd --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/SettingsStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class SettingsStateMachine extends ClientStateMachine { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Shield.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Shield.java index 67dce1d8..eaaa67cc 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Shield.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Shield.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class Shield extends PowerCard { +public class Shield extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java index 713aee9a..50fc01f7 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class Spectator extends Game { +public class Spectator extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/StartPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/StartPiece.java index f7e86512..1330df6c 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/StartPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/StartPiece.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class StartPiece extends ChoosePiece { +public class StartPiece extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Statistics.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Statistics.java new file mode 100644 index 00000000..e46a5e1d --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Statistics.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class Statistics extends ClientState { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Swap.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Swap.java new file mode 100644 index 00000000..60a9d28e --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Swap.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class Swap extends ClientState { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchEnemy.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchEnemy.java deleted file mode 100644 index b136ca16..00000000 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchEnemy.java +++ /dev/null @@ -1,4 +0,0 @@ -package pp.mdga.client; - -public class SwitchEnemy extends PowerCard { -} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchOwn.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchOwn.java deleted file mode 100644 index b4cd6526..00000000 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/SwitchOwn.java +++ /dev/null @@ -1,4 +0,0 @@ -package pp.mdga.client; - -public class SwitchOwn extends PowerCard { -} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java index 5dc54c3e..db60e158 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java @@ -1,4 +1,5 @@ package pp.mdga.client; -public class Turn extends Game { +public class Turn extends ClientState { + private final TurnStateMachine turnStateMachine = new TurnStateMachine(); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/TurnStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/TurnStateMachine.java new file mode 100644 index 00000000..892cf3e6 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/TurnStateMachine.java @@ -0,0 +1,4 @@ +package pp.mdga.client; + +public class TurnStateMachine extends ClientStateMachine { +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/VideoSettings.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/VideoSettings.java index e87036af..32d13929 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/VideoSettings.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/VideoSettings.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class VideoSettings extends Settings { +public class VideoSettings extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitRanking.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitRanking.java index a99a3696..5614da6a 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitRanking.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitRanking.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class WaitRanking extends DetermineStartPlayer { +public class WaitRanking extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java index 82791f28..4f0d719b 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class Waiting extends Game { +public class Waiting extends ClientState { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitingPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitingPiece.java index 529f01c9..d07fe63e 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitingPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/WaitingPiece.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class WaitingPiece extends ChoosePiece { +public class WaitingPiece extends ClientState { } 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 92a5dd30..bdbdcd5e 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 @@ -1,8 +1,8 @@ package pp.mdga.game; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.Map; +import java.util.*; + +import pp.mdga.server.Observer; /** * The Game class represents the game state of the Ludo game. @@ -12,7 +12,7 @@ public class Game { private int diceModifier = 1; private int diceEyes; - private Map players; + private Map players = new HashMap(); private Statistic gameStatistics; private ArrayList drawPile; private ArrayList discardPile = new ArrayList<>(); @@ -21,13 +21,17 @@ public class Game { private LinkedList order; private Map playerConnectionID; + private ArrayList observers = new ArrayList<>(); + private Boolean gameHasStarted = false; + private Boolean playerHasDisconnected = 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. */ - public Game(){ + public Game() { gameStatistics = new Statistic(); drawPile = new ArrayList<>(); for (int i = 0; i < AMOUNT_OF_TURBO_CARDS; i++) { @@ -223,7 +227,7 @@ public void setPlayerConnectionID(Map playerConnectionID) { /** * This method sets the player connection ID. * - * @param color the color of the player + * @param color the color of the player * @param connectionID the new connection ID */ public void setPlayerConnectionID(Color color, int connectionID) { @@ -243,7 +247,7 @@ public int getPlayerConnectionID(Color color) { /** * This method adds a player to the game. * - * @param color the color of the player + * @param color the color of the player * @param player the player to be added */ public void addPlayer(Color color, Player player) { @@ -258,4 +262,71 @@ public void addPlayer(Color color, Player player) { public void removePlayer(Color color) { players.remove(color); } + + /** + * This method adds an observer to the game. + * + * @param observer the observer to be added + */ + public void addObserver(Observer observer) { + observers.add(observer); + } + + /** + * This method removes an observer from the game. + * + * @param observer the observer to be removed + */ + public void removeObserver(Observer observer) { + observers.remove(observer); + } + + /** + * This method returns the game has started. + * + * @return the game has started + */ + public Boolean getGameHasStarted() { + return gameHasStarted; + } + + /** + * This method sets the game has started. + * + * @param gameHasStarted the new game has started + */ + public void setGameHasStarted(Boolean gameHasStarted) { + this.gameHasStarted = gameHasStarted; + if (gameHasStarted) notifyObservers(); + } + + /** + * This method returns the player has disconnected. + * + * @return the player has disconnected + */ + public Boolean getPlayerHasDisconnected() { + return playerHasDisconnected; + } + + /** + * This method sets the player has disconnected. + * + * @param playerHasDisconnected the new player has disconnected + */ + public void setPlayerHasDisconnected(Boolean playerHasDisconnected) { + this.playerHasDisconnected = playerHasDisconnected; + if (playerHasDisconnected) { + notifyObservers(); + } + } + + /** + * This method notifies the observers. + */ + public void notifyObservers() { + for (Observer observer : new ArrayList<>(observers)) { + observer.update(); + } + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/game/Player.java b/Projekte/mdga/model/src/main/java/pp.mdga/game/Player.java index 2a97d27c..e9e16645 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/game/Player.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/game/Player.java @@ -79,4 +79,13 @@ public BonusCard removeHandCard(BonusCard card) { } return cardToRemove; } + + /** + * Returns the id of the connection to the client represented by this player. + * + * @return the id + */ + public int getId() { + return id; + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientInterpreter.java b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientInterpreter.java index b406a5da..0b7ec4d5 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientInterpreter.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientInterpreter.java @@ -28,4 +28,10 @@ public interface ClientInterpreter { void received(SelectTSK selectTSK , int from); void received(ForceContinueGame forceContinueGame, int from); + + void received(ClientStartGame clientStartGame, int from); + + void received(NoPowerCard noPowerCard, int from); + + void received(SelectedPieces selectedPieces, int from); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientMessage.java b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientMessage.java index 11dae3e0..9ae2d921 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientMessage.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientMessage.java @@ -3,7 +3,6 @@ import com.jme3.network.AbstractMessage; public abstract class ClientMessage extends AbstractMessage { - protected ClientMessage() { super(true); } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientStartGame.java b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientStartGame.java new file mode 100644 index 00000000..86a69f73 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/ClientStartGame.java @@ -0,0 +1,13 @@ +package pp.mdga.message.client; + +public class ClientStartGame extends ClientMessage { + @Override + public String toString() { + return "null"; + } + + @Override + public void accept(ClientInterpreter interpreter, int from) { + interpreter.received(this, from); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/message/client/NoPowerCard.java b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/NoPowerCard.java new file mode 100644 index 00000000..3fa227de --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/NoPowerCard.java @@ -0,0 +1,13 @@ +package pp.mdga.message.client; + +public class NoPowerCard extends ClientMessage { + @Override + public String toString() { + return "null"; + } + + @Override + public void accept(ClientInterpreter interpreter, int from) { + interpreter.received(this, from); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/message/client/SelectedPieces.java b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/SelectedPieces.java new file mode 100644 index 00000000..d8978857 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/message/client/SelectedPieces.java @@ -0,0 +1,13 @@ +package pp.mdga.message.client; + +public class SelectedPieces extends ClientMessage { + @Override + public String toString() { + return "null"; + } + + @Override + public void accept(ClientInterpreter interpreter, int from) { + interpreter.received(this, from); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/message/server/StartGame.java b/Projekte/mdga/model/src/main/java/pp.mdga/message/server/ServerStartGame.java similarity index 78% rename from Projekte/mdga/model/src/main/java/pp.mdga/message/server/StartGame.java rename to Projekte/mdga/model/src/main/java/pp.mdga/message/server/ServerStartGame.java index 0f189f65..5a684bb8 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/message/server/StartGame.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/message/server/ServerStartGame.java @@ -1,6 +1,6 @@ package pp.mdga.message.server; -public class StartGame extends ServerMessage { +public class ServerStartGame extends ServerMessage { @Override public void accept(ServerInterpreter interpreter) { diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/Ceremony.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/Ceremony.java index 75c1386b..667aa927 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/Ceremony.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/Ceremony.java @@ -1,4 +1,7 @@ package pp.mdga.server; public class Ceremony extends ServerState { + public Ceremony(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePiece.java index b61504e8..b9e6f4be 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePiece.java @@ -1,4 +1,9 @@ package pp.mdga.server; -public class ChoosePiece extends Turn { +public class ChoosePiece extends ServerState { + private final ChoosePieceStateMachine choosePieceStateMachine = new ChoosePieceStateMachine(this, logic); + + public ChoosePiece(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePieceStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePieceStateMachine.java new file mode 100644 index 00000000..89dbefeb --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/ChoosePieceStateMachine.java @@ -0,0 +1,12 @@ +package pp.mdga.server; + +public class ChoosePieceStateMachine extends ServerStateMachine{ + public ChoosePieceStateMachine(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } + + @Override + public ServerState initialState() { + 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 index 51cb17fc..6160701f 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/DetermineStartPlayer.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/DetermineStartPlayer.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class DetermineStartPlayer extends Game { +public class DetermineStartPlayer extends ServerState { + public DetermineStartPlayer(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/Dialogs.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/Dialogs.java deleted file mode 100644 index 43cf5534..00000000 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/Dialogs.java +++ /dev/null @@ -1,4 +0,0 @@ -package pp.mdga.server; - -public class Dialogs extends ServerState { -} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/FirstRoll.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/FirstRoll.java index b24c5979..daa811dd 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/FirstRoll.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/FirstRoll.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class FirstRoll extends RollDice { +public class FirstRoll extends ServerState { + public FirstRoll(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/Game.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/Game.java deleted file mode 100644 index a8265d5e..00000000 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/Game.java +++ /dev/null @@ -1,4 +0,0 @@ -package pp.mdga.server; - -public class Game extends ServerState { -} 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..53ee5901 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/GameState.java @@ -0,0 +1,75 @@ +package pp.mdga.server; + +import pp.mdga.game.Piece; +import pp.mdga.message.client.*; +import pp.mdga.message.server.PossibleCard; + +public class GameState extends ServerState { + private final GameStateMachine gameStateMachine = new GameStateMachine(this, logic); + + public GameState(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + logic.getGame().addObserver(this); + } + + @Override + public void entry() { + gameStateMachine.entry(); + } + + @Override + public void receivedAnimationEnd(AnimationEnd msg) { + gameStateMachine.receivedAnimationEnd(msg); + } + + // todo piece? + @Override + public void receivedConfirmPiece(Piece piece) { + gameStateMachine.receivedConfirmPiece(piece); + } + + @Override + public void receivedNoPowerCard(NoPowerCard msg) { + gameStateMachine.receivedNoPowerCard(msg); + } + + @Override + public void receivedPowerCardChoice(SelectCard msg) { + gameStateMachine.receivedPowerCardChoice(msg); + } + + @Override + public void receivedRequestDice(RequestDice msg) { + gameStateMachine.receivedRequestDice(msg); + } + + // todo msg? + @Override + public void receivedRollRankingDice() { + gameStateMachine.receivedRollRankingDice(); + } + + @Override + public void receivedSelectedPieces(SelectedPieces msg) { + gameStateMachine.receivedSelectedPieces(msg); + } + + @Override + public void sentPossibleCard(PossibleCard msg) { + gameStateMachine.sentPossibleCard(msg); + } + + // todo msg?, sent to everyone? + @Override + public void sentRankingResponse() { + gameStateMachine.sentRankingResponse(); + } + + @Override + public void update() { + if (logic.getGame().playerHasDisconnected()) { + parent.gotoState(new Ceremony(parent, logic)); + logic.getGame().removeObserver(this); + } + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/GameStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/GameStateMachine.java new file mode 100644 index 00000000..b01981de --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/GameStateMachine.java @@ -0,0 +1,12 @@ +package pp.mdga.server; + +public class GameStateMachine extends ServerStateMachine{ + public GameStateMachine(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } + + @Override + public DetermineStartPlayer initialState() { + return new DetermineStartPlayer(this, logic); + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/Interrupt.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/Interrupt.java index 8bcc7aa3..0f9e0fdc 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/Interrupt.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/Interrupt.java @@ -1,4 +1,7 @@ package pp.mdga.server; public class Interrupt extends ServerState { + public Interrupt(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/Lobby.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/Lobby.java new file mode 100644 index 00000000..b3bb2330 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/Lobby.java @@ -0,0 +1,52 @@ +package pp.mdga.server; + +import pp.mdga.message.client.*; +import pp.mdga.message.server.ServerMessage; +import pp.mdga.message.server.UpdateReady; +import pp.mdga.message.server.UpdateTSK; + +public class Lobby extends ServerState { + public Lobby(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + logic.getGame().addObserver(this); + } + + @Override + public void receivedDeselectTSK(DeselectTSK msg) { + broadcastUpdate(new UpdateTSK()); + } + + @Override + public void receivedNotReady(LobbyNotReady msg) { + broadcastUpdate(new UpdateReady()); + } + + @Override + public void receivedReady(LobbyReady msg) { + broadcastUpdate(new UpdateReady()); + } + + @Override + public void receivedSelectTSK(SelectTSK msg) { + broadcastUpdate(new UpdateTSK()); + } + + private void broadcastUpdate(ServerMessage updateMessage) { + for (var entry : logic.getGame().getPlayers().entrySet()) { + logic.send(entry.getValue(), updateMessage); + } + } + + @Override + public void receivedStartGame(ClientStartGame msg) { + // todo: implement?? + } + + @Override + public void update() { + if (logic.getGame().getGameHasStarted()) { + parent.gotoState(new GameState(parent, logic)); + logic.getGame().removeObserver(this); + } + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/MovePiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/MovePiece.java index 25b990ab..38d40399 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/MovePiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/MovePiece.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class MovePiece extends Turn { +public class MovePiece extends ServerState { + public MovePiece(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/NoPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/NoPiece.java index eece4d47..9b2cbb48 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/NoPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/NoPiece.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class NoPiece extends ChoosePiece { +public class NoPiece extends ServerState { + public NoPiece(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/NoTurn.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/NoTurn.java index cd4540f0..9986437b 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/NoTurn.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/NoTurn.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class NoTurn extends ChoosePiece { +public class NoTurn extends ServerState { + public NoTurn(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/Observer.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/Observer.java new file mode 100644 index 00000000..a95ad2ad --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/Observer.java @@ -0,0 +1,5 @@ +package pp.mdga.server; + +public interface Observer { + void update(); +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/PowerCard.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/PowerCard.java index 5eb67ff2..fef94ce2 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/PowerCard.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/PowerCard.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class PowerCard extends Turn { +public class PowerCard extends ServerState { + public PowerCard(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/RollDice.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/RollDice.java index 42c5cbb2..acb43509 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/RollDice.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/RollDice.java @@ -1,4 +1,9 @@ package pp.mdga.server; -public class RollDice extends Turn { +public class RollDice extends ServerState { + private final RollDiceMachine rollDiceMachine = new RollDiceMachine(this, logic); + + public RollDice(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/RollDiceMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/RollDiceMachine.java new file mode 100644 index 00000000..49117d0c --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/RollDiceMachine.java @@ -0,0 +1,12 @@ +package pp.mdga.server; + +public class RollDiceMachine extends ServerStateMachine { + public RollDiceMachine(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } + + @Override + public ServerState initialState() { + return null; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/SecondRoll.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/SecondRoll.java index a4be16ed..63b98b9a 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/SecondRoll.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/SecondRoll.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class SecondRoll extends RollDice { +public class SecondRoll extends ServerState { + public SecondRoll(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/SelectPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/SelectPiece.java index 3ca82aa2..f3e21d28 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/SelectPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/SelectPiece.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class SelectPiece extends ChoosePiece { +public class SelectPiece extends ServerState { + public SelectPiece(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerAutomaton.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerAutomaton.java new file mode 100644 index 00000000..4d8bbd31 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerAutomaton.java @@ -0,0 +1,13 @@ +package pp.mdga.server; + +public class ServerAutomaton extends ServerStateMachine { + public ServerAutomaton(ServerGameLogic logic) { + super(null, logic); + entry(); + } + + @Override + public Lobby initialState() { + return new Lobby(this, 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 9b2a7615..c278a929 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 @@ -1,17 +1,24 @@ package pp.mdga.server; +import pp.mdga.game.Game; +import pp.mdga.game.Player; import pp.mdga.message.client.*; +import pp.mdga.message.server.ServerMessage; import java.lang.System.Logger; -import java.lang.System.Logger.Level; -import java.util.ArrayList; public class ServerGameLogic implements ClientInterpreter { - private static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName()); + static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName()); -// private final List players = new ArrayList<>(4); + private final Game game; + private final ServerSender serverSender; + private ServerState state; -// private ServerState state = new ; + public ServerGameLogic(Game game, ServerSender serverSender) { + this.game = game; + this.serverSender = serverSender; + state = new ServerAutomaton(this); + } @Override @@ -83,4 +90,43 @@ public void received(SelectTSK selectTSK, int from) { public void received(ForceContinueGame forceContinueGame, int from) { } + + @Override + public void received(ClientStartGame clientStartGame, int from) { + + } + + @Override + public void received(NoPowerCard noPowerCard, int from) { + + } + + @Override + public void received(SelectedPieces selectedPieces, int from) { + + } + + /** + * Sends a message to the specified player. + * + * @param player the player to send the message to + * @param msg the message to send + */ + public void send(Player player, ServerMessage msg) { + LOGGER.log(Logger.Level.INFO, "sending to {0}: {1}", player, msg); //NON-NLS + serverSender.send(player.getId(), msg); + } + + public ServerSender getServerSender() { + return serverSender; + } + + public Game getGame() { + return game; + } + + // todo: remove + public ServerState getState() { + return state; + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerSender.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerSender.java new file mode 100644 index 00000000..0efc8f5d --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerSender.java @@ -0,0 +1,7 @@ +package pp.mdga.server; + +import pp.mdga.message.server.ServerMessage; + +public interface ServerSender { + void send(int id, ServerMessage msg); +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerState.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerState.java index 7f023a7d..ee022302 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerState.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerState.java @@ -1,4 +1,65 @@ package pp.mdga.server; -public class ServerState { +import pp.mdga.game.Piece; +import pp.mdga.message.client.*; +import pp.mdga.message.server.PossibleCard; +import java.lang.System.Logger; + +public abstract class ServerState implements Observer { + protected static final Logger LOGGER = System.getLogger(ServerState.class.getName()); + protected ServerState parent; + protected ServerGameLogic logic; + + public ServerState(ServerState parent, ServerGameLogic logic) { + this.parent = parent; + this.logic = logic; + } + + public void entry() { /* do nothing */ } + + public void receivedAnimationEnd(AnimationEnd msg) { /* do nothing */ } + + // todo piece? + public void receivedConfirmPiece(Piece piece) { /* do nothing */ } + + public void receivedDeselectTSK(DeselectTSK msg) { /* do nothing */ } + + public void receivedNoPowerCard(NoPowerCard msg) { /* do nothing */ } + + public void receivedNotReady(LobbyNotReady msg) { /* do nothing */ } + + public void receivedPowerCardChoice(SelectCard msg) { /* do nothing */ } + + public void receivedReady(LobbyReady msg) { /* do nothing */ } + + public void receivedRequestDice(RequestDice msg) { /* do nothing */ } + + // todo msg? + public void receivedRollRankingDice() { /* do nothing */ } + + public void receivedSelectTSK(SelectTSK msg) { /* do nothing */ } + + public void receivedSelectedPieces(SelectedPieces msg) { /* do nothing */ } + + public void receivedStartGame(ClientStartGame msg) { /* do nothing */ } + + public void sentPossibleCard(PossibleCard msg) { /* do nothing */ } + + // todo msg?, sent to everyone? + public void sentRankingResponse() { /* do nothing */ } + + public void gotoState(ServerState state) { + throw new IllegalStateException("not in a statemachine"); + } + + public ServerState getParent() { + return parent; + } + + public void update() { /* do nothing */ } + + @Override + public String toString() { + return getClass().getSimpleName(); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerStateMachine.java new file mode 100644 index 00000000..f97d54f2 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/ServerStateMachine.java @@ -0,0 +1,114 @@ +package pp.mdga.server; + +import pp.mdga.game.Piece; +import pp.mdga.message.client.*; +import pp.mdga.message.server.PossibleCard; + +public abstract class ServerStateMachine extends ServerState { + + private ServerState state; + + public ServerStateMachine(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } + + public abstract ServerState initialState(); + + @Override + public void gotoState(ServerState newState) { + LOGGER.log(System.Logger.Level.DEBUG, "{0}: {1} --> {2}", this, state, newState); + enter(newState); + } + + @Override + public void entry() { + final ServerState newState = initialState(); + LOGGER.log(System.Logger.Level.DEBUG, "{0}: initial state={1}", this, newState); + enter(newState); + } + + private void enter(ServerState newState) { + if (newState.parent != this) + throw new IllegalArgumentException("Wrong state: " + newState + " belongs to " + newState.parent + " instead of " + this); + state = newState; + state.entry(); + } + + @Override + public void receivedAnimationEnd(AnimationEnd msg) { + state.receivedAnimationEnd(msg); + } + + // todo piece? + @Override + public void receivedConfirmPiece(Piece piece) { + state.receivedConfirmPiece(piece); + } + + @Override + public void receivedDeselectTSK(DeselectTSK msg) { + state.receivedDeselectTSK(msg); + } + + @Override + public void receivedNoPowerCard(NoPowerCard msg) { + state.receivedNoPowerCard(msg); + } + + @Override + public void receivedNotReady(LobbyNotReady msg) { + state.receivedNotReady(msg); + } + + @Override + public void receivedPowerCardChoice(SelectCard msg) { + state.receivedPowerCardChoice(msg); + } + + @Override + public void receivedReady(LobbyReady msg) { + state.receivedReady(msg); + } + + @Override + public void receivedRequestDice(RequestDice msg) { + state.receivedRequestDice(msg); + } + + // todo msg? + @Override + public void receivedRollRankingDice() { + state.receivedRollRankingDice(); + } + + @Override + public void receivedSelectTSK(SelectTSK msg) { + state.receivedSelectTSK(msg); + } + + @Override + public void receivedSelectedPieces(SelectedPieces msg) { + state.receivedSelectedPieces(msg); + } + + @Override + public void receivedStartGame(ClientStartGame msg) { + state.receivedStartGame(msg); + } + + @Override + public void sentPossibleCard(PossibleCard msg) { + state.sentPossibleCard(msg); + } + + // todo msg?, sent to everyone? + @Override + public void sentRankingResponse() { + state.sentRankingResponse(); + } + + @Override + public String toString() { + return super.toString() + "(in " + state + ")"; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/StartPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/StartPiece.java index 3b9bdabf..24e23b60 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/StartPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/StartPiece.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class StartPiece extends ChoosePiece { +public class StartPiece extends ServerState { + public StartPiece(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/ThirdRoll.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/ThirdRoll.java index 45bded82..5f5245d1 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/ThirdRoll.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/ThirdRoll.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class ThirdRoll extends RollDice { +public class ThirdRoll extends ServerState { + public ThirdRoll(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } 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 index 80dd59b8..ce1447a6 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/Turn.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/Turn.java @@ -1,4 +1,9 @@ package pp.mdga.server; public class Turn extends ServerState { + private final TurnStateMachine turnStateMachine = new TurnStateMachine(this, logic); + + public Turn(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/TurnStateMachine.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/TurnStateMachine.java new file mode 100644 index 00000000..b54f2e07 --- /dev/null +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/TurnStateMachine.java @@ -0,0 +1,12 @@ +package pp.mdga.server; + +public class TurnStateMachine extends ServerStateMachine { + public TurnStateMachine(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } + + @Override + public ServerState initialState() { + return null; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/WaitingPiece.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/WaitingPiece.java index bb074027..dcc28f3c 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/WaitingPiece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/WaitingPiece.java @@ -1,4 +1,7 @@ package pp.mdga.server; -public class WaitingPiece extends ChoosePiece { +public class WaitingPiece extends ServerState { + public WaitingPiece(ServerState parent, ServerGameLogic logic) { + super(parent, logic); + } } From 9662e1f6842d13f429056647de8858c5faca308d Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Sun, 17 Nov 2024 15:34:39 +0100 Subject: [PATCH 7/7] fixed a Bug where the import statement thought a package was a class because they where written the same --- Projekte/.run/MdgaApp.run.xml | 2 +- .../java/pp/mdga/client/Animation/MdgaAnimation.java | 4 ---- .../main/java/pp/mdga/client/Board/PileControl.java | 5 ----- .../src/main/java/pp/mdga/client/Dialog/Dialog.java | 5 ----- .../main/java/pp/mdga/client/Dialog/MenuDialog.java | 5 ----- .../src/main/java/pp/mdga/client/Gui/GuiView.java | 5 ----- .../client/src/main/java/pp/mdga/client/MdgaApp.java | 10 +++++----- .../client/{Acoustic => acoustic}/AcousticHandler.java | 2 +- .../mdga/client/{Acoustic => acoustic}/GameMusic.java | 2 +- .../mdga/client/{Acoustic => acoustic}/GameSound.java | 2 +- .../mdga/client/{Acoustic => acoustic}/MdgaSound.java | 2 +- .../mdga/client/{Acoustic => acoustic}/MusicAsset.java | 2 +- .../mdga/client/{Acoustic => acoustic}/SoundAsset.java | 2 +- .../{Acoustic => acoustic}/SoundAssetDelayVolume.java | 2 +- .../client/{Animation => animation}/Animation.java | 2 +- .../{Animation => animation}/AnimationHandler.java | 2 +- .../{Animation => animation}/EmptyAnimation.java | 2 +- .../java/pp/mdga/client/animation/MdgaAnimation.java | 4 ++++ .../pp/mdga/client/{Board => board}/AssetOnMap.java | 2 +- .../pp/mdga/client/{Board => board}/BoardAsset.java | 2 +- .../pp/mdga/client/{Board => board}/BoardView.java | 2 +- .../pp/mdga/client/{Board => board}/MapLoader.java | 2 +- .../pp/mdga/client/{Board => board}/NodeControl.java | 2 +- .../pp/mdga/client/{Board => board}/PieceControl.java | 2 +- .../main/java/pp/mdga/client/board/PileControl.java | 5 +++++ .../src/main/java/pp/mdga/client/dialog/Dialog.java | 5 +++++ .../pp/mdga/client/{Dialog => dialog}/DialogView.java | 2 +- .../client/{Dialog => dialog}/InterruptDialog.java | 2 +- .../main/java/pp/mdga/client/dialog/MenuDialog.java | 5 +++++ .../mdga/client/{Dialog => dialog}/NetworkDialog.java | 2 +- .../pp/mdga/client/{Dialog => dialog}/SoundDialog.java | 2 +- .../pp/mdga/client/{Dialog => dialog}/StartDialog.java | 2 +- .../pp/mdga/client/{Dialog => dialog}/VideoDialog.java | 2 +- .../src/main/java/pp/mdga/client/gui/GuiView.java | 5 +++++ .../mdga/model/src/main/java/pp.mdga/game/Game.java | 2 +- 35 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Animation/MdgaAnimation.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Board/PileControl.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/Dialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MenuDialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Gui/GuiView.java rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Acoustic => acoustic}/AcousticHandler.java (99%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Acoustic => acoustic}/GameMusic.java (99%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Acoustic => acoustic}/GameSound.java (98%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Acoustic => acoustic}/MdgaSound.java (94%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Acoustic => acoustic}/MusicAsset.java (98%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Acoustic => acoustic}/SoundAsset.java (96%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Acoustic => acoustic}/SoundAssetDelayVolume.java (87%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Animation => animation}/Animation.java (77%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Animation => animation}/AnimationHandler.java (93%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Animation => animation}/EmptyAnimation.java (86%) create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/animation/MdgaAnimation.java rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Board => board}/AssetOnMap.java (68%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Board => board}/BoardAsset.java (98%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Board => board}/BoardView.java (99%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Board => board}/MapLoader.java (98%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Board => board}/NodeControl.java (92%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Board => board}/PieceControl.java (92%) create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/board/PileControl.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Dialog => dialog}/DialogView.java (94%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Dialog => dialog}/InterruptDialog.java (52%) create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/MenuDialog.java rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Dialog => dialog}/NetworkDialog.java (51%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Dialog => dialog}/SoundDialog.java (50%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Dialog => dialog}/StartDialog.java (97%) rename Projekte/mdga/client/src/main/java/pp/mdga/client/{Dialog => dialog}/VideoDialog.java (50%) create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiView.java diff --git a/Projekte/.run/MdgaApp.run.xml b/Projekte/.run/MdgaApp.run.xml index 051df2ea..0ed782b0 100644 --- a/Projekte/.run/MdgaApp.run.xml +++ b/Projekte/.run/MdgaApp.run.xml @@ -6,7 +6,7 @@