Skip to content

Commit

Permalink
Add more restrictions to GameConfig validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lscgh committed Jan 26, 2024
1 parent cc40176 commit df2a022
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mavenmcserver/src/main/java/mavenmcserver/game/GameConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import org.joml.Vector3i;

public class GameConfig {

static int minFlatSize = 2;
static int minHeight = 1;

public Player mainPlayer;
public Player opponentPlayer;
public Vector3i size;
Expand All @@ -23,6 +27,22 @@ public GameConfig(Player mainPlayer, Player opponentPlayer, Vector3i size, int w
public List<String> validate() {
ArrayList<String> errors = new ArrayList<String>();

if(this.mainPlayer == null) {
errors.add("Couldn't add you to the game. Please retry!");
}

if(this.opponentPlayer == null) {
errors.add("Couldn't add the opponent player to the game.");
}

if(Math.min(this.size.x, Math.min(this.size.y, this.size.z)) <= 0) {
errors.add("No dimension of the game can be smaller than 1. The smallest possible game is (" + GameConfig.minFlatSize + ", " + GameConfig.minHeight + ", " + GameConfig.minFlatSize + ").");
}

if(Math.min(this.size.x, this.size.z) < GameConfig.minFlatSize) {
errors.add("The X and Z size of the game must not be smaller than " + GameConfig.minFlatSize);
}

if(this.winRequiredAmount > Math.max(this.size.x, Math.max(this.size.y, this.size.z))) {
errors.add("The required win amount must not be larger than the size's largest dimension");
}
Expand Down

0 comments on commit df2a022

Please sign in to comment.