diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 4e9a08a..c79d440 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -58,26 +58,61 @@ public class MyMouseListener implements MouseInputListener { selectedStack = tempStack; } - } - //saveStack is NOT empty + } + // saveStack is NOT empty else { - if(selectedStack == null) { + if (selectedStack == null) { System.out.println("ERROR selectedStack in StartStack"); } - if(tempStack.cardCheck(tempStack.peekLastCard(), saveStack.peekLastCard())) { - while(!saveStack.stackIsEmpty()) { + if (tempStack.cardCheck(tempStack.peekLastCard(), saveStack.peekLastCard())) { + while (!saveStack.stackIsEmpty()) { tempStack.addCard(saveStack.removeLastCard()); } } else { - //Alles wieder auf den Ursprünglichen Stack packen - while(!saveStack.stackIsEmpty()) { + // Alles wieder auf den Ursprünglichen Stack packen + while (!saveStack.stackIsEmpty()) { selectedStack.addCard(saveStack.removeLastCard()); } } - + selectedStack = null; } } + // AblageStack + else if (com.getParent() instanceof AblageStack || com instanceof AblageStack) { + + System.out.println("AblageStack"); + + if (com instanceof AblageStack) { + tempStack = (AblageStack) com; + } else { + tempStack = (AblageStack) com.getParent(); + + } + + if (saveStack.stackIsEmpty()) { + // Move Top Card from AblageStack in Save + if (tempStack.stackIsEmpty() == false) { + saveStack.addCard(tempStack.removeLastCard()); + selectedStack = tempStack; + } + + } else { + // Move Card from Save in AblageStack + if (saveStack.stackSize() == 1) { + if (tempStack.cardCheck(tempStack.peekLastCard(), saveStack.peekLastCard())) { + tempStack.addCard(saveStack.removeLastCard()); + } + + } else { + // Alles wieder auf den Ursprünglichen Stack packen + while (!saveStack.stackIsEmpty()) { + selectedStack.addCard(saveStack.removeLastCard()); + } + } + } + + } } diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index a7a56f5..4c16f06 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -26,9 +26,7 @@ public class SolitaerGamePanel extends JPanel { StartStack a = new StartStack(25,125); - - a.addCard(deck.getDeck().get(0)); - + deck.getDeck().get(5).setFaceUp(true); a.addCard((deck.getDeck().get(5))); @@ -44,6 +42,9 @@ public class SolitaerGamePanel extends JPanel { deck.getDeck().get(1).setFaceUp(true); a.addCard((deck.getDeck().get(1))); + deck.getDeck().get(0).setFaceUp(true); + a.addCard(deck.getDeck().get(0)); + this.add(a); StartStack b = new StartStack(200,125); @@ -54,10 +55,14 @@ public class SolitaerGamePanel extends JPanel { StartStack c = new StartStack(375,125); - deck.getDeck().get(33).setFaceUp(true); - c.addCard((deck.getDeck().get(33))); + deck.getDeck().get(13).setFaceUp(true); + c.addCard((deck.getDeck().get(12))); this.add(c); + + StartStack d = new StartStack(475,125); + this.add(d); + //save = new SaveStack(500,250); this.add(save);