Fix: full model refactor

This commit is contained in:
2026-06-14 12:28:53 +02:00
parent 9a931bfc1b
commit 85f2dd9208
24 changed files with 311 additions and 253 deletions
@@ -20,7 +20,7 @@ public class Player implements Serializable {
/**
* The maximum length allowed for the username string.
*/
private static final int MAX_VALUE = 32;
private static final int MAX_USERNAME_LENGTH = 32;
/**
* Identifier for the {@code Player} when displaying the game through the GUI.
@@ -135,11 +135,8 @@ public class Player implements Serializable {
// region Setters
/**
* Adds {@code Value} amount of {@code Food} to the Player.
* @param value The amount of {@code Food} to be added.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* Adds {@code value} amount of Food to the Player.
* @param value The amount of Food to be added. Should be non-negative.
* @see #foodValue
*/
public void addFood(int value){
@@ -156,20 +153,15 @@ public class Player implements Serializable {
}
/**
* Removes {@code Value} amount of {@code Food} from the Player.
* Note: {@link #foodValue} cannot be negative, so the method returns
* {@code false} if {@code Value} is greater than the amount of {@code Food}
* the Player possesses, and {@code true} otherwise.
* Removes {@code value} amount of Food from the Player.
* {@link #foodValue} cannot go negative: returns {@code false} if
* {@code value} exceeds the current food and leaves the value unchanged.
*
* @param value The amount of {@code Food} to be removed.
* Should be positive for expected results
* (otherwise the method will add the absolute
* value of {@code Value}).
* @return {@code Boolean} - {@code true} if the Food is successfully removed,
* {@code false} otherwise.
* @param value The amount of Food to be removed. Should be non-negative.
* @return {@code true} if the Food is successfully removed, {@code false} otherwise.
* @see #foodValue
*/
public Boolean removeFood(int value){
public boolean removeFood(int value){
if(value > this.foodValue){
return false;
}
@@ -178,28 +170,20 @@ public class Player implements Serializable {
}
/**
* Adds {@code Value} amount of {@code Prestige} to the Player.
* @param value The amount of {@code Prestige} to be added.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* Adds {@code value} amount of Prestige to the Player.
* @param value The amount of Prestige to be added. Should be non-negative.
* @see #prestigeValue
*/
public void addPrestige(int value){
this.prestigeValue += value;
}
/**
* Removes {@code Value} amount of {@code Prestige} to the Player.
* @param value The amount of {@code Prestige} to be removed.
* Should be positive for expected results
* (otherwise the method will add the absolute
* value of {@code Value}).
* Removes {@code value} amount of Prestige from the Player.
* @param value The amount of Prestige to be removed. Should be non-negative.
* @see #prestigeValue
*/
public void removePrestige(int value){
this.prestigeValue -= value;
}
@@ -211,15 +195,15 @@ public class Player implements Serializable {
* Constructor for the class {@code Player}. Each Player is uniquely identified by the {@link #userName}.
*
* @param userName Unique String identifier for a Player.
* @throws IllegalArgumentException when {@code UserName} is empty or exceeds {@link #MAX_VALUE},
* @throws IllegalArgumentException when {@code userName} is empty or exceeds {@link #MAX_USERNAME_LENGTH},
* with message:
* <pre>{@code UserName is empty or exceeds maximum permitted length.}</pre>
*
* @see #userName
* @see #MAX_VALUE
* @see #MAX_USERNAME_LENGTH
*/
public Player(String userName) throws IllegalArgumentException {
if(userName.isEmpty() || userName.length() > MAX_VALUE) {
if(userName.isEmpty() || userName.length() > MAX_USERNAME_LENGTH) {
throw new IllegalArgumentException("UserName is empty or exceeds maximum permitted length.");
}
this.userName = userName;