Browse Source

Refactor Card and StartStack

feature_solitaer_StartStack
Alexander Hartung 3 years ago
parent
commit
67d9ada932
  1. 10
      src/main/java/solitaer/Card.java
  2. 12
      src/main/java/solitaer/StartStack.java
  3. 9
      src/test/java/solitaer/StartStackTest.java

10
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;
@ -26,8 +23,11 @@ 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 "";
}
}

12
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<Card> stack = new ArrayList<Card>();
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);
}

9
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<Arguments> 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)
);
}
}
Loading…
Cancel
Save