diff --git a/.gitignore b/.gitignore index 84adb3f..c837958 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,25 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# End of https://www.toptal.com/developers/gitignore/api/maven + diff --git a/src/main/java/hauptmenue/GameWindow.java b/src/main/java/hauptmenue/GameWindow.java new file mode 100644 index 0000000..a2c7479 --- /dev/null +++ b/src/main/java/hauptmenue/GameWindow.java @@ -0,0 +1,27 @@ +package hauptmenue; + +import java.awt.Dimension; + +import javax.swing.JFrame; + +import solitaer.SolitaerGamePanel; + +public class GameWindow extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private final SolitaerGamePanel gamePanel = new SolitaerGamePanel(); + + public GameWindow() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + gamePanel.setPreferredSize(new Dimension(1180, 780)); + + add(gamePanel); + pack(); + + setVisible(true); + } + +} diff --git a/src/main/java/hauptmenue/main.java b/src/main/java/hauptmenue/main.java new file mode 100644 index 0000000..3f53c7f --- /dev/null +++ b/src/main/java/hauptmenue/main.java @@ -0,0 +1,10 @@ +package hauptmenue; + +public class main { + + public static void main(String[] args) { + // TODO Auto-generated method stub + new GameWindow(); + } + +} diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java new file mode 100644 index 0000000..76cc107 --- /dev/null +++ b/src/main/java/solitaer/Card.java @@ -0,0 +1,68 @@ +package solitaer; + +import java.util.Objects; + +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; + } + + public boolean isFaceUp() { + return faceUp; + } + + public void setFaceUp(boolean faceUp) { + this.faceUp = faceUp; + } + + public int getNr() { + return nr; + } + + public Symbol getSymbol() { + return symbol; + } + + @Override + public String toString() { + return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; + } + + @Override + public int hashCode() { + return Objects.hash(faceUp, nr, symbol); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Card other = (Card) obj; + return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol; + } + + + +} diff --git a/src/main/java/solitaer/CardDeck.java b/src/main/java/solitaer/CardDeck.java new file mode 100644 index 0000000..41a6518 --- /dev/null +++ b/src/main/java/solitaer/CardDeck.java @@ -0,0 +1,36 @@ +package solitaer; + +import java.util.ArrayList; + +public class CardDeck { + + private ArrayList deck = new ArrayList(); + + public CardDeck() { + for (int symboleZähler = 0; symboleZähler < 4; symboleZähler++) { + for (int nrZähler = 1; nrZähler <= 13; nrZähler++) { + switch (symboleZähler) { + case 0: + deck.add(new Card(nrZähler, Symbol.Herz, false)); + break; + case 1: + deck.add(new Card(nrZähler, Symbol.Karo, false)); + break; + case 2: + deck.add(new Card(nrZähler, Symbol.Kreuz, false)); + break; + case 3: + deck.add(new Card(nrZähler, Symbol.Pik, false)); + break; + } + + } + } + + } + + public ArrayList getDeck() { + return deck; + } + +} diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java new file mode 100644 index 0000000..3fa1888 --- /dev/null +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -0,0 +1,28 @@ +package solitaer; + +import java.awt.Color; +import java.awt.Graphics; + +import javax.swing.JPanel; + +public class SolitaerGamePanel extends JPanel { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + public SolitaerGamePanel() { + setLayout(null); + } + + + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + g.setColor(Color.green); + g.fillRect(0, 0, this.getWidth(), this.getHeight()); + } +} diff --git a/src/test/java/solitaer/CardDeckTest.java b/src/test/java/solitaer/CardDeckTest.java new file mode 100644 index 0000000..48776f9 --- /dev/null +++ b/src/test/java/solitaer/CardDeckTest.java @@ -0,0 +1,81 @@ +package solitaer; + +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; + +class CardDeckTest { + + private CardDeck deck = new CardDeck(); + + @Test + void testCardDeckSize() { + int result = deck.getDeck().size(); + + assertEquals(52, result, "Kartendeck muss genau 52 Carden haben") ; + + } + + + @ParameterizedTest + @MethodSource("testSymbole") + //Jedes Symbol muss einmal vorhand sein + void testCardDeckSymbole(String msg, Symbol _sym) { + + boolean result = false; + + for(int allCardZähler = 0; allCardZähler testSymbole(){ + return Stream.of( + Arguments.of("Herz", Symbol.Herz), + Arguments.of("Karo", Symbol.Karo), + Arguments.of("Pik", Symbol.Pik), + Arguments.of("Kreuz",Symbol.Kreuz) + ); + + + } + + @Test + //Jedes Symbol muss 13 mal vorrhanden sein + void testCardDeckNumber() { + + boolean result = true; + + result = CheckAllCards(Symbol.Herz) && + CheckAllCards(Symbol.Karo) && + CheckAllCards(Symbol.Kreuz) && + CheckAllCards(Symbol.Pik); + + assertTrue(result); + } + + + private boolean CheckAllCards(Symbol _sym) { + boolean result = true; + for(int nrZähler =1; nrZähler<=13; nrZähler++) { + if(deck.getDeck().contains(new Card(nrZähler, _sym, false))== false) { + result = false; + break; + } + } + return result; + } + + +}