Update von dem ganzen Projekt auf 1.1

This commit is contained in:
joachimschmidt557 2019-02-12 20:00:53 +01:00
parent f9c67cb2e0
commit 5574ea06ea
4 changed files with 25 additions and 7 deletions

View file

@ -46,7 +46,7 @@ public abstract class GraphAlgorithm<T> {
this.algorithmNodes = new HashMap<>(); this.algorithmNodes = new HashMap<>();
for(Node<T> node : graph.getNodes()) for(Node<T> 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; this.algorithmNodes.get(sourceNode).value = 0;
} }
@ -115,4 +115,11 @@ public abstract class GraphAlgorithm<T> {
* @return true, wenn die Kante passierbar ist. * @return true, wenn die Kante passierbar ist.
*/ */
protected abstract boolean isPassable(Edge<T> edge); protected abstract boolean isPassable(Edge<T> edge);
/**
* Gibt an, ob eine Knoten passierbar ist.
* @param node Eine Knoten
* @return true, wenn der Knoten passierbar ist.
*/
protected abstract boolean isPassable(Node<T> node);
} }

View file

@ -1,6 +1,7 @@
package game.map; package game.map;
import base.GraphAlgorithm; import base.GraphAlgorithm;
import base.Node;
import base.Edge; import base.Edge;
import base.Graph; import base.Graph;
import game.Player; import game.Player;
@ -52,6 +53,12 @@ public class PathFinding extends GraphAlgorithm<Castle> {
} }
} }
@Override
protected boolean isPassable(Node<Castle> node) {
return node.getValue().getOwner() == currentPlayer;
}
public List<Edge<Castle>> getPath(Castle targetCastle) { public List<Edge<Castle>> getPath(Castle targetCastle) {
return this.getPath(getGraph().getNode(targetCastle)); return this.getPath(getGraph().getNode(targetCastle));
} }

View file

@ -46,7 +46,7 @@ public class AttackThread extends Thread {
while(attackerCastle.getTroopCount() > attackUntil) { while(attackerCastle.getTroopCount() > attackUntil) {
// Attacker dices: at maximum 3 and not more than actual troop count // 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); int attackerDice[] = game.roll(attacker, attackerCount, fastForward);
sleep(1500); sleep(1500);

View file

@ -203,7 +203,7 @@ public class MapPanel extends JScrollPane {
currentAction = Action.NONE; currentAction = Action.NONE;
selectedCastle = nextCastle; selectedCastle = nextCastle;
setCursor(Cursor.getDefaultCursor()); 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); NumberDialog nd = new NumberDialog("Wie viele Truppen möchtest du verschieben?", 1, selectedCastle.getTroopCount() - 1, 1);
if(nd.showDialog(MapPanel.this)) { if(nd.showDialog(MapPanel.this)) {
selectedCastle.moveTroops(nextCastle, nd.getValue()); selectedCastle.moveTroops(nextCastle, nd.getValue());
@ -214,12 +214,16 @@ public class MapPanel extends JScrollPane {
setCursor(Cursor.getDefaultCursor()); setCursor(Cursor.getDefaultCursor());
gameView.updateStats(); gameView.updateStats();
} }
} else if(currentAction == Action.ATTACKING) { } 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()); NumberDialog nd = new NumberDialog("Mit wie vielen Truppen möchtest du angreifen?", 1, selectedCastle.getTroopCount(), selectedCastle.getTroopCount() - 1);
if(nd.showDialog(MapPanel.this)) { if(nd.showDialog(MapPanel.this)) {
game.startAttack(selectedCastle, targetCastle, nd.getValue()); game.startAttack(selectedCastle, nextCastle, nd.getValue());
currentAction = Action.NONE; currentAction = Action.NONE;
} }
} else {
currentAction = Action.NONE;
selectedCastle = nextCastle;
setCursor(Cursor.getDefaultCursor());
} }
} }