TD-52 buy tower for Money
All checks were successful
Quality Check / Validate OAS (push) Successful in 32s
Quality Check / Linting (push) Successful in 1m12s
Quality Check / Validate OAS (pull_request) Successful in 39s
Quality Check / Testing (push) Successful in 1m13s
Quality Check / Static Analysis (push) Successful in 1m19s
Quality Check / Linting (pull_request) Successful in 1m5s
Quality Check / Testing (pull_request) Successful in 48s
Quality Check / Static Analysis (pull_request) Successful in 53s
All checks were successful
Quality Check / Validate OAS (push) Successful in 32s
Quality Check / Linting (push) Successful in 1m12s
Quality Check / Validate OAS (pull_request) Successful in 39s
Quality Check / Testing (push) Successful in 1m13s
Quality Check / Static Analysis (push) Successful in 1m19s
Quality Check / Linting (pull_request) Successful in 1m5s
Quality Check / Testing (pull_request) Successful in 48s
Quality Check / Static Analysis (pull_request) Successful in 53s
This commit is contained in:
parent
ec63412af2
commit
b6bff21a11
4 changed files with 19 additions and 7 deletions
|
@ -4,7 +4,6 @@ import de.towerdefence.server.player.Player;
|
||||||
import de.towerdefence.server.server.channels.match.money.PlayerMoneyCallback;
|
import de.towerdefence.server.server.channels.match.money.PlayerMoneyCallback;
|
||||||
import de.towerdefence.server.server.channels.match.placing.InvalidPlacementReason;
|
import de.towerdefence.server.server.channels.match.placing.InvalidPlacementReason;
|
||||||
import de.towerdefence.server.server.channels.match.placing.Tower;
|
import de.towerdefence.server.server.channels.match.placing.Tower;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -12,6 +11,7 @@ import java.util.Optional;
|
||||||
@Getter
|
@Getter
|
||||||
public class Match {
|
public class Match {
|
||||||
|
|
||||||
|
public static final int TOWER_PRICE = 20;
|
||||||
public final static int MAP_SIZE_X = 10;
|
public final static int MAP_SIZE_X = 10;
|
||||||
public final static int MAP_SIZE_Y = 20;
|
public final static int MAP_SIZE_Y = 20;
|
||||||
public final static int START_MONEY = 50;
|
public final static int START_MONEY = 50;
|
||||||
|
@ -59,11 +59,13 @@ public class Match {
|
||||||
if (player1Map[x][y] != null) {
|
if (player1Map[x][y] != null) {
|
||||||
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
|
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
|
||||||
}
|
}
|
||||||
|
removeMoney(player, TOWER_PRICE);
|
||||||
player1Map[x][y] = tower;
|
player1Map[x][y] = tower;
|
||||||
} else {
|
} else {
|
||||||
if (player2Map[x][y] != null) {
|
if (player2Map[x][y] != null) {
|
||||||
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
|
throw new InvalidPlacementException(InvalidPlacementReason.LOCATION_USED);
|
||||||
}
|
}
|
||||||
|
removeMoney(player, TOWER_PRICE);
|
||||||
player2Map[x][y] = tower;
|
player2Map[x][y] = tower;
|
||||||
}
|
}
|
||||||
return getOpponent(player);
|
return getOpponent(player);
|
||||||
|
@ -87,16 +89,24 @@ public class Match {
|
||||||
player2Money += money;
|
player2Money += money;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMoney(Player player, int money) {
|
public void removeMoney(Player player, int price) throws InvalidPlacementException {
|
||||||
if (player == player1) {
|
if (player == player1) {
|
||||||
player1Money -= money;
|
if (price < player1Money) {
|
||||||
|
player1Money -= price;
|
||||||
|
} else {
|
||||||
|
throw new InvalidPlacementException(InvalidPlacementReason.NOT_ENOUGH_MONEY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (player == player2) {
|
if (player == player2) {
|
||||||
player2Money -= money;
|
if (price < player2Money) {
|
||||||
|
player2Money -= price;
|
||||||
|
} else {
|
||||||
|
throw new InvalidPlacementException(InvalidPlacementReason.NOT_ENOUGH_MONEY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerMoneyCallback( Player player, PlayerMoneyCallback playerMoneyCallback) {
|
public void setPlayerMoneyCallback(Player player, PlayerMoneyCallback playerMoneyCallback) {
|
||||||
if (player == player1) {
|
if (player == player1) {
|
||||||
this.player1MoneyCallback = playerMoneyCallback;
|
this.player1MoneyCallback = playerMoneyCallback;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class MatchService {
|
||||||
/**
|
/**
|
||||||
* @return opponent
|
* @return opponent
|
||||||
*/
|
*/
|
||||||
public Player placeTower(Player player, int x, int y) throws InvalidPlacementException {
|
public Player placeTower(Player player, int x, int y) throws InvalidPlacementException{
|
||||||
return playerMatches.get(player).addTower(player, new Tower(), x, y);
|
return playerMatches.get(player).addTower(player, new Tower(), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ import lombok.Getter;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum InvalidPlacementReason {
|
public enum InvalidPlacementReason {
|
||||||
OUT_OF_BOUNDS("out-of-bounds"),
|
OUT_OF_BOUNDS("out-of-bounds"),
|
||||||
LOCATION_USED("location-used");
|
LOCATION_USED("location-used"),
|
||||||
|
NOT_ENOUGH_MONEY("not-enough-money");
|
||||||
|
|
||||||
private final String jsonName;
|
private final String jsonName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,7 @@ channels:
|
||||||
enum:
|
enum:
|
||||||
- "out-of-bounds"
|
- "out-of-bounds"
|
||||||
- "location-used"
|
- "location-used"
|
||||||
|
- "not-enough-money"
|
||||||
required:
|
required:
|
||||||
- $id
|
- $id
|
||||||
- x
|
- x
|
||||||
|
|
Loading…
Add table
Reference in a new issue