From a0409b6b94e6f5b8c73008b54fd644bae2898e7f Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 16:04:03 +0100 Subject: [PATCH 01/10] Set Layout StartStacks --- src/main/java/solitaer/SolitaerGamePanel.java | 92 +++++++++++-------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 7eaf634..374b937 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -8,10 +8,19 @@ import javax.swing.JPanel; public class SolitaerGamePanel extends JPanel { private static final long serialVersionUID = 1L; + + private final int OFFSET_STACKS = 5; + public final int IMAGE_WIDTH = 72; + public final int IMAGE_HIGHT = 96; + private CardDeck deck; private MyMouseListener mouseL; private SaveStack save =new SaveStack(500,250); + private StartStack[] start = new StartStack[7] ; + + + public SolitaerGamePanel() { @@ -20,48 +29,53 @@ public class SolitaerGamePanel extends JPanel { mouseL = new MyMouseListener(save); this.addMouseListener(mouseL); - deck = new CardDeck(); - - - StartStack a = new StartStack(25,125); - - deck.getDeck().get(5).setFaceUp(true); - a.addCard((deck.getDeck().get(5))); - - deck.getDeck().get(4).setFaceUp(true); - a.addCard((deck.getDeck().get(4))); - - deck.getDeck().get(3).setFaceUp(true); - a.addCard((deck.getDeck().get(3))); - deck.getDeck().get(2).setFaceUp(true); - a.addCard((deck.getDeck().get(2))); - - 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); - - deck.getDeck().get(32).setFaceUp(true); - b.addCard((deck.getDeck().get(32))); - this.add(b); - - StartStack c = new StartStack(375,125); - - //deck.getDeck().get(20).setFaceUp(true); - c.addCard((deck.getDeck().get(20))); - this.add(c); - - - StartStack d = new StartStack(475,125); - this.add(d); + for(int i = 0; i<7; i++) { + int x = (((IMAGE_WIDTH+OFFSET_STACKS)*i)+OFFSET_STACKS); + System.out.println(x); + start[i] = new StartStack(x, 125); + this.add(start[i]); + } + +// StartStack a = new StartStack(25,125); +// +// deck.getDeck().get(5).setFaceUp(true); +// a.addCard((deck.getDeck().get(5))); +// +// deck.getDeck().get(4).setFaceUp(true); +// a.addCard((deck.getDeck().get(4))); +// +// deck.getDeck().get(3).setFaceUp(true); +// a.addCard((deck.getDeck().get(3))); +// +// deck.getDeck().get(2).setFaceUp(true); +// a.addCard((deck.getDeck().get(2))); +// +// 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); +// +// deck.getDeck().get(32).setFaceUp(true); +// b.addCard((deck.getDeck().get(32))); +// this.add(b); +// +// StartStack c = new StartStack(375,125); +// +// //deck.getDeck().get(20).setFaceUp(true); +// c.addCard((deck.getDeck().get(20))); +// this.add(c); +// +// +// StartStack d = new StartStack(475,125); +// this.add(d); //save = new SaveStack(500,250); this.add(save); From d79fd583f551c6faca906d4230b8b2cd0f7cd818 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 16:13:05 +0100 Subject: [PATCH 02/10] Set Layout AblageStacks --- src/main/java/solitaer/SolitaerGamePanel.java | 72 +++++++------------ 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 374b937..7e867a7 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -18,6 +18,7 @@ public class SolitaerGamePanel extends JPanel { private SaveStack save =new SaveStack(500,250); private StartStack[] start = new StartStack[7] ; + private AblageStack[] ablage = new AblageStack[4]; @@ -39,56 +40,33 @@ public class SolitaerGamePanel extends JPanel { this.add(start[i]); } -// StartStack a = new StartStack(25,125); -// -// deck.getDeck().get(5).setFaceUp(true); -// a.addCard((deck.getDeck().get(5))); -// -// deck.getDeck().get(4).setFaceUp(true); -// a.addCard((deck.getDeck().get(4))); -// -// deck.getDeck().get(3).setFaceUp(true); -// a.addCard((deck.getDeck().get(3))); -// -// deck.getDeck().get(2).setFaceUp(true); -// a.addCard((deck.getDeck().get(2))); -// -// 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); -// -// deck.getDeck().get(32).setFaceUp(true); -// b.addCard((deck.getDeck().get(32))); -// this.add(b); -// -// StartStack c = new StartStack(375,125); -// -// //deck.getDeck().get(20).setFaceUp(true); -// c.addCard((deck.getDeck().get(20))); -// this.add(c); -// -// -// StartStack d = new StartStack(475,125); -// this.add(d); + - //save = new SaveStack(500,250); - this.add(save); + for(int i = 0; i<4; i++) { + int x = (((IMAGE_WIDTH+OFFSET_STACKS)*(3+i))+OFFSET_STACKS); + switch (i) { + case 0: + ablage[i] = new AblageStack(x, 10, Symbol.Herz); + break; + case 1: + ablage[i] = new AblageStack(x, 10, Symbol.Kreuz); + break; + case 2: + ablage[i] = new AblageStack(x, 10, Symbol.Karo); + break; + case 3: + ablage[i] = new AblageStack(x, 10, Symbol.Pik); + break; + + default: + break; + } + this.add(ablage[i]); + } - AblageStack a1 = new AblageStack(200, 10, Symbol.Herz); - this.add(a1); - AblageStack a2 = new AblageStack(275, 10, Symbol.Kreuz); - this.add(a2); - AblageStack a3 = new AblageStack(350, 10, Symbol.Karo); - this.add(a3); - AblageStack a4 = new AblageStack(425, 10, Symbol.Pik); - this.add(a4); + //save = new SaveStack(500,250); + this.add(save); WasteStack w = new WasteStack(85, 10); From 8be8a7096b9d9b3a76492a6386488c49b95e4478 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 16:19:21 +0100 Subject: [PATCH 03/10] Set Layout Geber- WasteStack --- src/main/java/solitaer/SolitaerGamePanel.java | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 7e867a7..84454cd 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -9,7 +9,9 @@ public class SolitaerGamePanel extends JPanel { private static final long serialVersionUID = 1L; - private final int OFFSET_STACKS = 5; + private final int OFFSET_STACKS_X = 5; + private final int OFFSET_STACKS_Y = 10; + public final int IMAGE_WIDTH = 72; public final int IMAGE_HIGHT = 96; @@ -20,6 +22,9 @@ public class SolitaerGamePanel extends JPanel { private StartStack[] start = new StartStack[7] ; private AblageStack[] ablage = new AblageStack[4]; + private WasteStack w;// = new WasteStack(85, 10); + private GeberStack g;// = new GeberStack(10, 10, w); + @@ -34,7 +39,7 @@ public class SolitaerGamePanel extends JPanel { for(int i = 0; i<7; i++) { - int x = (((IMAGE_WIDTH+OFFSET_STACKS)*i)+OFFSET_STACKS); + int x = (((IMAGE_WIDTH+OFFSET_STACKS_X)*i)+OFFSET_STACKS_X); System.out.println(x); start[i] = new StartStack(x, 125); this.add(start[i]); @@ -43,19 +48,19 @@ public class SolitaerGamePanel extends JPanel { for(int i = 0; i<4; i++) { - int x = (((IMAGE_WIDTH+OFFSET_STACKS)*(3+i))+OFFSET_STACKS); + int x = (((IMAGE_WIDTH+OFFSET_STACKS_X)*(3+i))+OFFSET_STACKS_X); switch (i) { case 0: - ablage[i] = new AblageStack(x, 10, Symbol.Herz); + ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Herz); break; case 1: - ablage[i] = new AblageStack(x, 10, Symbol.Kreuz); + ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Kreuz); break; case 2: - ablage[i] = new AblageStack(x, 10, Symbol.Karo); + ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Karo); break; case 3: - ablage[i] = new AblageStack(x, 10, Symbol.Pik); + ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Pik); break; default: @@ -69,22 +74,8 @@ public class SolitaerGamePanel extends JPanel { this.add(save); - 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)); - - + w = new WasteStack((IMAGE_WIDTH+(OFFSET_STACKS_X)*2), OFFSET_STACKS_Y); + g = new GeberStack(OFFSET_STACKS_X, OFFSET_STACKS_Y, w); this.add(w); this.add(g); From c5a31c3991a952a682b5f007299c6766d71e4476 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 16:28:19 +0100 Subject: [PATCH 04/10] Set Layout SaveStack --- src/main/java/solitaer/SolitaerGamePanel.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 84454cd..3aa618b 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -1,8 +1,10 @@ package solitaer; import java.awt.Color; +import java.awt.Font; import java.awt.Graphics; +import javax.swing.JLabel; import javax.swing.JPanel; public class SolitaerGamePanel extends JPanel { @@ -18,7 +20,7 @@ public class SolitaerGamePanel extends JPanel { private CardDeck deck; private MyMouseListener mouseL; - private SaveStack save =new SaveStack(500,250); + private SaveStack save;// =new SaveStack(500,250); private StartStack[] start = new StartStack[7] ; private AblageStack[] ablage = new AblageStack[4]; @@ -70,7 +72,13 @@ public class SolitaerGamePanel extends JPanel { } - //save = new SaveStack(500,250); + int Offset_x_Save = (((IMAGE_WIDTH+OFFSET_STACKS_X)*8)+OFFSET_STACKS_X); + JLabel label = new JLabel(); + label.setText("selected Cards"); + label.setBounds(Offset_x_Save, 100, 200,25); + this.add(label); + + save = new SaveStack(Offset_x_Save,125); this.add(save); From d477a4f2e3062579a5782656e54b522dc546f4f3 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 16:45:55 +0100 Subject: [PATCH 05/10] Refactor SolitaerGamePanel --- src/main/java/solitaer/SolitaerGamePanel.java | 97 ++++++++++--------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 3aa618b..2c22ba6 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -10,59 +10,55 @@ import javax.swing.JPanel; public class SolitaerGamePanel extends JPanel { private static final long serialVersionUID = 1L; - + private final int OFFSET_STACKS_X = 5; - private final int OFFSET_STACKS_Y = 10; + private final int OFFSET_STACKS_Y = 15; public final int IMAGE_WIDTH = 72; public final int IMAGE_HIGHT = 96; - + + public final int STARTSTACK_SIZE = 7; + public final int ABLAGESTACK_SIZE = 4; + private CardDeck deck; private MyMouseListener mouseL; - - private SaveStack save;// =new SaveStack(500,250); - private StartStack[] start = new StartStack[7] ; + + private SaveStack save; + private StartStack[] start = new StartStack[7]; private AblageStack[] ablage = new AblageStack[4]; - - private WasteStack w;// = new WasteStack(85, 10); - private GeberStack g;// = new GeberStack(10, 10, w); - - - - - + + private WasteStack waste; + private GeberStack geber; + public SolitaerGamePanel() { setLayout(null); - + mouseL = new MyMouseListener(save); this.addMouseListener(mouseL); - deck = new CardDeck(); - + deck = new CardDeck(); - for(int i = 0; i<7; i++) { - int x = (((IMAGE_WIDTH+OFFSET_STACKS_X)*i)+OFFSET_STACKS_X); - System.out.println(x); - start[i] = new StartStack(x, 125); + for (int i = 0; i < STARTSTACK_SIZE; i++) { + int y = setLayouty(1); + start[i] = new StartStack(setLayoutX(i), y); this.add(start[i]); } - - - - for(int i = 0; i<4; i++) { - int x = (((IMAGE_WIDTH+OFFSET_STACKS_X)*(3+i))+OFFSET_STACKS_X); + + for (int i = 0; i < ABLAGESTACK_SIZE; i++) { + int x = setLayoutX(((STARTSTACK_SIZE - ABLAGESTACK_SIZE) + i)); + int y = setLayouty(0); switch (i) { case 0: - ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Herz); + ablage[i] = new AblageStack(x, y, Symbol.Herz); break; case 1: - ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Kreuz); + ablage[i] = new AblageStack(x, y, Symbol.Kreuz); break; case 2: - ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Karo); + ablage[i] = new AblageStack(x, y, Symbol.Karo); break; case 3: - ablage[i] = new AblageStack(x, OFFSET_STACKS_Y, Symbol.Pik); + ablage[i] = new AblageStack(x, y, Symbol.Pik); break; default: @@ -70,32 +66,41 @@ public class SolitaerGamePanel extends JPanel { } this.add(ablage[i]); } + + int Offset_x_Save = setLayoutX(STARTSTACK_SIZE + 1); + int Offset_y_Save = setLayouty(1); - - int Offset_x_Save = (((IMAGE_WIDTH+OFFSET_STACKS_X)*8)+OFFSET_STACKS_X); JLabel label = new JLabel(); label.setText("selected Cards"); - label.setBounds(Offset_x_Save, 100, 200,25); + label.setBounds(Offset_x_Save, Offset_y_Save - 25, 200, 25); this.add(label); - - save = new SaveStack(Offset_x_Save,125); + + save = new SaveStack(Offset_x_Save, Offset_y_Save); this.add(save); - - - w = new WasteStack((IMAGE_WIDTH+(OFFSET_STACKS_X)*2), OFFSET_STACKS_Y); - g = new GeberStack(OFFSET_STACKS_X, OFFSET_STACKS_Y, w); - this.add(w); - this.add(g); - - + + waste = new WasteStack(setLayoutX(1), OFFSET_STACKS_Y); + geber = new GeberStack(setLayoutX(0), OFFSET_STACKS_Y, waste); + this.add(waste); + this.add(geber); + + } + + private int setLayoutX(int _spalte) { + return (((IMAGE_WIDTH + OFFSET_STACKS_X) * _spalte) + OFFSET_STACKS_X); } - - + + private int setLayouty(int _row) { + if(_row == 1) + return IMAGE_HIGHT + (OFFSET_STACKS_Y * 3); + else + return OFFSET_STACKS_Y; + } + @Override protected void paintComponent(Graphics g) { // TODO Auto-generated method stub super.paintComponent(g); - g.setColor(Color.green); + g.setColor(new Color(0, 135, 62)); g.fillRect(0, 0, this.getWidth(), this.getHeight()); } } From 3576bf037069015f5d98bd87e725aad77c43f71c Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 16:57:15 +0100 Subject: [PATCH 06/10] ADD Cards to StartStacks --- src/main/java/solitaer/SolitaerGamePanel.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 2c22ba6..5d1165f 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -32,17 +32,40 @@ public class SolitaerGamePanel extends JPanel { public SolitaerGamePanel() { setLayout(null); + + + int Offset_x_Save = setLayoutX(STARTSTACK_SIZE + 1); + int Offset_y_Save = setLayouty(1); + + JLabel label = new JLabel(); + label.setText("selected Cards"); + label.setBounds(Offset_x_Save, Offset_y_Save - 25, 200, 25); + this.add(label); + + save = new SaveStack(Offset_x_Save, Offset_y_Save); + this.add(save); + mouseL = new MyMouseListener(save); this.addMouseListener(mouseL); deck = new CardDeck(); + System.out.println(deck.getDeck().size()); for (int i = 0; i < STARTSTACK_SIZE; i++) { int y = setLayouty(1); start[i] = new StartStack(setLayoutX(i), y); + int tmp = i; + while(tmp != 0) { + start[i].addCard(deck.getDeck().remove(0)); + tmp -= 1; + } + Card card = deck.getDeck().remove(0); + card.setFaceUp(true); + start[i].addCard(card); this.add(start[i]); } + System.out.println(deck.getDeck().size()); for (int i = 0; i < ABLAGESTACK_SIZE; i++) { int x = setLayoutX(((STARTSTACK_SIZE - ABLAGESTACK_SIZE) + i)); @@ -67,17 +90,6 @@ public class SolitaerGamePanel extends JPanel { this.add(ablage[i]); } - int Offset_x_Save = setLayoutX(STARTSTACK_SIZE + 1); - int Offset_y_Save = setLayouty(1); - - JLabel label = new JLabel(); - label.setText("selected Cards"); - label.setBounds(Offset_x_Save, Offset_y_Save - 25, 200, 25); - this.add(label); - - save = new SaveStack(Offset_x_Save, Offset_y_Save); - this.add(save); - waste = new WasteStack(setLayoutX(1), OFFSET_STACKS_Y); geber = new GeberStack(setLayoutX(0), OFFSET_STACKS_Y, waste); this.add(waste); From abecb9f8be2acd55af87ca423db6d2fda7eaab28 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 17:02:57 +0100 Subject: [PATCH 07/10] ADD all remaining Cards to GeberStack --- src/main/java/solitaer/SolitaerGamePanel.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 5d1165f..86b40c8 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -33,7 +33,6 @@ public class SolitaerGamePanel extends JPanel { public SolitaerGamePanel() { setLayout(null); - int Offset_x_Save = setLayoutX(STARTSTACK_SIZE + 1); int Offset_y_Save = setLayouty(1); @@ -45,12 +44,10 @@ public class SolitaerGamePanel extends JPanel { save = new SaveStack(Offset_x_Save, Offset_y_Save); this.add(save); - mouseL = new MyMouseListener(save); this.addMouseListener(mouseL); deck = new CardDeck(); - System.out.println(deck.getDeck().size()); for (int i = 0; i < STARTSTACK_SIZE; i++) { int y = setLayouty(1); @@ -65,7 +62,6 @@ public class SolitaerGamePanel extends JPanel { start[i].addCard(card); this.add(start[i]); } - System.out.println(deck.getDeck().size()); for (int i = 0; i < ABLAGESTACK_SIZE; i++) { int x = setLayoutX(((STARTSTACK_SIZE - ABLAGESTACK_SIZE) + i)); @@ -92,6 +88,11 @@ public class SolitaerGamePanel extends JPanel { waste = new WasteStack(setLayoutX(1), OFFSET_STACKS_Y); geber = new GeberStack(setLayoutX(0), OFFSET_STACKS_Y, waste); + + while(deck.getDeck().size() != 0) { + geber.addCard(deck.getDeck().remove(0)); + } + this.add(waste); this.add(geber); From 337594435a88245425e47e1cc5aa5cafa8e76cd4 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 17:11:22 +0100 Subject: [PATCH 08/10] ADD last card to WasteStack --- src/main/java/solitaer/SolitaerGamePanel.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 86b40c8..0edca74 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -89,10 +89,14 @@ public class SolitaerGamePanel extends JPanel { waste = new WasteStack(setLayoutX(1), OFFSET_STACKS_Y); geber = new GeberStack(setLayoutX(0), OFFSET_STACKS_Y, waste); - while(deck.getDeck().size() != 0) { + while(deck.getDeck().size() != 1) { geber.addCard(deck.getDeck().remove(0)); } + Card card = deck.getDeck().remove(0); + card.setFaceUp(true); + waste.addCard(card); + this.add(waste); this.add(geber); From f6a2f009da39d5ed07355eaac95a499cc77d6821 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 21:55:24 +0100 Subject: [PATCH 09/10] Add Shuffel for CardDeck --- src/main/java/solitaer/CardDeck.java | 6 ++++++ src/main/java/solitaer/SolitaerGamePanel.java | 1 + 2 files changed, 7 insertions(+) diff --git a/src/main/java/solitaer/CardDeck.java b/src/main/java/solitaer/CardDeck.java index 41a6518..3b49bdf 100644 --- a/src/main/java/solitaer/CardDeck.java +++ b/src/main/java/solitaer/CardDeck.java @@ -1,6 +1,7 @@ package solitaer; import java.util.ArrayList; +import java.util.Collections; public class CardDeck { @@ -33,4 +34,9 @@ public class CardDeck { return deck; } + + public void shuffelDeck() { + Collections.shuffle(deck); + } + } diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 0edca74..26b1e18 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -48,6 +48,7 @@ public class SolitaerGamePanel extends JPanel { this.addMouseListener(mouseL); deck = new CardDeck(); + deck.shuffelDeck(); for (int i = 0; i < STARTSTACK_SIZE; i++) { int y = setLayouty(1); From 6c2aaeb146d57f157f6b27933c27ca66c487ebfe Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 4 Feb 2022 22:08:17 +0100 Subject: [PATCH 10/10] Fix MouseListener --- src/main/java/solitaer/MyMouseListener.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 70aec81..d222ac6 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -29,14 +29,7 @@ public class MyMouseListener implements MouseInputListener { // TODO Auto-generated method stub 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) || (com instanceof StartStack && ((StartStack) com).stackIsEmpty())) { @@ -152,6 +145,12 @@ public class MyMouseListener implements MouseInputListener { } else { clearSaveStack(selectedStack); } + //Clear SaveStack click on SolitaerGamePanel + }else if(com instanceof SolitaerGamePanel || + com.getParent() instanceof SolitaerGamePanel && com instanceof StartStack ){ + if(saveStack.stackIsEmpty() == false) { + clearSaveStack(selectedStack); + } } }