|
|
@ -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"); |
|
|
|
} |
|
|
|