Browse Source

Merge commit '7d0878431ed5b959c3fa6887396ac1e8773665ad' into HEAD

feature_solitaer_MouseInput
Jenkins 3 years ago
parent
commit
fe4fac57b0
  1. 63
      src/main/java/solitaer/Card.java
  2. 7
      src/main/java/solitaer/SolitaerGamePanel.java
  3. 80
      src/main/java/solitaer/StartStack.java
  4. BIN
      src/main/java/solitaer/images/01Herz.png
  5. BIN
      src/main/java/solitaer/images/01Karo.png
  6. BIN
      src/main/java/solitaer/images/01Kreuz.png
  7. BIN
      src/main/java/solitaer/images/01Pik.png
  8. BIN
      src/main/java/solitaer/images/02Herz.png
  9. BIN
      src/main/java/solitaer/images/02Karo.png
  10. BIN
      src/main/java/solitaer/images/02Kreuz.png
  11. BIN
      src/main/java/solitaer/images/02Pik.png
  12. BIN
      src/main/java/solitaer/images/03Herz.png
  13. BIN
      src/main/java/solitaer/images/03Karo.png
  14. BIN
      src/main/java/solitaer/images/03Kreuz.png
  15. BIN
      src/main/java/solitaer/images/03Pik.png
  16. BIN
      src/main/java/solitaer/images/04Herz.png
  17. BIN
      src/main/java/solitaer/images/04Karo.png
  18. BIN
      src/main/java/solitaer/images/04Kreuz.png
  19. BIN
      src/main/java/solitaer/images/04Pik.png
  20. BIN
      src/main/java/solitaer/images/05Herz.png
  21. BIN
      src/main/java/solitaer/images/05Karo.png
  22. BIN
      src/main/java/solitaer/images/05Kreuz.png
  23. BIN
      src/main/java/solitaer/images/05Pik.png
  24. BIN
      src/main/java/solitaer/images/06Herz.png
  25. BIN
      src/main/java/solitaer/images/06Karo.png
  26. BIN
      src/main/java/solitaer/images/06Kreuz.png
  27. BIN
      src/main/java/solitaer/images/06Pik.png
  28. BIN
      src/main/java/solitaer/images/07Herz.png
  29. BIN
      src/main/java/solitaer/images/07Karo.png
  30. BIN
      src/main/java/solitaer/images/07Kreuz.png
  31. BIN
      src/main/java/solitaer/images/07Pik.png
  32. BIN
      src/main/java/solitaer/images/08Herz.png
  33. BIN
      src/main/java/solitaer/images/08Karo.png
  34. BIN
      src/main/java/solitaer/images/08Kreuz.png
  35. BIN
      src/main/java/solitaer/images/08Pik.png
  36. BIN
      src/main/java/solitaer/images/09Herz.png
  37. BIN
      src/main/java/solitaer/images/09Karo.png
  38. BIN
      src/main/java/solitaer/images/09Kreuz.png
  39. BIN
      src/main/java/solitaer/images/09Pik.png
  40. BIN
      src/main/java/solitaer/images/10Herz.png
  41. BIN
      src/main/java/solitaer/images/10Karo.png
  42. BIN
      src/main/java/solitaer/images/10Kreuz.png
  43. BIN
      src/main/java/solitaer/images/10Pik.png
  44. BIN
      src/main/java/solitaer/images/11Herz.png
  45. BIN
      src/main/java/solitaer/images/11Karo.png
  46. BIN
      src/main/java/solitaer/images/11Kreuz.png
  47. BIN
      src/main/java/solitaer/images/11Pik.png
  48. BIN
      src/main/java/solitaer/images/12Herz.png
  49. BIN
      src/main/java/solitaer/images/12Karo.png
  50. BIN
      src/main/java/solitaer/images/12Kreuz.png
  51. BIN
      src/main/java/solitaer/images/12Pik.png
  52. BIN
      src/main/java/solitaer/images/13Herz.png
  53. BIN
      src/main/java/solitaer/images/13Karo.png
  54. BIN
      src/main/java/solitaer/images/13Kreuz.png
  55. BIN
      src/main/java/solitaer/images/13Pik.png
  56. BIN
      src/main/java/solitaer/images/back.png
  57. BIN
      src/main/java/solitaer/images/empty.png
  58. 37
      src/test/java/solitaer/StartStackTest.java

