diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 4067231..70aec81 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -30,37 +30,49 @@ public class MyMouseListener implements MouseInputListener { System.out.println("DOWN"); Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); - // 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) { - tempCard = (Card) com; - tempStack = (StartStack) com.getParent(); +// // 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())) { if (saveStack.stackIsEmpty()) { - // Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um - if (!tempCard.isFaceUp()) { - if (tempStack.peekLastCard().equals(tempCard)) { - tempCard.setFaceUp(true); - tempCard.repaint(); - } - } - // Card faceUp - else { - // move all Cards below the selected Card to Save - int index = tempStack.indexOfCard(tempCard); - while (tempStack.stackSize() - 1 >= index) { - saveStack.addCard(tempStack.removeLastCard()); + + if (com instanceof Card && com.getParent() instanceof StartStack) { + tempCard = (Card) com; + tempStack = (StartStack) com.getParent(); + + // Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um + if (!tempCard.isFaceUp()) { + if (tempStack.peekLastCard().equals(tempCard)) { + tempCard.setFaceUp(true); + tempCard.repaint(); + } } - selectedStack = tempStack; + // Card faceUp + else { + // move all Cards below the selected Card to Save + int index = tempStack.indexOfCard(tempCard); + while (tempStack.stackSize() - 1 >= index) { + saveStack.addCard(tempStack.removeLastCard()); + } + selectedStack = tempStack; + } } } // saveStack is NOT empty else { + if(com instanceof StartStack) { + tempStack = (StartStack) com; + } else { + tempStack = (StartStack) com.getParent(); + } + if (selectedStack == null) { System.out.println("ERROR selectedStack in StartStack"); } diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index f3f757d..7eaf634 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -55,8 +55,8 @@ public class SolitaerGamePanel extends JPanel { 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);