Fix: checkstyle violations

This commit is contained in:
Julian Kropff
2026-04-11 16:34:24 +02:00
parent 406567d375
commit 3c7773e7fb
9 changed files with 202 additions and 121 deletions
@@ -60,16 +60,12 @@ public class GameService {
return state.players;
}
/**
* Send a CALL command to the server to indicate that the player wants to call.
*/
/** Send a CALL command to the server to indicate that the player wants to call. */
public void call() {
client.sendCall();
}
/**
* Send a FOLD command to the server to indicate that the player wants to fold.
*/
/** Send a FOLD command to the server to indicate that the player wants to fold. */
public void fold() {
client.sendFold();
}
@@ -183,9 +183,7 @@ public class Player {
this.chips -= amount;
}
/**
* Sets the player's state to FOLDED, indicating that they have folded in the current hand.
*/
/** Sets the player's state to FOLDED, indicating that they have folded in the current hand. */
public void fall() {
this.state = PlayerState.FOLDED;
if (this.id != null) {
@@ -2,9 +2,7 @@ package ch.unibas.dmi.dbis.cs108.casono.client.game;
import java.util.Objects;
/**
* Represents a unique identifier for a player in the client domain.
*/
/** Represents a unique identifier for a player in the client domain. */
public record PlayerId(String value) {
/**
@@ -21,9 +19,7 @@ public record PlayerId(String value) {
}
}
/**
* Factory method to create a PlayerId.
*/
/** Factory method to create a PlayerId. */
public static PlayerId of(String value) {
return new PlayerId(value);
}
@@ -1,8 +1,6 @@
package ch.unibas.dmi.dbis.cs108.casono.client.game;
/**
* Enumeration representing the possible states of a player in the poker game.
*/
/** Enumeration representing the possible states of a player in the poker game. */
public enum PlayerState {
ACTIVE,
FOLDED,
@@ -5,6 +5,7 @@ import ch.unibas.dmi.dbis.cs108.casono.client.game.GameState;
import ch.unibas.dmi.dbis.cs108.casono.client.game.Player;
import ch.unibas.dmi.dbis.cs108.casono.client.game.PlayerId;
import ch.unibas.dmi.dbis.cs108.casono.client.game.PlayerState;
import java.util.List;
/**
* The GameClient class is responsible for communicating with the server to retrieve the current
@@ -33,14 +34,15 @@ public class GameClient {
* @return A GameState object representing the current state of the game, as parsed
*/
public GameState fetchGameState() {
List<String> responseLines = client.processCommand("GET_GAME_STATE\nGAME_ID=" + gameId);
String response = client.processCommand("GET_GAME_STATE\nGAME_ID=" + gameId);
if (response == null || response.isBlank()) {
if (responseLines == null || responseLines.isEmpty()) {
throw new RuntimeException("Empty server response");
}
return parse(response);
String fullResponse = String.join("\n", responseLines);
return parse(fullResponse);
}
/** Send a CALL command to the server to indicate that the player wants to call */
@@ -68,95 +70,204 @@ public class GameClient {
}
/**
* Parse the raw string response from the server into a structured GameState object.
* Parses the raw server response string into a structured GameState object.
*
* @param input The raw string response from the server representing the game state.
* @return A GameState object representing the parsed game state.
* @param input The raw server response string containing the game state information.
* @return A GameState object representing the current state of the game.
*/
private GameState parse(String input) {
GameState state = new GameState();
Player currentPlayer = null;
Card currentCard = null;
boolean inPlayers = false;
boolean inPlayerCards = false;
boolean inCommunityCards = false;
ParserContext ctx = new ParserContext(state);
for (String raw : input.split("\n")) {
String line = raw.trim();
if (line.isEmpty() || line.startsWith("+OK")) {
if (shouldSkip(line)) {
continue;
}
if (line.startsWith("PHASE=")) {
state.phase = value(line);
} else if (line.startsWith("POT=")) {
state.pot = intVal(line);
} else if (line.startsWith("CURRENT_BET=")) {
state.currentBet = intVal(line);
} else if (line.startsWith("DEALER=")) {
state.dealer = intVal(line);
} else if (line.startsWith("ACTIVE_PLAYER=")) {
state.activePlayer = intVal(line);
} else if (line.startsWith("WINNER=")) {
state.winnerIndex = intVal(line);
} else if (line.equals("END")) {
inPlayers = false;
inPlayerCards = false;
inCommunityCards = false;
currentPlayer = null;
currentCard = null;
if (handleGlobal(line, ctx)) {
continue;
} else if (line.equals("PLAYERS")) {
inPlayers = true;
inPlayerCards = false;
inCommunityCards = false;
continue;
} else if (line.equals("PLAYER")) {
currentPlayer = new Player();
state.players.add(currentPlayer);
continue;
} else if (line.startsWith("NAME=") && currentPlayer != null) {
currentPlayer.setId(PlayerId.of(value(line)));
} else if (line.startsWith("CHIPS=") && currentPlayer != null) {
currentPlayer.setChips(intVal(line));
} else if (line.startsWith("BET=") && currentPlayer != null) {
currentPlayer.setBet(intVal(line));
} else if (line.startsWith("STATE=") && currentPlayer != null) {
currentPlayer.setState(parseState(value(line)));
} else if (line.equals("CARDS")) {
if (inPlayers && currentPlayer != null) {
inPlayerCards = true;
inCommunityCards = false;
} else {
inCommunityCards = true;
inPlayerCards = false;
}
}
if (handleSections(line, ctx)) {
continue;
} else if (line.startsWith("CARD")) {
currentCard = new Card("", "");
}
if (inPlayerCards && currentPlayer != null) {
currentPlayer.addCard(currentCard);
} else if (inCommunityCards) {
state.communityCards.add(currentCard);
}
} else if (line.startsWith("VALUE=") && currentCard != null) {
currentCard.setValue(value(line));
} else if (line.startsWith("SUIT=") && currentCard != null) {
currentCard.setSuit(value(line));
if (handlePlayer(line, ctx)) {
continue;
}
if (handleCards(line, ctx)) {
continue;
}
}
return state;
}
/** Holds the mutable parsing state while processing the server response. */
private static class ParserContext {
GameState state;
Player currentPlayer;
Card currentCard;
boolean inPlayers;
boolean inPlayerCards;
boolean inCommunityCards;
ParserContext(GameState state) {
this.state = state;
}
}
/**
* Checks whether a line should be ignored.
*
* @param line the current input line
* @return true if the line is empty or a status message, false otherwise
*/
private boolean shouldSkip(String line) {
return line.isEmpty() || line.startsWith("+OK");
}
/**
* Parses global game state properties (e.g., phase, pot, current bet).
*
* @param line the current input line
* @param ctx the parser context containing the game state
* @return true if the line was handled, false otherwise
*/
private boolean handleGlobal(String line, ParserContext ctx) {
GameState state = ctx.state;
if (line.startsWith("PHASE=")) {
state.phase = value(line);
} else if (line.startsWith("POT=")) {
state.pot = intVal(line);
} else if (line.startsWith("CURRENT_BET=")) {
state.currentBet = intVal(line);
} else if (line.startsWith("DEALER=")) {
state.dealer = intVal(line);
} else if (line.startsWith("ACTIVE_PLAYER=")) {
state.activePlayer = intVal(line);
} else if (line.startsWith("WINNER=")) {
state.winnerIndex = intVal(line);
} else {
return false;
}
return true;
}
/**
* Processes section markers such as PLAYERS, PLAYER, CARDS, and END. Updates the parser context
* accordingly.
*
* @param line the current input line
* @param ctx the parser context
* @return true if the line was handled, false otherwise
*/
private boolean handleSections(String line, ParserContext ctx) {
if (line.equals("END")) {
ctx.inPlayers = false;
ctx.inPlayerCards = false;
ctx.inCommunityCards = false;
ctx.currentPlayer = null;
ctx.currentCard = null;
return true;
}
if (line.equals("PLAYERS")) {
ctx.inPlayers = true;
return true;
}
if (line.equals("PLAYER")) {
ctx.currentPlayer = new Player();
ctx.state.players.add(ctx.currentPlayer);
return true;
}
if (line.equals("CARDS")) {
if (ctx.inPlayers && ctx.currentPlayer != null) {
ctx.inPlayerCards = true;
ctx.inCommunityCards = false;
} else {
ctx.inCommunityCards = true;
ctx.inPlayerCards = false;
}
return true;
}
return false;
}
/**
* Parses properties of the current player (e.g., name, chips, bet, state).
*
* @param line the current input line
* @param ctx the parser context
* @return true if the line was handled, false otherwise
*/
private boolean handlePlayer(String line, ParserContext ctx) {
Player p = ctx.currentPlayer;
if (p == null) {
return false;
}
if (line.startsWith("NAME=")) {
p.setId(PlayerId.of(value(line)));
} else if (line.startsWith("CHIPS=")) {
p.setChips(intVal(line));
} else if (line.startsWith("BET=")) {
p.setBet(intVal(line));
} else if (line.startsWith("STATE=")) {
p.setState(parseState(value(line)));
} else {
return false;
}
return true;
}
/**
* Parses card-related lines and assigns cards to the current player or the community cards.
*
* @param line the current input line
* @param ctx the parser context
* @return true if the line was handled, false otherwise
*/
private boolean handleCards(String line, ParserContext ctx) {
if (line.startsWith("CARD")) {
ctx.currentCard = new Card("", "");
if (ctx.inPlayerCards && ctx.currentPlayer != null) {
ctx.currentPlayer.addCard(ctx.currentCard);
} else if (ctx.inCommunityCards) {
ctx.state.communityCards.add(ctx.currentCard);
}
return true;
}
if (line.startsWith("VALUE=") && ctx.currentCard != null) {
ctx.currentCard.setValue(value(line));
return true;
}
if (line.startsWith("SUIT=") && ctx.currentCard != null) {
ctx.currentCard.setSuit(value(line));
return true;
}
return false;
}
/**
* Helper method to extract the value from a line in the format KEY=VALUE.
*
@@ -19,10 +19,10 @@ import javafx.scene.layout.VBox;
/**
* Controller for the casino gaming area.
*
* Responsible for: - the display of the poker table and the player interface, - the processing
* <p>Responsible for: - the display of the poker table and the player interface, - the processing
* of user input, - the interface to the game engine and the network protocol.
*
* Notes: - The `onTableClick()` method currently serves only as test logic. It may no longer be
* <p>Notes: - The `onTableClick()` method currently serves only as test logic. It may no longer be
* functional and will be replaced by the final game interaction in the future.
*/
public class CasinoGameController {
@@ -118,9 +118,7 @@ public class CasinoGameController {
private static final long CHIP_DROP_DURATION_MS = 250;
private static final long CHIP_STAGGER_DELAY_MULTIPLIER = 35L;
/**
* Standard constructor. Used by FXML.
*/
/** Standard constructor. Used by FXML. */
public CasinoGameController() {
// default constructor for FXML
}
@@ -136,9 +134,7 @@ public class CasinoGameController {
this.gameService = gameService;
}
/**
* Set the PlayerId of the current player.
*/
/** Set the PlayerId of the current player. */
@FXML
public void initialize() {
LOGGER.info("INIT UI");
@@ -265,9 +261,7 @@ public class CasinoGameController {
// updateGameInfo(s);
// }
/**
* Start the UI update loop.
*/
/** Start the UI update loop. */
public void start() {
if (gameService == null) {
@@ -10,10 +10,10 @@ import javafx.stage.Stage;
/**
* Main class for the Casono Game UI.
*
* Starts the JavaFX application, loads the graphical user interface from the FXML file, and
* <p>Starts the JavaFX application, loads the graphical user interface from the FXML file, and
* initializes the main stage for the game.
*
* Tasks: - Loads the FXML interface "/ui-structure/Casinogameui.fxml". - Loads the application
* <p>Tasks: - Loads the FXML interface "/ui-structure/Casinogameui.fxml". - Loads the application
* icon from "/images/logoinverted.png". - Starts the application in full-screen mode.
*/
public class CasinoGameUI extends Application {
@@ -27,9 +27,7 @@ public class PlayerStatusController {
private static final String DEALER_IMAGE_PATH = "/images/chip-dealer-blue-3.png";
private static final double DEALER_ICON_X_FACTOR = 0.8;
/**
* Initialize the controller, load dealer image, and set up bindings.
*/
/** Initialize the controller, load dealer image, and set up bindings. */
@FXML
public void initialize() {
@@ -62,9 +60,7 @@ public class PlayerStatusController {
refresh();
}
/**
* Refresh UI safely
*/
/** Refresh UI safely */
public void refresh() {
if (player == null) {
@@ -51,9 +51,7 @@ public class TaskbarController {
private static final String STYLE_RED_INPUT = "red-input-field";
private static final double SCALE_NORMAL = 1.0;
/**
* Standard constructor. Used by FXML.
*/
/** Standard constructor. Used by FXML. */
public TaskbarController() {
// default constructor for FXML
}
@@ -309,9 +307,7 @@ public class TaskbarController {
processBet();
}
/**
* Called when the Call button is clicked.
*/
/** Called when the Call button is clicked. */
@FXML
private void onInputPlayerCall() {
@@ -326,9 +322,7 @@ public class TaskbarController {
refreshGame();
}
/**
* Called when the Fold button is clicked.
*/
/** Called when the Fold button is clicked. */
@FXML
private void onInputPlayerFold() {
@@ -343,9 +337,7 @@ public class TaskbarController {
refreshGame();
}
/**
* Called when the Raise button is clicked.
*/
/** Called when the Raise button is clicked. */
@FXML
private void onInputPlayerRaise() {
@@ -442,7 +434,7 @@ public class TaskbarController {
/**
* Opens the integrated Casono web browser.
*
* TODO: Replace the start URL with the official project website (e.g., Tips & Tricks page)
* <p>TODO: Replace the start URL with the official project website (e.g., Tips & Tricks page)
* once the content for strategies and support is available.
*/
@FXML