63
src/main/java/solitaer/Card.java

@ -1,5 +1,7 @@
package solitaer; package solitaer;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Objects; import java.util.Objects;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -10,16 +12,17 @@ enum Symbol {
public class Card extends JPanel { public class Card extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int nr; private int nr;
private Symbol symbol; private Symbol symbol;
private boolean faceUp; private boolean faceUp;
private final int IMAGE_WIDTH = 72;
private final int IMAGE_HIGHT = 96;
public Card(int nr, Symbol symbol, boolean faceUp) { public Card(int nr, Symbol symbol, boolean faceUp) {
this.setSize(IMAGE_WIDTH,IMAGE_HIGHT);
this.nr = nr; this.nr = nr;
this.symbol = symbol; this.symbol = symbol;
this.faceUp = faceUp; this.faceUp = faceUp;
@ -37,10 +40,33 @@ public class Card extends JPanel {
return nr; return nr;
} }
private String getNrText() {
if (this.nr < 10) {
return "0" + this.nr;
} else {
return "" + this.nr;
}
}
public Symbol getSymbol() { public Symbol getSymbol() {
return symbol; 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 @Override
public String toString() { public String toString() {
return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; 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; 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);
}
}
} }

7
src/main/java/solitaer/SolitaerGamePanel.java

@ -15,6 +15,13 @@ public class SolitaerGamePanel extends JPanel {
public SolitaerGamePanel() { public SolitaerGamePanel() {
setLayout(null); 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);
} }

80
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<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(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);
}
}
}

BIN
src/main/java/solitaer/images/01Herz.png

After

Width: 73  |  Height: 97  |  Size: 523 B

BIN
src/main/java/solitaer/images/01Karo.png

After

Width: 73  |  Height: 97  |  Size: 539 B

BIN
src/main/java/solitaer/images/01Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 564 B

BIN
src/main/java/solitaer/images/01Pik.png

After

Width: 73  |  Height: 97  |  Size: 506 B

BIN
src/main/java/solitaer/images/02Herz.png

After

Width: 73  |  Height: 97  |  Size: 530 B

BIN
src/main/java/solitaer/images/02Karo.png

After

Width: 73  |  Height: 97  |  Size: 546 B

BIN
src/main/java/solitaer/images/02Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 574 B

BIN
src/main/java/solitaer/images/02Pik.png

After

Width: 73  |  Height: 97  |  Size: 517 B

BIN
src/main/java/solitaer/images/03Herz.png

After

Width: 73  |  Height: 97  |  Size: 532 B

BIN
src/main/java/solitaer/images/03Karo.png

After

Width: 73  |  Height: 97  |  Size: 547 B

BIN
src/main/java/solitaer/images/03Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 576 B

BIN
src/main/java/solitaer/images/03Pik.png

After

Width: 73  |  Height: 97  |  Size: 518 B

BIN
src/main/java/solitaer/images/04Herz.png

After

Width: 73  |  Height: 97  |  Size: 530 B

BIN
src/main/java/solitaer/images/04Karo.png

After

Width: 73  |  Height: 97  |  Size: 547 B

BIN
src/main/java/solitaer/images/04Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 574 B

BIN
src/main/java/solitaer/images/04Pik.png

After

Width: 73  |  Height: 97  |  Size: 516 B

BIN
src/main/java/solitaer/images/05Herz.png

After

Width: 73  |  Height: 97  |  Size: 531 B

BIN
src/main/java/solitaer/images/05Karo.png

After

Width: 73  |  Height: 97  |  Size: 548 B

BIN
src/main/java/solitaer/images/05Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 575 B

BIN
src/main/java/solitaer/images/05Pik.png

After

Width: 73  |  Height: 97  |  Size: 519 B

BIN
src/main/java/solitaer/images/06Herz.png

After

Width: 73  |  Height: 97  |  Size: 540 B

BIN
src/main/java/solitaer/images/06Karo.png

After

Width: 73  |  Height: 97  |  Size: 555 B

BIN
src/main/java/solitaer/images/06Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 584 B

BIN
src/main/java/solitaer/images/06Pik.png

After

Width: 73  |  Height: 97  |  Size: 527 B

BIN
src/main/java/solitaer/images/07Herz.png

After

Width: 73  |  Height: 97  |  Size: 525 B

BIN
src/main/java/solitaer/images/07Karo.png

After

Width: 73  |  Height: 97  |  Size: 542 B

BIN
src/main/java/solitaer/images/07Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 567 B

BIN
src/main/java/solitaer/images/07Pik.png

After

Width: 73  |  Height: 97  |  Size: 510 B

BIN
src/main/java/solitaer/images/08Herz.png

After

Width: 73  |  Height: 97  |  Size: 543 B

BIN
src/main/java/solitaer/images/08Karo.png

After

Width: 73  |  Height: 97  |  Size: 557 B

BIN
src/main/java/solitaer/images/08Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 588 B

BIN
src/main/java/solitaer/images/08Pik.png

After

Width: 73  |  Height: 97  |  Size: 530 B

BIN
src/main/java/solitaer/images/09Herz.png

After

Width: 73  |  Height: 97  |  Size: 540 B

BIN
src/main/java/solitaer/images/09Karo.png

After

Width: 73  |  Height: 97  |  Size: 555 B

BIN
src/main/java/solitaer/images/09Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 584 B

BIN
src/main/java/solitaer/images/09Pik.png

After

Width: 73  |  Height: 97  |  Size: 527 B

BIN
src/main/java/solitaer/images/10Herz.png

After

Width: 73  |  Height: 97  |  Size: 523 B

BIN
src/main/java/solitaer/images/10Karo.png

After

Width: 73  |  Height: 97  |  Size: 539 B

BIN
src/main/java/solitaer/images/10Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 563 B

BIN
src/main/java/solitaer/images/10Pik.png

After

Width: 73  |  Height: 97  |  Size: 507 B

BIN
src/main/java/solitaer/images/11Herz.png

After

Width: 73  |  Height: 97  |  Size: 499 B

BIN
src/main/java/solitaer/images/11Karo.png

After

Width: 73  |  Height: 97  |  Size: 518 B

BIN
src/main/java/solitaer/images/11Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 540 B

BIN
src/main/java/solitaer/images/11Pik.png

After

Width: 73  |  Height: 97  |  Size: 483 B

BIN
src/main/java/solitaer/images/12Herz.png

After

Width: 73  |  Height: 97  |  Size: 509 B

BIN
src/main/java/solitaer/images/12Karo.png

After

Width: 73  |  Height: 97  |  Size: 525 B

BIN
src/main/java/solitaer/images/12Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 552 B

BIN
src/main/java/solitaer/images/12Pik.png

After

Width: 73  |  Height: 97  |  Size: 494 B

BIN
src/main/java/solitaer/images/13Herz.png

After

Width: 73  |  Height: 97  |  Size: 511 B

BIN
src/main/java/solitaer/images/13Karo.png

After

Width: 73  |  Height: 97  |  Size: 527 B

BIN
src/main/java/solitaer/images/13Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 554 B

BIN
src/main/java/solitaer/images/13Pik.png

After

Width: 73  |  Height: 97  |  Size: 495 B

BIN
src/main/java/solitaer/images/back.png

After

Width: 73  |  Height: 97  |  Size: 1.3 KiB

BIN
src/main/java/solitaer/images/empty.png

After

Width: 73  |  Height: 97  |  Size: 6.9 KiB

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