From 5574ea06eac5424dc9c18f58ec7f67bcafd662e5 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Tue, 12 Feb 2019 20:00:53 +0100 Subject: [PATCH] Update von dem ganzen Projekt auf 1.1 --- Projektgruppe_175/src/base/GraphAlgorithm.java | 9 ++++++++- Projektgruppe_175/src/game/map/PathFinding.java | 7 +++++++ Projektgruppe_175/src/gui/AttackThread.java | 4 ++-- Projektgruppe_175/src/gui/components/MapPanel.java | 12 ++++++++---- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Projektgruppe_175/src/base/GraphAlgorithm.java b/Projektgruppe_175/src/base/GraphAlgorithm.java index c06563d..baa1f6b 100644 --- a/Projektgruppe_175/src/base/GraphAlgorithm.java +++ b/Projektgruppe_175/src/base/GraphAlgorithm.java @@ -46,7 +46,7 @@ public abstract class GraphAlgorithm { this.algorithmNodes = new HashMap<>(); for(Node node : graph.getNodes()) - this.algorithmNodes.put(node, new AlgorithmNode<>(sourceNode, null, -1)); + this.algorithmNodes.put(node, new AlgorithmNode<>(node, null, -1)); this.algorithmNodes.get(sourceNode).value = 0; } @@ -115,4 +115,11 @@ public abstract class GraphAlgorithm { * @return true, wenn die Kante passierbar ist. */ protected abstract boolean isPassable(Edge edge); + + /** + * Gibt an, ob eine Knoten passierbar ist. + * @param node Eine Knoten + * @return true, wenn der Knoten passierbar ist. + */ + protected abstract boolean isPassable(Node node); } diff --git a/Projektgruppe_175/src/game/map/PathFinding.java b/Projektgruppe_175/src/game/map/PathFinding.java index 2120838..5709a16 100644 --- a/Projektgruppe_175/src/game/map/PathFinding.java +++ b/Projektgruppe_175/src/game/map/PathFinding.java @@ -1,6 +1,7 @@ package game.map; import base.GraphAlgorithm; +import base.Node; import base.Edge; import base.Graph; import game.Player; @@ -52,6 +53,12 @@ public class PathFinding extends GraphAlgorithm { } } + + @Override + protected boolean isPassable(Node node) { + return node.getValue().getOwner() == currentPlayer; + } + public List> getPath(Castle targetCastle) { return this.getPath(getGraph().getNode(targetCastle)); } diff --git a/Projektgruppe_175/src/gui/AttackThread.java b/Projektgruppe_175/src/gui/AttackThread.java index 6affbca..87e2d29 100644 --- a/Projektgruppe_175/src/gui/AttackThread.java +++ b/Projektgruppe_175/src/gui/AttackThread.java @@ -46,7 +46,7 @@ public class AttackThread extends Thread { while(attackerCastle.getTroopCount() > attackUntil) { // Attacker dices: at maximum 3 and not more than actual troop count - int attackerCount = Math.min(troopAttackCount, Math.min(attackerCastle.getTroopCount(), 3)); + int attackerCount = Math.min(troopAttackCount, Math.min(attackerCastle.getTroopCount() - 1, 3)); int attackerDice[] = game.roll(attacker, attackerCount, fastForward); sleep(1500); @@ -73,4 +73,4 @@ public class AttackThread extends Thread { public Player getWinner() { return winner; } -} \ No newline at end of file +} diff --git a/Projektgruppe_175/src/gui/components/MapPanel.java b/Projektgruppe_175/src/gui/components/MapPanel.java index 32ca60e..0f5ace7 100644 --- a/Projektgruppe_175/src/gui/components/MapPanel.java +++ b/Projektgruppe_175/src/gui/components/MapPanel.java @@ -203,7 +203,7 @@ public class MapPanel extends JScrollPane { currentAction = Action.NONE; selectedCastle = nextCastle; setCursor(Cursor.getDefaultCursor()); - } else if(currentAction == Action.MOVING) { + } else if(currentAction == Action.MOVING && pathFinding.getPath(nextCastle) != null) { NumberDialog nd = new NumberDialog("Wie viele Truppen möchtest du verschieben?", 1, selectedCastle.getTroopCount() - 1, 1); if(nd.showDialog(MapPanel.this)) { selectedCastle.moveTroops(nextCastle, nd.getValue()); @@ -214,12 +214,16 @@ public class MapPanel extends JScrollPane { setCursor(Cursor.getDefaultCursor()); gameView.updateStats(); } - } else if(currentAction == Action.ATTACKING) { - NumberDialog nd = new NumberDialog("Mit wie vielen Truppen möchtest du angreifen?", 1, selectedCastle.getTroopCount(), selectedCastle.getTroopCount()); + } else if(currentAction == Action.ATTACKING && pathFinding.getPath(nextCastle) != null && nextCastle.getOwner() != selectedCastle.getOwner()) { + NumberDialog nd = new NumberDialog("Mit wie vielen Truppen möchtest du angreifen?", 1, selectedCastle.getTroopCount(), selectedCastle.getTroopCount() - 1); if(nd.showDialog(MapPanel.this)) { - game.startAttack(selectedCastle, targetCastle, nd.getValue()); + game.startAttack(selectedCastle, nextCastle, nd.getValue()); currentAction = Action.NONE; } + } else { + currentAction = Action.NONE; + selectedCastle = nextCastle; + setCursor(Cursor.getDefaultCursor()); } }