2025-03-12 14:34:55 +01:00
|
|
|
package de.towerdefence.server.match;
|
|
|
|
|
2025-03-13 12:08:07 +01:00
|
|
|
import de.towerdefence.server.match.callbacks.PlayerHitpointsCallback;
|
2025-03-12 14:34:55 +01:00
|
|
|
import de.towerdefence.server.match.callbacks.PlayerMoneyCallback;
|
|
|
|
import de.towerdefence.server.match.exeptions.InvalidPlacementException;
|
|
|
|
import de.towerdefence.server.match.exeptions.InvalidPlacementReason;
|
|
|
|
import de.towerdefence.server.player.Player;
|
|
|
|
import lombok.Getter;
|
|
|
|
|
|
|
|
public class GameSession {
|
2025-03-13 12:08:07 +01:00
|
|
|
final static int START_HITPOINTS = 100;
|
2025-03-12 14:34:55 +01:00
|
|
|
final static int START_MONEY = 50;
|
|
|
|
final static int MAP_SIZE_X = 10;
|
|
|
|
final static int MAP_SIZE_Y = 20;
|
|
|
|
|
|
|
|
private final Tower[][] towers = new Tower[MAP_SIZE_X][MAP_SIZE_Y];
|
|
|
|
|
|
|
|
private final Player player;
|
|
|
|
@Getter
|
|
|
|
private int money;
|
2025-03-13 12:08:07 +01:00
|
|
|
@Getter
|
|
|
|
private int playerHitpoints;
|
2025-03-12 14:34:55 +01:00
|
|
|
private final PlayerMoneyCallback moneyCallback;
|
2025-03-13 12:08:07 +01:00
|
|
|
//private final PlayerHitpointsCallback hitpointsCallback;
|
2025-03-12 14:34:55 +01:00
|
|
|
|
|
|
|
public GameSession(Player player, PlayerMoneyCallback moneyCallback) {
|
|
|
|
this.player = player;
|
|
|
|
this.moneyCallback = moneyCallback;
|
2025-03-13 12:08:07 +01:00
|
|
|
//this.hitpointsCallback = hitpointsCallback;
|
2025-03-12 14:34:55 +01:00
|
|
|
this.money = START_MONEY;
|
2025-03-13 12:08:07 +01:00
|
|
|
this.playerHitpoints = START_HITPOINTS;
|
|
|
|
|
2025-03-12 14:34:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void placeTower(Tower tower, int x, int y) throws InvalidPlacementException {
|
|
|
|
if (x < 0 || y < 0 || x + 1 > MAP_SIZE_X || y + 1 > MAP_SIZE_Y) {
|
|
|
|
throw new InvalidPlacementException(InvalidPlacementReason.OUT_OF_BOUNDS);
|
|
|
|
}
|
|
|
|
if (towers[x][y] != null) {
|
|
|
|
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
|
|
|
|
}
|
|
|
|
if (money < Tower.COST) {
|
|
|
|
throw new InvalidPlacementException(InvalidPlacementReason.NOT_ENOUGH_MONEY);
|
|
|
|
}
|
|
|
|
money -= Tower.COST;
|
|
|
|
moneyCallback.call(player, money);
|
|
|
|
towers[x][y] = tower;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addMoney(int amount) {
|
|
|
|
money += amount;
|
2025-03-13 12:08:07 +01:00
|
|
|
moneyCallback.call(player, money);
|
2025-03-12 14:34:55 +01:00
|
|
|
}
|
|
|
|
}
|