From 29b2c1db6776a33abc30d581ba495423f01b2bf3 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 17:50:24 +0100 Subject: [PATCH 1/8] Add GeberStack --- src/main/java/solitaer/GeberStack.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/solitaer/GeberStack.java diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java new file mode 100644 index 0000000..2696e62 --- /dev/null +++ b/src/main/java/solitaer/GeberStack.java @@ -0,0 +1,21 @@ +package solitaer; + +public class GeberStack extends BaseStack { + + private static final long serialVersionUID = 1L; + + public GeberStack(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; + } + +} From e5832eac493f85582d3ae3e722b4690c248a4b32 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 17:53:39 +0100 Subject: [PATCH 2/8] Add WasteStack --- src/main/java/solitaer/GeberStack.java | 6 +++++- src/main/java/solitaer/WasteStack.java | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/java/solitaer/WasteStack.java diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java index 2696e62..b3c6e58 100644 --- a/src/main/java/solitaer/GeberStack.java +++ b/src/main/java/solitaer/GeberStack.java @@ -3,13 +3,17 @@ package solitaer; public class GeberStack extends BaseStack { private static final long serialVersionUID = 1L; + + private WasteStack wasteStack; - public GeberStack(int _x, int _y) { + 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; } @Override diff --git a/src/main/java/solitaer/WasteStack.java b/src/main/java/solitaer/WasteStack.java new file mode 100644 index 0000000..554a936 --- /dev/null +++ b/src/main/java/solitaer/WasteStack.java @@ -0,0 +1,21 @@ +package solitaer; + +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; + } + +} From f95187e009424b4fecb31f55a43cc6a72f17d988 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 17:58:22 +0100 Subject: [PATCH 3/8] Add render for GeberStack --- src/main/java/solitaer/GeberStack.java | 19 +++++++++++++++++++ src/main/java/solitaer/SolitaerGamePanel.java | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java index b3c6e58..9e10e10 100644 --- a/src/main/java/solitaer/GeberStack.java +++ b/src/main/java/solitaer/GeberStack.java @@ -1,5 +1,8 @@ package solitaer; +import java.awt.Color; +import java.awt.Graphics; + public class GeberStack extends BaseStack { private static final long serialVersionUID = 1L; @@ -21,5 +24,21 @@ public class GeberStack extends BaseStack { // 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/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 4c16f06..834e22a 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -77,6 +77,13 @@ public class SolitaerGamePanel extends JPanel { this.add(a4); + WasteStack w = new WasteStack(85, 10); + GeberStack g = new GeberStack(10, 10, w); + + this.add(w); + this.add(g); + + } From 698569ba076d98eeadb6894a593b444f6064db59 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 18:00:49 +0100 Subject: [PATCH 4/8] Add render for WasteStack --- src/main/java/solitaer/WasteStack.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/solitaer/WasteStack.java b/src/main/java/solitaer/WasteStack.java index 554a936..c86d360 100644 --- a/src/main/java/solitaer/WasteStack.java +++ b/src/main/java/solitaer/WasteStack.java @@ -1,5 +1,8 @@ package solitaer; +import java.awt.Color; +import java.awt.Graphics; + public class WasteStack extends BaseStack { private static final long serialVersionUID = 1L; @@ -17,5 +20,19 @@ public class WasteStack extends BaseStack { // 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); + + } + } } From f83db6a3f957e407e93ccc34bc4fb41b01645b48 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 18:38:24 +0100 Subject: [PATCH 5/8] Add swapGeberWaste Funktion and Add Test --- src/main/java/solitaer/GeberStack.java | 11 ++++++++++ src/test/java/solitaer/GeberStackTest.java | 25 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/test/java/solitaer/GeberStackTest.java diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java index 9e10e10..1136daa 100644 --- a/src/main/java/solitaer/GeberStack.java +++ b/src/main/java/solitaer/GeberStack.java @@ -19,6 +19,17 @@ public class GeberStack extends BaseStack { this.wasteStack = _waste; } + public WasteStack getWastStack() { + return wasteStack; + } + + public void swapWasteGeber() { + while(wasteStack.stackIsEmpty() == false) { + this.addCard(wasteStack.removeLastCard()); + } + } + + @Override protected boolean cardCheck(Card _topStack, Card _playerCard) { // TODO Auto-generated method stub 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"); + } + +} From ae20cbcbaefab7e9470b1d9946a3cb159c574add Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 21:20:56 +0100 Subject: [PATCH 6/8] Add MousInput GeberStack --- src/main/java/solitaer/GeberStack.java | 4 ++- src/main/java/solitaer/MyMouseListener.java | 25 ++++++++++++++++++- src/main/java/solitaer/SolitaerGamePanel.java | 13 ++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java index 1136daa..a974883 100644 --- a/src/main/java/solitaer/GeberStack.java +++ b/src/main/java/solitaer/GeberStack.java @@ -25,7 +25,9 @@ public class GeberStack extends BaseStack { public void swapWasteGeber() { while(wasteStack.stackIsEmpty() == false) { - this.addCard(wasteStack.removeLastCard()); + Card card = wasteStack.removeLastCard(); + card.setFaceUp(false); + this.addCard(card); } } diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index ee54111..2e227a2 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -105,9 +105,32 @@ public class MyMouseListener implements MouseInputListener { } } + // 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 + tempCard = tempStack.removeLastCard(); + tempCard.setFaceUp(true); + ((GeberStack) this.tempStack).getWastStack() + .addCard(tempCard); + + } + } + + } private void clearSaveStack(BaseStack _ziel) { // Alles wieder auf den Ursprünglichen Stack packen while (!saveStack.stackIsEmpty()) { diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 834e22a..837bf33 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -80,6 +80,19 @@ public class SolitaerGamePanel extends JPanel { 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); From b2be476c381ec84dd50bf186bfb6d68005fc83ea Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 21:28:35 +0100 Subject: [PATCH 7/8] Refactor GeberStack --- src/main/java/solitaer/GeberStack.java | 15 ++++++++++++--- src/main/java/solitaer/MyMouseListener.java | 14 +++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java index a974883..41aa66a 100644 --- a/src/main/java/solitaer/GeberStack.java +++ b/src/main/java/solitaer/GeberStack.java @@ -25,12 +25,21 @@ public class GeberStack extends BaseStack { public void swapWasteGeber() { while(wasteStack.stackIsEmpty() == false) { - Card card = wasteStack.removeLastCard(); - card.setFaceUp(false); - this.addCard(card); + 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) { diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 2e227a2..695a440 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -106,30 +106,22 @@ public class MyMouseListener implements MouseInputListener { } // GeberStack - else if (com.getParent() instanceof GeberStack || com instanceof 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 - tempCard = tempStack.removeLastCard(); - tempCard.setFaceUp(true); - ((GeberStack) this.tempStack).getWastStack() - .addCard(tempCard); - + ((GeberStack) this.tempStack).moveToWaste(); } - } - } private void clearSaveStack(BaseStack _ziel) { // Alles wieder auf den Ursprünglichen Stack packen From 8b93f0414429295fcd4fc0e20a3eb6e1f0cab381 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 21:56:46 +0100 Subject: [PATCH 8/8] Add MouseInput WasteStack --- src/main/java/solitaer/MyMouseListener.java | 26 ++++++++++++++++--- src/main/java/solitaer/SolitaerGamePanel.java | 4 +-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 695a440..4067231 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -99,15 +99,14 @@ public class MyMouseListener implements MouseInputListener { } } else { - //Clear Save + // Clear Save clearSaveStack(selectedStack); } } } // GeberStack - else if (com.getParent() instanceof GeberStack - || com instanceof GeberStack) { + else if (com.getParent() instanceof GeberStack || com instanceof GeberStack) { System.out.println("GeberStack"); if (com instanceof GeberStack) { tempStack = (GeberStack) com; @@ -122,7 +121,28 @@ public class MyMouseListener implements MouseInputListener { ((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) { // Alles wieder auf den Ursprünglichen Stack packen while (!saveStack.stackIsEmpty()) { diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 837bf33..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);