package de.towerdefence.server.match; import de.towerdefence.server.match.callbacks.PlayerHitpointsCallback; 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 { final static int START_HITPOINTS = 100; 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; @Getter private int playerHitpoints; private final PlayerMoneyCallback moneyCallback; //private final PlayerHitpointsCallback hitpointsCallback; public GameSession(Player player, PlayerMoneyCallback moneyCallback) { this.player = player; this.moneyCallback = moneyCallback; //this.hitpointsCallback = hitpointsCallback; this.money = START_MONEY; this.playerHitpoints = START_HITPOINTS; } 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; moneyCallback.call(player, money); } }