Skip to content

Commit

Permalink
Merge pull request #114 from EntelectChallenge/develop
Browse files Browse the repository at this point in the history
Phase 3 Release 3.0.0
  • Loading branch information
Blaarkies authored Aug 10, 2018
2 parents 0c095c4 + 09bba09 commit 93e073a
Show file tree
Hide file tree
Showing 30 changed files with 1,372 additions and 838 deletions.
2 changes: 1 addition & 1 deletion game-engine-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>za.co.entelect.challenge</groupId>
<artifactId>game-engine-interface</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>

<distributionManagement>
<repository>
Expand Down
4 changes: 2 additions & 2 deletions game-engine/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>game-engine</artifactId>
<groupId>za.co.entelect.challenge</groupId>
<version>2.0.3</version>
<version>3.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -27,7 +27,7 @@
<dependency>
<groupId>za.co.entelect.challenge</groupId>
<artifactId>domain</artifactId>
<version>2.0.3</version>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.logging.log4j.Logger;
import za.co.entelect.challenge.commands.DeconstructBuildingCommand;
import za.co.entelect.challenge.commands.DoNothingCommand;
import za.co.entelect.challenge.commands.IronCurtainCommand;
import za.co.entelect.challenge.commands.PlaceBuildingCommand;
import za.co.entelect.challenge.config.GameConfig;
import za.co.entelect.challenge.entities.Building;
Expand Down Expand Up @@ -32,21 +33,19 @@ public boolean processRound(GameMap gameMap, Hashtable<GamePlayer, RawCommand> c
towerDefenseGameMap = (TowerDefenseGameMap) gameMap;
towerDefenseGameMap.clearErrorList();
towerDefenseGameMap.clearTeslaTargetList();
towerDefenseGameMap.clearIroncurtainHitList();

processCommands(commands);

constructBuildings();

try {
fireTeslaTowers();
} catch (Exception e) {
log.error(e);
}
updateIronCurtains();
fireTeslaTowers();

createMissilesFromAttackBuildings();
calculateMissileMovement();
removeDeadEntities();
moveMissiles();

removeDeadEntities();
addResources();

return true;
Expand All @@ -62,25 +61,41 @@ private void constructBuildings() {
.forEach(b -> b.decreaseConstructionTimeLeft());
}

private void updateIronCurtains() {
towerDefenseGameMap.getTowerDefensePlayers()
.forEach(p -> p.updateIronCurtain(towerDefenseGameMap.getCurrentRound()));
}

private void createMissilesFromAttackBuildings() {
towerDefenseGameMap.getBuildings().stream()
.filter(b -> b.isConstructed() && b.getBuildingType() == BuildingType.ATTACK)
.forEach(b -> towerDefenseGameMap.addMissileFromBuilding(b));
}

private void fireTeslaTowers() throws Exception {
private void fireTeslaTowers() {
List<Building> playerTeslaTowers = towerDefenseGameMap.getBuildings().stream()
.filter(b -> b.isConstructed() && b.getBuildingType() == BuildingType.TESLA)
.sorted(Comparator.comparing(b -> b.getConstructionTimeLeft()))
.collect(Collectors.toList());

for (Building teslaTower : playerTeslaTowers) {

TowerDefensePlayer currentPlayer = towerDefenseGameMap.getPlayer(teslaTower.getPlayerType());
TowerDefensePlayer currentPlayer = null;
try {
currentPlayer = towerDefenseGameMap.getPlayer(teslaTower.getPlayerType());
} catch (Exception e) {
log.error(e);
}

int playerEnergy = currentPlayer.getEnergy();

if (playerEnergy >= teslaTower.getEnergyPerShot() && teslaTower.getWeaponCooldownTimeLeft() == 0) {
currentPlayer.removeEnergy(teslaTower.getEnergyPerShot());
try {
currentPlayer.removeEnergy(teslaTower.getEnergyPerShot());
} catch (Exception e) {
log.error(e);
}

towerDefenseGameMap.fireTeslaTower(teslaTower);
teslaTower.resetCooldown();
} else {
Expand Down Expand Up @@ -131,7 +146,7 @@ private void removeDeadEntities() {
.forEach(p -> towerDefenseGameMap.removeMissile(p));
}

private void calculateMissileMovement() {
private void moveMissiles() {
int maxMissileSpeed = towerDefenseGameMap.getMissiles().stream()
.mapToInt(m -> m.getSpeed())
.max().orElse(0);
Expand Down Expand Up @@ -172,6 +187,8 @@ private void parseAndExecuteCommand(RawCommand command, GamePlayer player) {
towerDefensePlayer.setConsecutiveDoNothings(0);
if (buildingType == BuildingType.DECONSTRUCT) {
new DeconstructBuildingCommand(positionX, positionY).performCommand(towerDefenseGameMap, player);
} else if (buildingType == BuildingType.IRONCURTAIN) {
new IronCurtainCommand().performCommand(towerDefenseGameMap, player);
} else {
new PlaceBuildingCommand(positionX, positionY, buildingType).performCommand(towerDefenseGameMap, player);
}
Expand All @@ -185,7 +202,7 @@ private void parseAndExecuteCommand(RawCommand command, GamePlayer player) {
} catch (IllegalArgumentException e) {
doNothingCommand.performCommand(towerDefenseGameMap, player, true);
towerDefenseGameMap.addErrorToErrorList(String.format(
"Unable to parse building type: Expected 0[Defense], 1[Attack], 2[Energy], 3[Deconstruct], 4[Tesla]. Received:%s",
"Unable to parse building type: Expected 0[Defense], 1[Attack], 2[Energy], 3[Deconstruct], 4[Tesla], 5[Iron Curtain]. Received:%s",
commandLine[2]), towerDefensePlayer);

log.error(towerDefenseGameMap.getErrorList().get(towerDefenseGameMap.getErrorList().size() - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import za.co.entelect.challenge.enums.BuildingType;
import za.co.entelect.challenge.factories.BuildingFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class GameDetails {

Expand All @@ -20,6 +22,7 @@ public class GameDetails {
private HashMap<BuildingType, Integer> buildingPrices = new HashMap<>();

private HashMap<BuildingType, BuildingStats> buildingsStats = new HashMap<>();
private HashMap<String, Integer> ironCurtainStats = new HashMap<>();

public GameDetails(int round) {
this.round = round;
Expand All @@ -28,12 +31,21 @@ public GameDetails(int round) {
this.mapHeight = GameConfig.getMapHeight();
this.roundIncomeEnergy = GameConfig.getRoundIncomeEnergy();

final List<BuildingType> buildingTypesWithoutStats = new ArrayList<BuildingType>() {{
add(BuildingType.DECONSTRUCT);
add(BuildingType.IRONCURTAIN);
}};
Arrays.stream(BuildingType.values())
.filter(bt -> bt != BuildingType.DECONSTRUCT)
.filter(bt -> !buildingTypesWithoutStats.contains(bt))
.forEach(bt -> buildingPrices.put(bt, BuildingFactory.createBuildingStats(bt).price));

Arrays.stream(BuildingType.values())
.filter(bt -> bt != BuildingType.DECONSTRUCT)
.filter(bt -> !buildingTypesWithoutStats.contains(bt))
.forEach(bt -> buildingsStats.put(bt, BuildingFactory.createBuildingStats(bt)));

ironCurtainStats.put("price", 150);
ironCurtainStats.put("activeRounds", 6);
ironCurtainStats.put("resetPeriod", 50);
ironCurtainStats.put("constructionScore", 20);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
import za.co.entelect.challenge.enums.PlayerType;

public class PlayerData {

protected PlayerType playerType;
protected int energy;
protected int health;
protected int hitsTaken;
protected int score;
protected boolean ironCurtainAvailable;
protected int activeIronCurtainLifetime;

public PlayerData(PlayerType playerType, int energy, int health, int hitsTaken, int score){
public PlayerData(PlayerType playerType, int energy, int health, int hitsTaken, int score, boolean ironCurtainAvailable, int activeIronCurtainLifetime) {
this.playerType = playerType;
this.energy = energy;
this.health = health;
this.hitsTaken = hitsTaken;
this.score = score;
this.ironCurtainAvailable = ironCurtainAvailable;
this.activeIronCurtainLifetime = activeIronCurtainLifetime;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ public class ThreeEntityCell {
private String middle;
private String right;

private boolean ironCurtainCell;

public ThreeEntityCell() {
this.left = " ";
this.middle = " ";
this.right = " ";
this.ironCurtainCell = false;
}

public ThreeEntityCell(Integer y, Integer x) {
this.left = TowerDefenseConsoleMapRenderer.ANSI_GRAY + x.toString() + TowerDefenseConsoleMapRenderer.ANSI_RESET;
this.middle = " ";
this.right = TowerDefenseConsoleMapRenderer.ANSI_GRAY + y.toString() + TowerDefenseConsoleMapRenderer.ANSI_RESET;
}

public void setRight(String right) {
if (StringUtils.isNumeric(removeColour(this.right))) {
this.right = right;
} else {
this.right = this.right + right;
}
this.ironCurtainCell = false;
}

@Override
public String toString() {
if (ironCurtainCell) {
return " " + left + middle + right + " ";
}
return "[" + left + middle + right + "]";
}

Expand All @@ -48,6 +47,28 @@ public void setMiddle(String middle) {
this.middle = middle;
}

public void setRight(String right) {
if (StringUtils.isNumeric(removeColour(this.right))) {
this.right = right;
} else {
this.right = this.right + right;
}
}

public void setShieldLeft(String text) {
this.left = text;
setAsIronCurtainCell();
}

public void setShieldRight(String text) {
this.right = text;
setAsIronCurtainCell();
}

public void setAsIronCurtainCell() {
this.ironCurtainCell = true;
}

public String getLeft() {
return left;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
import java.util.List;

public class TowerDefenseJsonContainer {

protected GameDetails gameDetails;
protected PlayerData[] players;
protected List<PlayerData> players;
protected CellStateContainer[][] gameMap;
protected ArrayList<List<Cell>> teslaHitList;
protected List<Cell> ironcurtainHitList;

public TowerDefenseJsonContainer(CellStateContainer[][] gameMap, PlayerData[] players, int round, ArrayList<List<Cell>> teslaHitList) {
public TowerDefenseJsonContainer(CellStateContainer[][] gameMap,
List<PlayerData> players,
int round,
ArrayList<List<Cell>> teslaHitList,
List<Cell> ironcurtainHitList) {
this.gameDetails = new GameDetails(round);
this.players = players;
this.gameMap = gameMap;
this.teslaHitList = teslaHitList;
this.ironcurtainHitList = ironcurtainHitList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import za.co.entelect.challenge.config.GameConfig;
import za.co.entelect.challenge.core.entities.CellStateContainer;
import za.co.entelect.challenge.entities.Cell;
import za.co.entelect.challenge.entities.TowerDefenseGameMap;
import za.co.entelect.challenge.enums.PlayerType;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class RendererHelper {
Expand Down Expand Up @@ -39,20 +36,20 @@ public static CellStateContainer[][] renderPlayerB(TowerDefenseGameMap towerDefe

towerDefenseGameMap.getMissiles()
.forEach(p -> {
outputMap[p.getY()][GameConfig.getMapWidth() - p.getX() - 1 ].missiles.add(p.getInvertedXInstance());
outputMap[p.getY()][GameConfig.getMapWidth() - p.getX() - 1].missiles.add(p.getInvertedXInstance());
});

return outputMap;
}

private static CellStateContainer[][] generateEmptyBoard(){
private static CellStateContainer[][] generateEmptyBoard() {
CellStateContainer[][] outputMap = new CellStateContainer[GameConfig.getMapHeight()][GameConfig.getMapWidth()];

IntStream.range(0, GameConfig.getMapHeight())
.forEach(y -> {
IntStream.range(0, GameConfig.getMapWidth())
.forEach(x -> {
PlayerType renderedPlayerType = (x >= GameConfig.getMapWidth()/2 ? PlayerType.B : PlayerType.A);
PlayerType renderedPlayerType = (x >= GameConfig.getMapWidth() / 2 ? PlayerType.B : PlayerType.A);

outputMap[y][x] = new CellStateContainer(x, y, renderedPlayerType);
});
Expand Down
Loading

0 comments on commit 93e073a

Please sign in to comment.