Make fit for beta release (#51)

* removed

* edited a lot of stuff
This commit is contained in:
Valentin Heiserer
2024-04-26 01:41:50 +02:00
committed by GitHub
parent 2e5a42b6d3
commit 539e29dc56
94 changed files with 843 additions and 8636 deletions

View File

@@ -41,7 +41,7 @@ public class GameState {
}
private GamePhase gamePhase;
private Integer currentPlayer; // Using Integer to allow for null
private String currentPlayer; // Using Integer to allow for null
private Karte card;
private KartenFarbe color;
private boolean trumpf;
@@ -52,7 +52,7 @@ public class GameState {
this.gamePhase = phase;
}
public GameState(GamePhase phase, Integer player) {
public GameState(GamePhase phase, String player) {
this.gamePhase = phase;
this.currentPlayer = player;
}
@@ -60,7 +60,7 @@ public class GameState {
/**
* GameState.
*/
public GameState(GamePhase phase, Integer player, Karte card, KartenFarbe color, boolean trumpf) {
public GameState(GamePhase phase, String player, Karte card, KartenFarbe color, boolean trumpf) {
this.gamePhase = phase;
this.currentPlayer = player;
this.card = card;
@@ -71,7 +71,7 @@ public class GameState {
/**
* GameState.
*/
public GameState(GamePhase phase, Integer player, Karte card) {
public GameState(GamePhase phase, String player, Karte card) {
this.gamePhase = phase;
this.currentPlayer = player;
this.card = card;

View File

@@ -28,7 +28,6 @@ public class Schafkopf {
private final Player[] player;
private GameState gameState = new GameState(GamePhase.GAME_STOP);
private Thread spielThread;
/**
* Constructor for the Schafkopf class.
@@ -100,8 +99,6 @@ public class Schafkopf {
gameState = new GameState(GamePhase.GAME_STOP);
setAndSendGameState(gameState);
}
spielThread.interrupt();
}
/**

View File

@@ -21,6 +21,31 @@ public class SchafkopfException extends Exception {
// You can also include additional constructors or methods if needed
}
/**
* The main entrypoint of the Application.
*/
public static class NoGameSessionException extends SchafkopfException {
public NoGameSessionException() {
super("No game session available");
}
// You can also include additional constructors or methods if needed
}
/**
* The main entrypoint of the Application.
*/
public static class PlayerNotReadyException extends SchafkopfException {
public PlayerNotReadyException() {
super("Not all Players are in Ready State");
}
// You can also include additional constructors or methods if needed
}
/**
* Class that represents one Frontend Connection.
*/

View File

@@ -13,22 +13,27 @@ public class SchafkopfMessage {
public static class SchafkopfBaseMessage {
private JsonObject message;
private SchafkopfMessageType messageType;
public SchafkopfBaseMessage(SchafkopfMessageType messageType, String content) {
this.messageType = messageType;
this.message = buildBaseMessage(messageType, content);
}
public SchafkopfBaseMessage(SchafkopfMessageType messageType, JsonObject content) {
this.messageType = messageType;
this.message = buildBaseMessage(messageType, content);
}
public SchafkopfBaseMessage(SchafkopfMessageType messageType) {
this.messageType = messageType;
this.message = buildBaseMessage(messageType);
}
public JsonObject getBaseMessage() {
return message;
}
}
JsonObject message;
@@ -118,6 +123,8 @@ public class SchafkopfMessage {
*/
public enum SchafkopfMessageType {
UNKNOWN_ERROR,
INFO_MESSAGE,
HEARTBEAT_SYN,
HEARTBEAT_ACK,
GET_CARD_ONLINE_PLAYER,
@@ -125,9 +132,17 @@ public class SchafkopfMessage {
GAME_STATE,
SERVER_CONNECTION_SUCCESSFUL,
REQUEST_SERVER_CONNECTION,
START_GAME,
JOIN_GAME,
PLAYER_CARD
JOIN_ONLINE_GAME,
START_DEDICATED_GAME,
PLAYER_CARD,
LIST_ONLINE_GAMES,
GET_ONLINE_GAME,
CREATE_ONLINE_GAME,
SET_STATUS_READY,
SET_PLAYER_NAME,
GAME_START_READY,
LEAVE_ONLINE_GAME
}
/**

View File

@@ -49,8 +49,9 @@ public class Spielablauf {
for (int i = 0; i < 4; i++) {
int currentPlayer = (i + startingPlayer) % 4;
logger.info("Spieler ist dran: {}", currentPlayer);
schafkopf.setAndSendGameState(new GameState(GamePhase.WAIT_FOR_CARD, currentPlayer));
logger.info("Spieler ist dran: {}", players[currentPlayer].getName());
schafkopf.setAndSendGameState(
new GameState(GamePhase.WAIT_FOR_CARD, players[currentPlayer].getName()));
Karte playedCard = players[currentPlayer].play(spiel, tischKarten, gespielteKarten);
tischKarten.addKarten(playedCard);
@@ -58,7 +59,7 @@ public class Spielablauf {
schafkopf.setAndSendGameState(
new GameState(
GamePhase.PLAYER_CARD,
currentPlayer,
players[currentPlayer].getName(),
playedCard,
tischKarten.getByIndex(0).getFarbe(),
spiel.isTrumpf(tischKarten.getByIndex(0))));
@@ -72,7 +73,8 @@ public class Spielablauf {
schafkopf.setAndSendGameState(
new GameState(
GamePhase.PLAYER_TRICK, winningPlayerIndex, tischKarten.getByIndex(stichSpieler)));
GamePhase.PLAYER_TRICK, players[winningPlayerIndex].getName(),
tischKarten.getByIndex(stichSpieler)));
try {
Thread.sleep(3000);

View File

@@ -13,8 +13,8 @@ public class BotPlayer extends Player {
private KartenListe eigeneKarten;
private KartenListe unbekannteKarten = KartenUtil.initializeSchafKopfCardDeck();
public BotPlayer() {
// TODO document why this constructor is empty
public BotPlayer(String name) {
super(name);
}
@Override

View File

@@ -20,7 +20,8 @@ public class OnlinePlayer extends Player {
private KartenListe karten = new KartenListe();
public OnlinePlayer(MessageSender messageSender) {
public OnlinePlayer(MessageSender messageSender, String name) {
super(name);
this.messageSender = messageSender;
}

View File

@@ -9,6 +9,16 @@ import org.schafkopf.spielcontroller.SpielController;
*/
public abstract class Player {
private String name;
protected Player(String name) {
this.name = name;
}
public String getName() {
return name;
}
public abstract Karte play(
SpielController spiel, KartenListe tischKarten, KartenListe gespielteKarten)
throws InterruptedException;