Browse Source

implement CardDeck with 52 Cards

feature_solitaer_001
Alexander Hartung 3 years ago
parent
commit
9346c42223
  1. 28
      src/main/java/solitaer/Card.java
  2. 23
      src/main/java/solitaer/CardDeck.java
  3. 21
      src/test/java/solitaer/CardDeckTest.java

28
src/main/java/solitaer/Card.java

@ -0,0 +1,28 @@
package solitaer;
import javax.swing.JPanel;
enum Symbol {
Herz, Karo, Kreuz, Pik
}
public class Card extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
private int nr;
private Symbol symbol;
private boolean faceUp;
public Card(int nr, Symbol symbol, boolean faceUp) {
this.nr = nr;
this.symbol = symbol;
this.faceUp = faceUp;
}
}

23
src/main/java/solitaer/CardDeck.java

@ -0,0 +1,23 @@
package solitaer;
import java.util.ArrayList;
public class CardDeck {
private ArrayList<Card> deck = new ArrayList<Card>();
public CardDeck() {
for(int i= 0; i<52; i++) {
deck.add(new Card(i, Symbol.Herz, false));
}
}
public ArrayList<Card> getDeck() {
return deck;
}
}

21
src/test/java/solitaer/CardDeckTest.java

@ -0,0 +1,21 @@
package solitaer;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class CardDeckTest {
@Test
void testCardDeckSize() {
CardDeck deck = new CardDeck();
int result = deck.getDeck().size();
assertEquals(52, result, "Kartendeck muss genau 52 Carden haben") ;
}
}
Loading…
Cancel
Save