From 745b86a8f37cae3b8526aa04148da9c1951ed5bd Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Mon, 25 Mar 2019 13:28:42 +0100 Subject: [PATCH] Add visualizing of flag castles --- Projektgruppe_175/src/game/Game.java | 8 +++++ .../src/game/goals/CaptureTheFlagGoal.java | 8 ++++- .../src/gui/components/MapPanel.java | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Projektgruppe_175/src/game/Game.java b/Projektgruppe_175/src/game/Game.java index caa7376..45722b0 100644 --- a/Projektgruppe_175/src/game/Game.java +++ b/Projektgruppe_175/src/game/Game.java @@ -53,6 +53,14 @@ public class Game { this.goal = goal; 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 diff --git a/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java b/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java index beecaaf..3df0cc3 100644 --- a/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java +++ b/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java @@ -89,6 +89,12 @@ public class CaptureTheFlagGoal extends Goal { } + public boolean isFlagCastle(Castle castle) { + + return flagCastles.contains(castle); + + } + /** * Distribute the flag castles evenly to * all players @@ -133,7 +139,7 @@ public class CaptureTheFlagGoal extends Goal { private List pickRandomCastles(List castles, int num) { int min = 0; - int max = castles.size(); + int max = castles.size() - 1; List nums = new ArrayList(); diff --git a/Projektgruppe_175/src/gui/components/MapPanel.java b/Projektgruppe_175/src/gui/components/MapPanel.java index 0f5ace7..34f1a67 100644 --- a/Projektgruppe_175/src/gui/components/MapPanel.java +++ b/Projektgruppe_175/src/gui/components/MapPanel.java @@ -14,6 +14,7 @@ import game.AI; import game.Game; import game.map.PathFinding; import game.Player; +import game.goals.CaptureTheFlagGoal; import game.map.Castle; import game.map.GameMap; import game.players.Human; @@ -389,6 +390,7 @@ public class MapPanel extends JScrollPane { if (map != null) { g.drawImage(map.getBackgroundImage(), offset.x, offset.y, null); + // Draw the connections if (showConnections) { for (Edge edge : map.getEdges()) { Point p1 = translate(edge.getNodeA().getValue().getLocationOnMap()); @@ -407,12 +409,31 @@ public class MapPanel extends JScrollPane { } } + // Draw the castles for (Castle region : map.getCastles()) { Color color = region.getOwner() == null ? Color.WHITE : region.getOwner().getColor(); Point location = translate(region.getLocationOnMap()); BufferedImage castle = resources.getCastle(color, region.getType()); 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 if(region.getTroopCount() > 0) { BufferedImage unitIcon = resources.getUnitIcon(); @@ -443,18 +464,31 @@ public class MapPanel extends JScrollPane { g.drawImage(icon, x, y, ICON_SIZE, ICON_SIZE, null); } + // Capture the flag specific visuals + if (game.getGoal() instanceof CaptureTheFlagGoal) { + + + + } + // HUD if (selectedCastle != null) { + // Draw rectangle around the selected castle Point location = translate(selectedCastle.getLocationOnMap()); g.setColor(selectedCastle.getOwner() == null ? Color.WHITE : selectedCastle.getOwner().getColor()); g.drawRect(location.x - 5, location.y - 5, CASTLE_SIZE + 10, CASTLE_SIZE + 10); + // Draw actions if(canPerformAction()) { + + // Choose castle if (canChooseCastle()) { BufferedImage icon = resources.getCheckIcon(); Rectangle bounds = getBoundsIconCheck(location); g.drawImage(icon, bounds.x, bounds.y, ICON_SIZE, ICON_SIZE, null); + + // Use castle } else if (selectedCastle.getOwner() == game.getCurrentPlayer() && game.getRound() > 1) { boolean hasTroops = game.getCurrentPlayer().getRemainingTroops() > 0; boolean canMove = selectedCastle.getTroopCount() > 1;