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.event.*;
|
||||||
import java.awt.geom.Line2D;
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
@ -30,6 +31,9 @@ public class MapPanel extends JScrollPane {
|
||||||
ATTACKING
|
ATTACKING
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isChoosingJoker = false;
|
||||||
|
|
||||||
|
|
||||||
private static final int CASTLE_SIZE = 50;
|
private static final int CASTLE_SIZE = 50;
|
||||||
private static final int ICON_SIZE = 20;
|
private static final int ICON_SIZE = 20;
|
||||||
private final GameView gameView;
|
private final GameView gameView;
|
||||||
|
|
@ -112,6 +116,9 @@ public class MapPanel extends JScrollPane {
|
||||||
public void mouseReleased(MouseEvent mouseEvent) {
|
public void mouseReleased(MouseEvent mouseEvent) {
|
||||||
super.mousePressed(mouseEvent);
|
super.mousePressed(mouseEvent);
|
||||||
|
|
||||||
|
if(isChoosingJoker)
|
||||||
|
return;
|
||||||
|
|
||||||
if(getCursor().getType() == Cursor.MOVE_CURSOR)
|
if(getCursor().getType() == Cursor.MOVE_CURSOR)
|
||||||
setCursor(Cursor.getDefaultCursor());
|
setCursor(Cursor.getDefaultCursor());
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +161,61 @@ public class MapPanel extends JScrollPane {
|
||||||
boolean selectNew = true;
|
boolean selectNew = true;
|
||||||
Action lastAction = currentAction;
|
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()) {
|
if (selectedCastle != null && canPerformAction()) {
|
||||||
Point castlePos = selectedCastle.getLocationOnMap();
|
Point castlePos = selectedCastle.getLocationOnMap();
|
||||||
|
|
||||||
|
|
@ -553,6 +615,11 @@ public class MapPanel extends JScrollPane {
|
||||||
this.selectedCastle = null;
|
this.selectedCastle = null;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIsChoosingJoker(boolean b) {
|
||||||
|
this.isChoosingJoker = b;
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
currentAction = MapPanel.Action.NONE;
|
currentAction = MapPanel.Action.NONE;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue