diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 76cc107..1933d7a 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -1,5 +1,7 @@ package solitaer; +import java.awt.Color; +import java.awt.Graphics; import java.util.Objects; import javax.swing.JPanel; @@ -9,17 +11,18 @@ enum Symbol { } public class Card extends JPanel { - - /** - * - */ + private static final long serialVersionUID = 1L; private int nr; private Symbol symbol; - + private boolean faceUp; + + private final int IMAGE_WIDTH = 72; + private final int IMAGE_HIGHT = 96; public Card(int nr, Symbol symbol, boolean faceUp) { + this.setSize(IMAGE_WIDTH,IMAGE_HIGHT); this.nr = nr; this.symbol = symbol; this.faceUp = faceUp; @@ -37,10 +40,33 @@ public class Card extends JPanel { return nr; } + private String getNrText() { + if (this.nr < 10) { + return "0" + this.nr; + } else { + return "" + this.nr; + } + } + public Symbol getSymbol() { return symbol; } + private String getSymboleText() { + switch (this.symbol) { + case Herz: + return "Herz"; + case Karo: + return "Karo"; + case Pik: + return "Pik"; + case Kreuz: + return "Kreuz"; + default: + return ""; + } + } + @Override public String toString() { return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; @@ -63,6 +89,37 @@ public class Card extends JPanel { return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol; } + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + paintCard(g); + + } + + private void paintCard(Graphics g) { + if (faceUp) { + g.setColor(Color.white); + g.fillRect(0, 0, this.getWidth(), this.getHeight()); + + g.setColor(Color.black); + g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); + + if (this.symbol == Symbol.Herz || this.symbol == Symbol.Karo) + g.setColor(Color.red); + else + g.setColor(Color.black); + + String text = "" + this.getNrText() + " " + this.getSymboleText(); + g.drawString(text, 3, 15); + } else { + g.setColor(Color.blue); + g.fillRect(0, 0, this.getWidth(), this.getHeight()); + + g.setColor(Color.black); + g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); + } + } } diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 3fa1888..3577a3a 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -15,6 +15,13 @@ public class SolitaerGamePanel extends JPanel { public SolitaerGamePanel() { setLayout(null); + StartStack a = new StartStack(25,25); + a.addCard(new Card(13, Symbol.Karo, true)); + a.addCard(new Card(1, Symbol.Karo, true)); + this.add(a); + + StartStack b = new StartStack(200,25); + this.add(b); } diff --git a/src/main/java/solitaer/StartStack.java b/src/main/java/solitaer/StartStack.java new file mode 100644 index 0000000..7bc782e --- /dev/null +++ b/src/main/java/solitaer/StartStack.java @@ -0,0 +1,80 @@ +package solitaer; + +import java.awt.Color; +import java.awt.Graphics; +import java.util.ArrayList; + +import javax.swing.JPanel; + +public class StartStack extends JPanel { + + private static final long serialVersionUID = 1L; + 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(IMAGE_WIDTH, IMAGE_HIGHT); + super.setOpaque(false); + super.setLayout(null); + + offset = 0; + } + + public boolean cardCheck(Card _topStack, Card _playerCard) { + if(_topStack == null && _playerCard == null) { + return false; + } + if (_topStack == null) { + // Nur der König kann auf einen leeren Stapel gelegt werden + return _playerCard.getNr() == 13; + }else { + return (// Nummer nur aufsteigend + _topStack.getNr() == _playerCard.getNr() + 1) + && + // rot auf Schwarz + ( + ((_topStack.getSymbol() == Symbol.Herz || _topStack.getSymbol() == Symbol.Karo) + && (_playerCard.getSymbol() == Symbol.Pik || _playerCard.getSymbol() == Symbol.Kreuz)) + || + // schwarz auf rot + ((_topStack.getSymbol() == Symbol.Pik || _topStack.getSymbol() == Symbol.Kreuz) + && (_playerCard.getSymbol() == Symbol.Herz || _playerCard.getSymbol() == Symbol.Karo)) + ); + } + } + + public void addCard(Card _card) { + _card.setLocation(0, offset); + stack.add(_card); + addtoPanel(); + 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)); + } + } + + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + if (stack.size() == 0) { + g.setColor(Color.gray); + g.fillRect(0, 0, this.getWidth(), 96); + + g.setColor(Color.black); + g.drawRect(0, 0, this.getWidth()-1, 96-1); + } + } + +} diff --git a/src/main/java/solitaer/images/01Herz.png b/src/main/java/solitaer/images/01Herz.png new file mode 100644 index 0000000..62d0956 Binary files /dev/null and b/src/main/java/solitaer/images/01Herz.png differ diff --git a/src/main/java/solitaer/images/01Karo.png b/src/main/java/solitaer/images/01Karo.png new file mode 100644 index 0000000..73b0128 Binary files /dev/null and b/src/main/java/solitaer/images/01Karo.png differ diff --git a/src/main/java/solitaer/images/01Kreuz.png b/src/main/java/solitaer/images/01Kreuz.png new file mode 100644 index 0000000..a202c88 Binary files /dev/null and b/src/main/java/solitaer/images/01Kreuz.png differ diff --git a/src/main/java/solitaer/images/01Pik.png b/src/main/java/solitaer/images/01Pik.png new file mode 100644 index 0000000..faa496e Binary files /dev/null and b/src/main/java/solitaer/images/01Pik.png differ diff --git a/src/main/java/solitaer/images/02Herz.png b/src/main/java/solitaer/images/02Herz.png new file mode 100644 index 0000000..559fbbe Binary files /dev/null and b/src/main/java/solitaer/images/02Herz.png differ diff --git a/src/main/java/solitaer/images/02Karo.png b/src/main/java/solitaer/images/02Karo.png new file mode 100644 index 0000000..028c276 Binary files /dev/null and b/src/main/java/solitaer/images/02Karo.png differ diff --git a/src/main/java/solitaer/images/02Kreuz.png b/src/main/java/solitaer/images/02Kreuz.png new file mode 100644 index 0000000..8a0fd46 Binary files /dev/null and b/src/main/java/solitaer/images/02Kreuz.png differ diff --git a/src/main/java/solitaer/images/02Pik.png b/src/main/java/solitaer/images/02Pik.png new file mode 100644 index 0000000..0a1e274 Binary files /dev/null and b/src/main/java/solitaer/images/02Pik.png differ diff --git a/src/main/java/solitaer/images/03Herz.png b/src/main/java/solitaer/images/03Herz.png new file mode 100644 index 0000000..05c7794 Binary files /dev/null and b/src/main/java/solitaer/images/03Herz.png differ diff --git a/src/main/java/solitaer/images/03Karo.png b/src/main/java/solitaer/images/03Karo.png new file mode 100644 index 0000000..da7c45d Binary files /dev/null and b/src/main/java/solitaer/images/03Karo.png differ diff --git a/src/main/java/solitaer/images/03Kreuz.png b/src/main/java/solitaer/images/03Kreuz.png new file mode 100644 index 0000000..aac5c92 Binary files /dev/null and b/src/main/java/solitaer/images/03Kreuz.png differ diff --git a/src/main/java/solitaer/images/03Pik.png b/src/main/java/solitaer/images/03Pik.png new file mode 100644 index 0000000..16ebe5b Binary files /dev/null and b/src/main/java/solitaer/images/03Pik.png differ diff --git a/src/main/java/solitaer/images/04Herz.png b/src/main/java/solitaer/images/04Herz.png new file mode 100644 index 0000000..abf7b19 Binary files /dev/null and b/src/main/java/solitaer/images/04Herz.png differ diff --git a/src/main/java/solitaer/images/04Karo.png b/src/main/java/solitaer/images/04Karo.png new file mode 100644 index 0000000..4c37a84 Binary files /dev/null and b/src/main/java/solitaer/images/04Karo.png differ diff --git a/src/main/java/solitaer/images/04Kreuz.png b/src/main/java/solitaer/images/04Kreuz.png new file mode 100644 index 0000000..acbfba9 Binary files /dev/null and b/src/main/java/solitaer/images/04Kreuz.png differ diff --git a/src/main/java/solitaer/images/04Pik.png b/src/main/java/solitaer/images/04Pik.png new file mode 100644 index 0000000..d33a448 Binary files /dev/null and b/src/main/java/solitaer/images/04Pik.png differ diff --git a/src/main/java/solitaer/images/05Herz.png b/src/main/java/solitaer/images/05Herz.png new file mode 100644 index 0000000..4eaf218 Binary files /dev/null and b/src/main/java/solitaer/images/05Herz.png differ diff --git a/src/main/java/solitaer/images/05Karo.png b/src/main/java/solitaer/images/05Karo.png new file mode 100644 index 0000000..45d75ca Binary files /dev/null and b/src/main/java/solitaer/images/05Karo.png differ diff --git a/src/main/java/solitaer/images/05Kreuz.png b/src/main/java/solitaer/images/05Kreuz.png new file mode 100644 index 0000000..7ab055a Binary files /dev/null and b/src/main/java/solitaer/images/05Kreuz.png differ diff --git a/src/main/java/solitaer/images/05Pik.png b/src/main/java/solitaer/images/05Pik.png new file mode 100644 index 0000000..6bbfab9 Binary files /dev/null and b/src/main/java/solitaer/images/05Pik.png differ diff --git a/src/main/java/solitaer/images/06Herz.png b/src/main/java/solitaer/images/06Herz.png new file mode 100644 index 0000000..04e7477 Binary files /dev/null and b/src/main/java/solitaer/images/06Herz.png differ diff --git a/src/main/java/solitaer/images/06Karo.png b/src/main/java/solitaer/images/06Karo.png new file mode 100644 index 0000000..be2d58a Binary files /dev/null and b/src/main/java/solitaer/images/06Karo.png differ diff --git a/src/main/java/solitaer/images/06Kreuz.png b/src/main/java/solitaer/images/06Kreuz.png new file mode 100644 index 0000000..c79e672 Binary files /dev/null and b/src/main/java/solitaer/images/06Kreuz.png differ diff --git a/src/main/java/solitaer/images/06Pik.png b/src/main/java/solitaer/images/06Pik.png new file mode 100644 index 0000000..35e3403 Binary files /dev/null and b/src/main/java/solitaer/images/06Pik.png differ diff --git a/src/main/java/solitaer/images/07Herz.png b/src/main/java/solitaer/images/07Herz.png new file mode 100644 index 0000000..b16d663 Binary files /dev/null and b/src/main/java/solitaer/images/07Herz.png differ diff --git a/src/main/java/solitaer/images/07Karo.png b/src/main/java/solitaer/images/07Karo.png new file mode 100644 index 0000000..854f4f0 Binary files /dev/null and b/src/main/java/solitaer/images/07Karo.png differ diff --git a/src/main/java/solitaer/images/07Kreuz.png b/src/main/java/solitaer/images/07Kreuz.png new file mode 100644 index 0000000..0cc142d Binary files /dev/null and b/src/main/java/solitaer/images/07Kreuz.png differ diff --git a/src/main/java/solitaer/images/07Pik.png b/src/main/java/solitaer/images/07Pik.png new file mode 100644 index 0000000..9391d2a Binary files /dev/null and b/src/main/java/solitaer/images/07Pik.png differ diff --git a/src/main/java/solitaer/images/08Herz.png b/src/main/java/solitaer/images/08Herz.png new file mode 100644 index 0000000..f95f90c Binary files /dev/null and b/src/main/java/solitaer/images/08Herz.png differ diff --git a/src/main/java/solitaer/images/08Karo.png b/src/main/java/solitaer/images/08Karo.png new file mode 100644 index 0000000..064e234 Binary files /dev/null and b/src/main/java/solitaer/images/08Karo.png differ diff --git a/src/main/java/solitaer/images/08Kreuz.png b/src/main/java/solitaer/images/08Kreuz.png new file mode 100644 index 0000000..3ed11e7 Binary files /dev/null and b/src/main/java/solitaer/images/08Kreuz.png differ diff --git a/src/main/java/solitaer/images/08Pik.png b/src/main/java/solitaer/images/08Pik.png new file mode 100644 index 0000000..6519112 Binary files /dev/null and b/src/main/java/solitaer/images/08Pik.png differ diff --git a/src/main/java/solitaer/images/09Herz.png b/src/main/java/solitaer/images/09Herz.png new file mode 100644 index 0000000..67532fb Binary files /dev/null and b/src/main/java/solitaer/images/09Herz.png differ diff --git a/src/main/java/solitaer/images/09Karo.png b/src/main/java/solitaer/images/09Karo.png new file mode 100644 index 0000000..719aba4 Binary files /dev/null and b/src/main/java/solitaer/images/09Karo.png differ diff --git a/src/main/java/solitaer/images/09Kreuz.png b/src/main/java/solitaer/images/09Kreuz.png new file mode 100644 index 0000000..1838a50 Binary files /dev/null and b/src/main/java/solitaer/images/09Kreuz.png differ diff --git a/src/main/java/solitaer/images/09Pik.png b/src/main/java/solitaer/images/09Pik.png new file mode 100644 index 0000000..9bd7df3 Binary files /dev/null and b/src/main/java/solitaer/images/09Pik.png differ diff --git a/src/main/java/solitaer/images/10Herz.png b/src/main/java/solitaer/images/10Herz.png new file mode 100644 index 0000000..80d7080 Binary files /dev/null and b/src/main/java/solitaer/images/10Herz.png differ diff --git a/src/main/java/solitaer/images/10Karo.png b/src/main/java/solitaer/images/10Karo.png new file mode 100644 index 0000000..2e44348 Binary files /dev/null and b/src/main/java/solitaer/images/10Karo.png differ diff --git a/src/main/java/solitaer/images/10Kreuz.png b/src/main/java/solitaer/images/10Kreuz.png new file mode 100644 index 0000000..7f5e236 Binary files /dev/null and b/src/main/java/solitaer/images/10Kreuz.png differ diff --git a/src/main/java/solitaer/images/10Pik.png b/src/main/java/solitaer/images/10Pik.png new file mode 100644 index 0000000..fa6024a Binary files /dev/null and b/src/main/java/solitaer/images/10Pik.png differ diff --git a/src/main/java/solitaer/images/11Herz.png b/src/main/java/solitaer/images/11Herz.png new file mode 100644 index 0000000..a6efc0f Binary files /dev/null and b/src/main/java/solitaer/images/11Herz.png differ diff --git a/src/main/java/solitaer/images/11Karo.png b/src/main/java/solitaer/images/11Karo.png new file mode 100644 index 0000000..422760b Binary files /dev/null and b/src/main/java/solitaer/images/11Karo.png differ diff --git a/src/main/java/solitaer/images/11Kreuz.png b/src/main/java/solitaer/images/11Kreuz.png new file mode 100644 index 0000000..2000018 Binary files /dev/null and b/src/main/java/solitaer/images/11Kreuz.png differ diff --git a/src/main/java/solitaer/images/11Pik.png b/src/main/java/solitaer/images/11Pik.png new file mode 100644 index 0000000..cb6ed92 Binary files /dev/null and b/src/main/java/solitaer/images/11Pik.png differ diff --git a/src/main/java/solitaer/images/12Herz.png b/src/main/java/solitaer/images/12Herz.png new file mode 100644 index 0000000..cfda346 Binary files /dev/null and b/src/main/java/solitaer/images/12Herz.png differ diff --git a/src/main/java/solitaer/images/12Karo.png b/src/main/java/solitaer/images/12Karo.png new file mode 100644 index 0000000..d9f8a0b Binary files /dev/null and b/src/main/java/solitaer/images/12Karo.png differ diff --git a/src/main/java/solitaer/images/12Kreuz.png b/src/main/java/solitaer/images/12Kreuz.png new file mode 100644 index 0000000..a6356c8 Binary files /dev/null and b/src/main/java/solitaer/images/12Kreuz.png differ diff --git a/src/main/java/solitaer/images/12Pik.png b/src/main/java/solitaer/images/12Pik.png new file mode 100644 index 0000000..c57f94c Binary files /dev/null and b/src/main/java/solitaer/images/12Pik.png differ diff --git a/src/main/java/solitaer/images/13Herz.png b/src/main/java/solitaer/images/13Herz.png new file mode 100644 index 0000000..5362efa Binary files /dev/null and b/src/main/java/solitaer/images/13Herz.png differ diff --git a/src/main/java/solitaer/images/13Karo.png b/src/main/java/solitaer/images/13Karo.png new file mode 100644 index 0000000..7945855 Binary files /dev/null and b/src/main/java/solitaer/images/13Karo.png differ diff --git a/src/main/java/solitaer/images/13Kreuz.png b/src/main/java/solitaer/images/13Kreuz.png new file mode 100644 index 0000000..2765266 Binary files /dev/null and b/src/main/java/solitaer/images/13Kreuz.png differ diff --git a/src/main/java/solitaer/images/13Pik.png b/src/main/java/solitaer/images/13Pik.png new file mode 100644 index 0000000..605141a Binary files /dev/null and b/src/main/java/solitaer/images/13Pik.png differ diff --git a/src/main/java/solitaer/images/back.png b/src/main/java/solitaer/images/back.png new file mode 100644 index 0000000..9457b30 Binary files /dev/null and b/src/main/java/solitaer/images/back.png differ diff --git a/src/main/java/solitaer/images/empty.png b/src/main/java/solitaer/images/empty.png new file mode 100644 index 0000000..f6c6284 Binary files /dev/null and b/src/main/java/solitaer/images/empty.png differ diff --git a/src/test/java/solitaer/StartStackTest.java b/src/test/java/solitaer/StartStackTest.java new file mode 100644 index 0000000..e9515e8 --- /dev/null +++ b/src/test/java/solitaer/StartStackTest.java @@ -0,0 +1,37 @@ +package solitaer; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class StartStackTest { + + @ParameterizedTest + @MethodSource("testStartStackTestDaten") + //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); + } + + + 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 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), + Arguments.of("König-Karo auf Ass-Kreuz", new Card(1, Symbol.Kreuz, true), new Card(13, Symbol.Karo, true), false), + 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) + ); + } + +}