|
|
@ -10,6 +10,7 @@ public class MyMouseListener implements MouseInputListener { |
|
|
|
|
|
|
|
private SaveStack save; |
|
|
|
private BaseStack tempStack; |
|
|
|
private BaseStack selectedStack; |
|
|
|
private Card tempCard; |
|
|
|
|
|
|
|
public MyMouseListener(SaveStack _save) { |
|
|
@ -27,41 +28,55 @@ public class MyMouseListener implements MouseInputListener { |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
System.out.println("DOWN"); |
|
|
|
Component com = SwingUtilities.getDeepestComponentAt( |
|
|
|
e.getComponent(), e.getX(), e.getY()); |
|
|
|
// System.out.println("########"); |
|
|
|
// System.out.println(com.toString()); |
|
|
|
// System.out.println(com.getParent().toString()); |
|
|
|
// System.out.println("########"); |
|
|
|
|
|
|
|
//Leeres StartFeld |
|
|
|
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) { |
|
|
|
// Karte, die in einem StartStack liegt |
|
|
|
else 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)) { |
|
|
|
if (save.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(); |
|
|
|
System.out.println("Turn"+tempCard.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
// Card faceUp |
|
|
|
else { |
|
|
|
// move all Cards below the selected Card to Save |
|
|
|
int index = tempStack.indexOfCard(tempCard); |
|
|
|
while (tempStack.stackSize() - 1 >= index) { |
|
|
|
save.addCard(tempStack.removeLastCard()); |
|
|
|
} |
|
|
|
selectedStack = tempStack; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//saveStack is NOT empty |
|
|
|
else { |
|
|
|
if(selectedStack == null) { |
|
|
|
System.out.println("ERROR selectedStack in StartStack"); |
|
|
|
} |
|
|
|
if(tempStack.cardCheck(tempStack.peekLastCard(), save.peekLastCard())) { |
|
|
|
while(!save.stackIsEmpty()) { |
|
|
|
tempStack.addCard(save.removeLastCard()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
//Alles wieder auf den Ursprünglichen Stack packen |
|
|
|
while(!save.stackIsEmpty()) { |
|
|
|
selectedStack.addCard(save.removeLastCard()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//System.out.println("Karte in StartStack"+com.toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//save.addCard(((BaseStack)com.getParent()).removeLastCard());; |
|
|
|
selectedStack = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|