2025-02-26 13:26:58 +01:00
|
|
|
package de.towerdefence.server.match;
|
|
|
|
|
|
|
|
import de.towerdefence.server.player.Player;
|
2025-03-10 13:39:14 +01:00
|
|
|
import de.towerdefence.server.server.channels.match.placing.InvalidPlacementReason;
|
|
|
|
import de.towerdefence.server.server.channels.match.placing.Tower;
|
2025-02-26 13:26:58 +01:00
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Getter;
|
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
@Getter
|
|
|
|
public class Match {
|
2025-03-05 11:39:47 +01:00
|
|
|
|
2025-03-10 13:39:14 +01:00
|
|
|
public final static int MAP_SIZE_X = 10;
|
|
|
|
public final static int MAP_SIZE_Y = 20;
|
2025-02-26 13:26:58 +01:00
|
|
|
private final String matchId;
|
2025-03-05 11:39:47 +01:00
|
|
|
private final Player player1;
|
|
|
|
private final Player player2;
|
2025-03-10 13:39:14 +01:00
|
|
|
private final Tower[][] player1Map = new Tower[MAP_SIZE_X][MAP_SIZE_Y];
|
|
|
|
private final Tower[][] player2Map = new Tower[MAP_SIZE_X][MAP_SIZE_Y];
|
|
|
|
|
|
|
|
public Player getOpponent(Player player) {
|
|
|
|
boolean isPlayer1 = player1.equals(player);
|
|
|
|
boolean isPlayer2 = player2.equals(player);
|
|
|
|
if (!isPlayer1 && !isPlayer2) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (isPlayer1) {
|
|
|
|
return player2;
|
|
|
|
}
|
|
|
|
return player1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return opponent
|
|
|
|
*/
|
|
|
|
public Player addTower(Player player, Tower tower, int x, int y) throws InvalidPlacementException {
|
|
|
|
if (player != player1 && player != player2) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (x < 0 || y < 0 || x + 1 > Match.MAP_SIZE_X || y + 1 > Match.MAP_SIZE_Y) {
|
|
|
|
throw new InvalidPlacementException(InvalidPlacementReason.OUT_OF_BOUNDS);
|
|
|
|
}
|
|
|
|
if (player == player1) {
|
|
|
|
if (player1Map[x][y] != null) {
|
|
|
|
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
|
|
|
|
}
|
|
|
|
player1Map[x][y] = tower;
|
|
|
|
} else {
|
|
|
|
if (player2Map[x][y] != null) {
|
|
|
|
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
|
|
|
|
}
|
|
|
|
player2Map[x][y] = tower;
|
|
|
|
}
|
|
|
|
return getOpponent(player);
|
|
|
|
}
|
2025-02-26 13:26:58 +01:00
|
|
|
}
|