From 25f30237d28014dbfb8da9b09aecedb72b9120e7 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 21 Jan 2022 14:18:17 +0100 Subject: [PATCH 1/5] init GameWindow --- .gitignore | 22 +++++++++++++++ src/main/java/hauptmenue/GameWindow.java | 27 ++++++++++++++++++ src/main/java/hauptmenue/main.java | 10 +++++++ src/main/java/solitaer/SolitaerGamePanel.java | 28 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 src/main/java/hauptmenue/GameWindow.java create mode 100644 src/main/java/hauptmenue/main.java create mode 100644 src/main/java/solitaer/SolitaerGamePanel.java 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/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()); + } +} From 9346c4222389381a0b320b7d03f6b4b7e7cfc44a Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 21 Jan 2022 16:11:22 +0100 Subject: [PATCH 2/5] implement CardDeck with 52 Cards --- src/main/java/solitaer/Card.java | 28 ++++++++++++++++++++++++ src/main/java/solitaer/CardDeck.java | 23 +++++++++++++++++++ src/test/java/solitaer/CardDeckTest.java | 21 ++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/main/java/solitaer/Card.java create mode 100644 src/main/java/solitaer/CardDeck.java create mode 100644 src/test/java/solitaer/CardDeckTest.java diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java new file mode 100644 index 0000000..38bb04d --- /dev/null +++ b/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; + } + + + +} diff --git a/src/main/java/solitaer/CardDeck.java b/src/main/java/solitaer/CardDeck.java new file mode 100644 index 0000000..522a7fd --- /dev/null +++ b/src/main/java/solitaer/CardDeck.java @@ -0,0 +1,23 @@ +package solitaer; + +import java.util.ArrayList; + +public class CardDeck { + + private ArrayList deck = new ArrayList(); + + + public CardDeck() { + for(int i= 0; i<52; i++) { + deck.add(new Card(i, Symbol.Herz, false)); + } + + } + + + public ArrayList getDeck() { + return deck; + } + + +} diff --git a/src/test/java/solitaer/CardDeckTest.java b/src/test/java/solitaer/CardDeckTest.java new file mode 100644 index 0000000..751c85d --- /dev/null +++ b/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") ; + + } + + + +} From 84fab3b0848014d25da6c569bf0b598160d24d83 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 21 Jan 2022 17:14:36 +0100 Subject: [PATCH 3/5] CardDeck with different Symbole --- src/main/java/solitaer/Card.java | 23 +++++++++++++- src/main/java/solitaer/CardDeck.java | 29 +++++++++++++----- src/test/java/solitaer/CardDeckTest.java | 39 ++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 38bb04d..9fed8b5 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -23,6 +23,27 @@ public class Card extends JPanel { 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 + "]"; + } + - + } diff --git a/src/main/java/solitaer/CardDeck.java b/src/main/java/solitaer/CardDeck.java index 522a7fd..1387542 100644 --- a/src/main/java/solitaer/CardDeck.java +++ b/src/main/java/solitaer/CardDeck.java @@ -3,21 +3,34 @@ package solitaer; import java.util.ArrayList; public class CardDeck { - + private ArrayList deck = new ArrayList(); - - + public CardDeck() { - for(int i= 0; i<52; i++) { - deck.add(new Card(i, Symbol.Herz, false)); + for (int j = 0; j < 4; j++) { + for (int i = 0; i < 13; i++) { + switch (j) { + case 0: + deck.add(new Card(1, Symbol.Herz, false)); + break; + case 1: + deck.add(new Card(1, Symbol.Karo, false)); + break; + case 2: + deck.add(new Card(1, Symbol.Kreuz, false)); + break; + case 3: + deck.add(new Card(1, Symbol.Pik, false)); + break; + } + + } } - - } + } public ArrayList getDeck() { return deck; } - } diff --git a/src/test/java/solitaer/CardDeckTest.java b/src/test/java/solitaer/CardDeckTest.java index 751c85d..448cc87 100644 --- a/src/test/java/solitaer/CardDeckTest.java +++ b/src/test/java/solitaer/CardDeckTest.java @@ -1,21 +1,54 @@ package solitaer; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.verify; + +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() { - CardDeck deck = new CardDeck(); - + void testCardDeckSize() { int result = deck.getDeck().size(); assertEquals(52, result, "Kartendeck muss genau 52 Carden haben") ; } + + + @ParameterizedTest + @MethodSource("testSymbole") + void testCardDeckSymbole(String msg, Symbol _sym) { + + boolean result = false; + + for(int i = 0; i testSymbole(){ + return Stream.of( + Arguments.of("Herz", Symbol.Herz), + Arguments.of("Karo", Symbol.Karo), + Arguments.of("Pik", Symbol.Pik), + Arguments.of("Kreuz",Symbol.Kreuz) + ); + + + } } From 2de3d41bfd1d4a57d6945200794323f34f249d2e Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 21 Jan 2022 17:44:58 +0100 Subject: [PATCH 4/5] CardDeck with 13 Cards of each Symbol --- src/main/java/solitaer/Card.java | 19 +++++++++++++++++ src/main/java/solitaer/CardDeck.java | 10 ++++----- src/test/java/solitaer/CardDeckTest.java | 27 +++++++++++++++++++++++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 9fed8b5..76cc107 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -1,5 +1,7 @@ package solitaer; +import java.util.Objects; + import javax.swing.JPanel; enum Symbol { @@ -44,6 +46,23 @@ public class Card extends JPanel { 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 index 1387542..f5036df 100644 --- a/src/main/java/solitaer/CardDeck.java +++ b/src/main/java/solitaer/CardDeck.java @@ -8,19 +8,19 @@ public class CardDeck { public CardDeck() { for (int j = 0; j < 4; j++) { - for (int i = 0; i < 13; i++) { + for (int i = 1; i <= 13; i++) { switch (j) { case 0: - deck.add(new Card(1, Symbol.Herz, false)); + deck.add(new Card(i, Symbol.Herz, false)); break; case 1: - deck.add(new Card(1, Symbol.Karo, false)); + deck.add(new Card(i, Symbol.Karo, false)); break; case 2: - deck.add(new Card(1, Symbol.Kreuz, false)); + deck.add(new Card(i, Symbol.Kreuz, false)); break; case 3: - deck.add(new Card(1, Symbol.Pik, false)); + deck.add(new Card(i, Symbol.Pik, false)); break; } diff --git a/src/test/java/solitaer/CardDeckTest.java b/src/test/java/solitaer/CardDeckTest.java index 448cc87..daa7371 100644 --- a/src/test/java/solitaer/CardDeckTest.java +++ b/src/test/java/solitaer/CardDeckTest.java @@ -1,7 +1,6 @@ package solitaer; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.verify; import java.util.stream.Stream; @@ -50,5 +49,31 @@ class CardDeckTest { } + + @Test + 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 i =1; i<=13; i++) { + if(deck.getDeck().contains(new Card(i, _sym, false))== false) { + result = false; + break; + } + } + return result; + } + } From a10127d1b227a91831a48e2bbb2c2ef603b71c87 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Wed, 26 Jan 2022 14:36:44 +0100 Subject: [PATCH 5/5] Refactor CardDeck and CardDeckTest --- src/main/java/solitaer/CardDeck.java | 14 +++++++------- src/test/java/solitaer/CardDeckTest.java | 10 ++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/solitaer/CardDeck.java b/src/main/java/solitaer/CardDeck.java index f5036df..41a6518 100644 --- a/src/main/java/solitaer/CardDeck.java +++ b/src/main/java/solitaer/CardDeck.java @@ -7,20 +7,20 @@ public class CardDeck { private ArrayList deck = new ArrayList(); public CardDeck() { - for (int j = 0; j < 4; j++) { - for (int i = 1; i <= 13; i++) { - switch (j) { + 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(i, Symbol.Herz, false)); + deck.add(new Card(nrZähler, Symbol.Herz, false)); break; case 1: - deck.add(new Card(i, Symbol.Karo, false)); + deck.add(new Card(nrZähler, Symbol.Karo, false)); break; case 2: - deck.add(new Card(i, Symbol.Kreuz, false)); + deck.add(new Card(nrZähler, Symbol.Kreuz, false)); break; case 3: - deck.add(new Card(i, Symbol.Pik, false)); + deck.add(new Card(nrZähler, Symbol.Pik, false)); break; } diff --git a/src/test/java/solitaer/CardDeckTest.java b/src/test/java/solitaer/CardDeckTest.java index daa7371..48776f9 100644 --- a/src/test/java/solitaer/CardDeckTest.java +++ b/src/test/java/solitaer/CardDeckTest.java @@ -24,12 +24,13 @@ class CardDeckTest { @ParameterizedTest @MethodSource("testSymbole") + //Jedes Symbol muss einmal vorhand sein void testCardDeckSymbole(String msg, Symbol _sym) { boolean result = false; - for(int i = 0; i