Add visualizing of flag castles

This commit is contained in:
joachimschmidt557 2019-03-25 13:28:42 +01:00
parent 7f14dc6a42
commit 745b86a8f3
3 changed files with 49 additions and 1 deletions

View file

@ -53,6 +53,14 @@ public class Game {
this.goal = goal; this.goal = goal;
this.goal.setGame(this); this.goal.setGame(this);
} }
/**
* Gets the current goal
* @return The current goal
*/
public Goal getGoal() {
return this.goal;
}
/** /**
* The round this game is currently in * The round this game is currently in

View file

@ -89,6 +89,12 @@ public class CaptureTheFlagGoal extends Goal {
} }
public boolean isFlagCastle(Castle castle) {
return flagCastles.contains(castle);
}
/** /**
* Distribute the flag castles evenly to * Distribute the flag castles evenly to
* all players * all players
@ -133,7 +139,7 @@ public class CaptureTheFlagGoal extends Goal {
private List<Castle> pickRandomCastles(List<Castle> castles, int num) { private List<Castle> pickRandomCastles(List<Castle> castles, int num) {
int min = 0; int min = 0;
int max = castles.size(); int max = castles.size() - 1;
List<Integer> nums = new ArrayList<Integer>(); List<Integer> nums = new ArrayList<Integer>();

View file

@ -14,6 +14,7 @@ import game.AI;
import game.Game; import game.Game;
import game.map.PathFinding; import game.map.PathFinding;
import game.Player; import game.Player;
import game.goals.CaptureTheFlagGoal;
import game.map.Castle; import game.map.Castle;
import game.map.GameMap; import game.map.GameMap;
import game.players.Human; import game.players.Human;
@ -389,6 +390,7 @@ public class MapPanel extends JScrollPane {
if (map != null) { if (map != null) {
g.drawImage(map.getBackgroundImage(), offset.x, offset.y, null); g.drawImage(map.getBackgroundImage(), offset.x, offset.y, null);
// Draw the connections
if (showConnections) { if (showConnections) {
for (Edge<Castle> edge : map.getEdges()) { for (Edge<Castle> edge : map.getEdges()) {
Point p1 = translate(edge.getNodeA().getValue().getLocationOnMap()); Point p1 = translate(edge.getNodeA().getValue().getLocationOnMap());
@ -407,12 +409,31 @@ public class MapPanel extends JScrollPane {
} }
} }
// Draw the castles
for (Castle region : map.getCastles()) { for (Castle region : map.getCastles()) {
Color color = region.getOwner() == null ? Color.WHITE : region.getOwner().getColor(); Color color = region.getOwner() == null ? Color.WHITE : region.getOwner().getColor();
Point location = translate(region.getLocationOnMap()); Point location = translate(region.getLocationOnMap());
BufferedImage castle = resources.getCastle(color, region.getType()); BufferedImage castle = resources.getCastle(color, region.getType());
g.drawImage(castle, location.x, location.y, null); g.drawImage(castle, location.x, location.y, null);
// Capture the flag specific visuals
if (game.getGoal() instanceof CaptureTheFlagGoal) {
CaptureTheFlagGoal goal = (CaptureTheFlagGoal) game.getGoal();
if (goal.isFlagCastle(region)) {
Color prevColor = g.getColor();
Stroke prevStroke = g2.getStroke();
g.setColor(color.WHITE);
g2.setStroke(new BasicStroke(6));
g.drawRoundRect(location.x - 5, location.y - 5, CASTLE_SIZE + 10, CASTLE_SIZE + 10, 5, 5);
g.setColor(prevColor);
g2.setStroke(prevStroke);
}
}
// Draw troop count // Draw troop count
if(region.getTroopCount() > 0) { if(region.getTroopCount() > 0) {
BufferedImage unitIcon = resources.getUnitIcon(); BufferedImage unitIcon = resources.getUnitIcon();
@ -443,18 +464,31 @@ public class MapPanel extends JScrollPane {
g.drawImage(icon, x, y, ICON_SIZE, ICON_SIZE, null); g.drawImage(icon, x, y, ICON_SIZE, ICON_SIZE, null);
} }
// Capture the flag specific visuals
if (game.getGoal() instanceof CaptureTheFlagGoal) {
}
// HUD // HUD
if (selectedCastle != null) { if (selectedCastle != null) {
// Draw rectangle around the selected castle
Point location = translate(selectedCastle.getLocationOnMap()); Point location = translate(selectedCastle.getLocationOnMap());
g.setColor(selectedCastle.getOwner() == null ? Color.WHITE : selectedCastle.getOwner().getColor()); g.setColor(selectedCastle.getOwner() == null ? Color.WHITE : selectedCastle.getOwner().getColor());
g.drawRect(location.x - 5, location.y - 5, CASTLE_SIZE + 10, CASTLE_SIZE + 10); g.drawRect(location.x - 5, location.y - 5, CASTLE_SIZE + 10, CASTLE_SIZE + 10);
// Draw actions
if(canPerformAction()) { if(canPerformAction()) {
// Choose castle
if (canChooseCastle()) { if (canChooseCastle()) {
BufferedImage icon = resources.getCheckIcon(); BufferedImage icon = resources.getCheckIcon();
Rectangle bounds = getBoundsIconCheck(location); Rectangle bounds = getBoundsIconCheck(location);
g.drawImage(icon, bounds.x, bounds.y, ICON_SIZE, ICON_SIZE, null); g.drawImage(icon, bounds.x, bounds.y, ICON_SIZE, ICON_SIZE, null);
// Use castle
} else if (selectedCastle.getOwner() == game.getCurrentPlayer() && game.getRound() > 1) { } else if (selectedCastle.getOwner() == game.getCurrentPlayer() && game.getRound() > 1) {
boolean hasTroops = game.getCurrentPlayer().getRemainingTroops() > 0; boolean hasTroops = game.getCurrentPlayer().getRemainingTroops() > 0;
boolean canMove = selectedCastle.getTroopCount() > 1; boolean canMove = selectedCastle.getTroopCount() > 1;