Update MapPanel.java - Joker funktionalität
This commit is contained in:
parent
d155b7f18e
commit
cc8df22352
1 changed files with 67 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import java.awt.*;
|
|||
import java.awt.event.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
@ -30,6 +31,9 @@ public class MapPanel extends JScrollPane {
|
|||
ATTACKING
|
||||
}
|
||||
|
||||
private boolean isChoosingJoker = false;
|
||||
|
||||
|
||||
private static final int CASTLE_SIZE = 50;
|
||||
private static final int ICON_SIZE = 20;
|
||||
private final GameView gameView;
|
||||
|
|
@ -112,6 +116,9 @@ public class MapPanel extends JScrollPane {
|
|||
public void mouseReleased(MouseEvent mouseEvent) {
|
||||
super.mousePressed(mouseEvent);
|
||||
|
||||
if(isChoosingJoker)
|
||||
return;
|
||||
|
||||
if(getCursor().getType() == Cursor.MOVE_CURSOR)
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
}
|
||||
|
|
@ -154,6 +161,61 @@ public class MapPanel extends JScrollPane {
|
|||
boolean selectNew = true;
|
||||
Action lastAction = currentAction;
|
||||
|
||||
if(isChoosingJoker) {
|
||||
// Verscheuchen-Joker funktionalität
|
||||
Castle scared = getRegion(mousePos);
|
||||
if(scared == null)
|
||||
return;
|
||||
if(scared.getOwner() == game.getCurrentPlayer()) {
|
||||
return;
|
||||
}
|
||||
System.out.println("Ausgewählt: " + scared.getName());
|
||||
List<Edge<Castle>> castleEdges = map.getEdges();
|
||||
List<Castle> adjacentCastles = new ArrayList<>();
|
||||
for(Edge<Castle> edge : castleEdges) {
|
||||
if(edge.getNodeA().getValue().equals(scared)) {
|
||||
if(edge.getNodeB().getValue().getOwner() != game.getCurrentPlayer() && !edge.getNodeB().getValue().equals(scared)) {
|
||||
adjacentCastles.add(edge.getNodeB().getValue());
|
||||
System.out.print("added: " + edge.getNodeB().getValue().getName());
|
||||
}
|
||||
} else if(edge.getNodeB().getValue().equals(scared)) {
|
||||
if(edge.getNodeA().getValue().getOwner() != game.getCurrentPlayer() && !edge.getNodeA().getValue().equals(scared)) {
|
||||
adjacentCastles.add(edge.getNodeA().getValue());
|
||||
System.out.print("added: " + edge.getNodeA().getValue().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int troopsToDistribute = scared.getTroopCount() - 1;
|
||||
System.out.println(troopsToDistribute);
|
||||
scared.removeTroops(troopsToDistribute);
|
||||
System.out.println(adjacentCastles.size());
|
||||
for(Castle c : adjacentCastles) {
|
||||
System.out.print(c.getName() + " ");
|
||||
}
|
||||
|
||||
if(adjacentCastles.isEmpty()) {
|
||||
gameView.revalidate();
|
||||
gameView.repaint();
|
||||
isChoosingJoker = false;
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
for(int i = 0; i < troopsToDistribute; i++) {
|
||||
int castleNumber = random.nextInt(adjacentCastles.size());
|
||||
System.out.print(castleNumber + " ");
|
||||
adjacentCastles.get(castleNumber).addTroops(1);
|
||||
}
|
||||
|
||||
gameView.revalidate();
|
||||
gameView.repaint();
|
||||
isChoosingJoker = false;
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedCastle != null && canPerformAction()) {
|
||||
Point castlePos = selectedCastle.getLocationOnMap();
|
||||
|
||||
|
|
@ -554,6 +616,11 @@ public class MapPanel extends JScrollPane {
|
|||
repaint();
|
||||
}
|
||||
|
||||
public void setIsChoosingJoker(boolean b) {
|
||||
this.isChoosingJoker = b;
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
currentAction = MapPanel.Action.NONE;
|
||||
selectedCastle = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue