From 67d9ada9322950927d06cebb1b6444b48b9527de Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Wed, 26 Jan 2022 21:19:33 +0100 Subject: [PATCH] Refactor Card and StartStack --- src/main/java/solitaer/Card.java | 10 +++++----- src/main/java/solitaer/StartStack.java | 12 +++++++----- src/test/java/solitaer/StartStackTest.java | 9 ++------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 63b1d8e..9eeec05 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -14,9 +14,6 @@ enum Symbol { public class Card extends JPanel { - /** - * - */ private static final long serialVersionUID = 1L; private int nr; private Symbol symbol; @@ -25,9 +22,12 @@ public class Card extends JPanel { private Image Up; private Image back; + + private final int IMAGE_WIDTH = 72; + private final int IMAGE_HIGHT = 96; public Card(int nr, Symbol symbol, boolean faceUp) { - this.setSize(72,96); + this.setSize(IMAGE_WIDTH,IMAGE_HIGHT); this.nr = nr; this.symbol = symbol; this.faceUp = faceUp; @@ -75,7 +75,7 @@ public class Card extends JPanel { case Kreuz: return "Kreuz"; default: - return null; + return ""; } } diff --git a/src/main/java/solitaer/StartStack.java b/src/main/java/solitaer/StartStack.java index 6a001ea..a4bd932 100644 --- a/src/main/java/solitaer/StartStack.java +++ b/src/main/java/solitaer/StartStack.java @@ -12,12 +12,16 @@ public class StartStack extends JPanel { private static final long serialVersionUID = 1L; private Image im; private ArrayList stack = new ArrayList(); + private final int OFFSET_VALUE = 20; + + private final int IMAGE_WIDTH = 72; + private final int IMAGE_HIGHT = 450; private int offset; public StartStack(int _x, int _y) { super.setLocation(_x, _y); - super.setSize(72, 450); + super.setSize(IMAGE_WIDTH, IMAGE_HIGHT); super.setOpaque(false); super.setLayout(null); @@ -51,12 +55,12 @@ public class StartStack extends JPanel { _card.setLocation(0, offset); stack.add(_card); addtoPanel(); - offset += 20; + offset += OFFSET_VALUE; } private void addtoPanel() { - this.removeAll(); + //Alles neu Zeichnen for (int i = stack.size() - 1; i >= 0; i--) { this.add(stack.get(i)); } @@ -67,9 +71,7 @@ public class StartStack extends JPanel { // TODO Auto-generated method stub super.paintComponent(g); if (stack.size() == 0) { - //Arcade64\src\main\java\solitaer\images ImageIcon ii = new ImageIcon(getClass().getResource("images/empty.png")); - //ImageIcon ii = new ImageIcon("C:/Users/Alexander/eclipse-workspace/Arcade64/src/main/java/solitaer/images/empty.png"); im = ii.getImage(); g.drawImage(im, 0, 0, this.getWidth(), 96, this); } diff --git a/src/test/java/solitaer/StartStackTest.java b/src/test/java/solitaer/StartStackTest.java index bf65ff1..e9515e8 100644 --- a/src/test/java/solitaer/StartStackTest.java +++ b/src/test/java/solitaer/StartStackTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.*; import java.util.stream.Stream; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -16,8 +15,6 @@ class StartStackTest { //Jedes Symbol muss einmal vorhand sein void testRulesetStartStack(String msg, Card _stapel, Card _spieler, boolean _expectedResult) { StartStack stack = new StartStack(10, 10); - - assertEquals(_expectedResult, stack.cardCheck(_stapel, _spieler), msg); } @@ -25,7 +22,8 @@ class StartStackTest { private static Stream testStartStackTestDaten(){ return Stream.of( Arguments.of("Ass-Kreuz auf 2-Herz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Kreuz, true), true), - Arguments.of("Ass-Herz auf 2Herz", new Card(1, Symbol.Herz, true), new Card(2, Symbol.Herz, true), false), + Arguments.of("Ass-Herz auf 2-Herz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Herz, true), false), + Arguments.of("Ass-Herz auf 2-Herz", new Card(1, Symbol.Herz, true), new Card(2, Symbol.Herz, true), false), Arguments.of("Ass-Kreuz auf leeres Feld", null, new Card(1, Symbol.Kreuz, true), false), Arguments.of("König auf leeres Feld", null, new Card(13, Symbol.Kreuz, true), true), Arguments.of("5-Pik auf 6-Karo", new Card(6, Symbol.Karo, true), new Card(5, Symbol.Pik, true), true), @@ -33,10 +31,7 @@ class StartStackTest { Arguments.of("5-Karo auf 7-Kreuz", new Card(7, Symbol.Kreuz, true), new Card(5, Symbol.Karo, true), false), Arguments.of("2-Herz auf Ass-Kreuz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Kreuz, true), true), Arguments.of("null auf null", null, null, false) - ); - - } }