diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java new file mode 100644 index 0000000..41aa66a --- /dev/null +++ b/src/main/java/solitaer/GeberStack.java @@ -0,0 +1,66 @@ +package solitaer; + +import java.awt.Color; +import java.awt.Graphics; + +public class GeberStack extends BaseStack { + + private static final long serialVersionUID = 1L; + + private WasteStack wasteStack; + + public GeberStack(int _x, int _y, WasteStack _waste) { + super(false); + super.setLocation(_x, _y); + super.setSize(IMAGE_WIDTH, STACK_HIGHT); + super.setOpaque(false); + super.setLayout(null); + + this.wasteStack = _waste; + } + + public WasteStack getWastStack() { + return wasteStack; + } + + public void swapWasteGeber() { + while(wasteStack.stackIsEmpty() == false) { + moveCardTurnFace(wasteStack, this, false); + } + } + + public void moveToWaste() { + moveCardTurnFace(this, wasteStack, true); + } + + private void moveCardTurnFace(BaseStack _removeStack, BaseStack _addStack, boolean _face) { + Card card = _removeStack.removeLastCard(); + card.setFaceUp(_face); + _addStack.addCard(card); + + } + + + @Override + protected boolean cardCheck(Card _topStack, Card _playerCard) { + // TODO Auto-generated method stub + return false; + } + + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + if (stackIsEmpty()) { + g.setColor(Color.pink); + g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); + + g.setColor(Color.black); + g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1); + + String text = "Start\nAgain"; + g.drawString(text, 5, this.IMAGE_HIGHT/2); + } + } + +} diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index ee54111..4067231 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -99,13 +99,48 @@ public class MyMouseListener implements MouseInputListener { } } else { - //Clear Save + // Clear Save clearSaveStack(selectedStack); } } } + // GeberStack + else if (com.getParent() instanceof GeberStack || com instanceof GeberStack) { + System.out.println("GeberStack"); + if (com instanceof GeberStack) { + tempStack = (GeberStack) com; + } else { + tempStack = (GeberStack) com.getParent(); + } + if (tempStack.stackIsEmpty()) { + // Move all from Waste to Geber + ((GeberStack) this.tempStack).swapWasteGeber(); + } else { + // Move next card to Waste + ((GeberStack) this.tempStack).moveToWaste(); + } + } + // WasteStack + else if (com.getParent() instanceof WasteStack || com instanceof WasteStack) { + System.out.println("WasteStack"); + if (com instanceof WasteStack) { + tempStack = (WasteStack) com; + } else { + tempStack = (WasteStack) com.getParent(); + } + if (saveStack.stackIsEmpty()) { + // Move Top Card from AblageStack in Save + if (tempStack.stackIsEmpty() == false) { + saveStack.addCard(tempStack.removeLastCard()); + selectedStack = tempStack; + } + + } else { + clearSaveStack(selectedStack); + } + } } private void clearSaveStack(BaseStack _ziel) { diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 4c16f06..f3f757d 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(13).setFaceUp(true); - c.addCard((deck.getDeck().get(12))); + deck.getDeck().get(10).setFaceUp(true); + c.addCard((deck.getDeck().get(10))); this.add(c); @@ -77,6 +77,26 @@ public class SolitaerGamePanel extends JPanel { this.add(a4); + WasteStack w = new WasteStack(85, 10); + GeberStack g = new GeberStack(10, 10, w); + + deck.getDeck().get(34).setFaceUp(true); + w.addCard(deck.getDeck().get(34)); + deck.getDeck().get(35).setFaceUp(true); + w.addCard(deck.getDeck().get(35)); + deck.getDeck().get(36).setFaceUp(true); + w.addCard(deck.getDeck().get(36)); + deck.getDeck().get(37).setFaceUp(true); + w.addCard(deck.getDeck().get(37)); + + + g.addCard(deck.getDeck().get(38)); + + + this.add(w); + this.add(g); + + } diff --git a/src/main/java/solitaer/WasteStack.java b/src/main/java/solitaer/WasteStack.java new file mode 100644 index 0000000..c86d360 --- /dev/null +++ b/src/main/java/solitaer/WasteStack.java @@ -0,0 +1,38 @@ +package solitaer; + +import java.awt.Color; +import java.awt.Graphics; + +public class WasteStack extends BaseStack { + + private static final long serialVersionUID = 1L; + + public WasteStack(int _x, int _y) { + super(false); + super.setLocation(_x, _y); + super.setSize(IMAGE_WIDTH, STACK_HIGHT); + super.setOpaque(false); + super.setLayout(null); + } + + @Override + protected boolean cardCheck(Card _topStack, Card _playerCard) { + // TODO Auto-generated method stub + return false; + } + + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + if (stackIsEmpty()) { + g.setColor(Color.lightGray); + g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); + + g.setColor(Color.black); + g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1); + + } + } + +} diff --git a/src/test/java/solitaer/GeberStackTest.java b/src/test/java/solitaer/GeberStackTest.java new file mode 100644 index 0000000..0115389 --- /dev/null +++ b/src/test/java/solitaer/GeberStackTest.java @@ -0,0 +1,25 @@ +package solitaer; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class GeberStackTest { + + @Test + void testswapGeberWaste001() { + WasteStack waste = new WasteStack(0, 0); + GeberStack geber = new GeberStack(0, 0, waste); + + for (int i = 1; i < 14; i++) { + waste.addCard(new Card(0, Symbol.Pik, false)); + } + + int expectedResult = waste.stackSize(); + + geber.swapWasteGeber(); + + assertEquals(geber.stackSize(), expectedResult, "same Size"); + } + +}