Update von dem ganzen Projekt auf 1.1
This commit is contained in:
parent
f9c67cb2e0
commit
5574ea06ea
4 changed files with 25 additions and 7 deletions
|
|
@ -46,7 +46,7 @@ public abstract class GraphAlgorithm<T> {
|
|||
this.algorithmNodes = new HashMap<>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -115,4 +115,11 @@ public abstract class GraphAlgorithm<T> {
|
|||
* @return true, wenn die Kante passierbar ist.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Castle> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isPassable(Node<Castle> node) {
|
||||
return node.getValue().getOwner() == currentPlayer;
|
||||
}
|
||||
|
||||
public List<Edge<Castle>> getPath(Castle targetCastle) {
|
||||
return this.getPath(getGraph().getNode(targetCastle));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue