Browse Source

Fix MouseInput StartStack

feature_solitaer_fix_StartStack
Alexander Hartung 3 years ago
parent
commit
5f6b3bbfff
  1. 26
      src/main/java/solitaer/MyMouseListener.java
  2. 4
      src/main/java/solitaer/SolitaerGamePanel.java

26
src/main/java/solitaer/MyMouseListener.java

@ -30,17 +30,22 @@ public class MyMouseListener implements MouseInputListener {
System.out.println("DOWN"); System.out.println("DOWN");
Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
// Leeres StartFeld
if (com instanceof StartStack) {
System.out.println("Leer Start");
// // Leeres StartFeld
// if (com instanceof StartStack) {
// System.out.println("Leer Start");
//
// }
// // Karte, die in einem StartStack liegt
// else
if ((com instanceof Card && com.getParent() instanceof StartStack)
|| (com instanceof StartStack && ((StartStack) com).stackIsEmpty())) {
}
// Karte, die in einem StartStack liegt
else if (com instanceof Card && com.getParent() instanceof StartStack) {
if (saveStack.stackIsEmpty()) {
if (com instanceof Card && com.getParent() instanceof StartStack) {
tempCard = (Card) com; tempCard = (Card) com;
tempStack = (StartStack) com.getParent(); tempStack = (StartStack) com.getParent();
if (saveStack.stackIsEmpty()) {
// Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um // Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um
if (!tempCard.isFaceUp()) { if (!tempCard.isFaceUp()) {
if (tempStack.peekLastCard().equals(tempCard)) { if (tempStack.peekLastCard().equals(tempCard)) {
@ -59,8 +64,15 @@ public class MyMouseListener implements MouseInputListener {
} }
} }
}
// saveStack is NOT empty // saveStack is NOT empty
else { else {
if(com instanceof StartStack) {
tempStack = (StartStack) com;
} else {
tempStack = (StartStack) com.getParent();
}
if (selectedStack == null) { if (selectedStack == null) {
System.out.println("ERROR selectedStack in StartStack"); System.out.println("ERROR selectedStack in StartStack");
} }

4
src/main/java/solitaer/SolitaerGamePanel.java

@ -55,8 +55,8 @@ public class SolitaerGamePanel extends JPanel {
StartStack c = new StartStack(375,125); StartStack c = new StartStack(375,125);
deck.getDeck().get(10).setFaceUp(true);
c.addCard((deck.getDeck().get(10)));
//deck.getDeck().get(20).setFaceUp(true);
c.addCard((deck.getDeck().get(20)));
this.add(c); this.add(c);

Loading…
Cancel
Save