Browse Source

Merge commit '3ad5083c354c4999ba1c9b2ae4595f7c2a45d9f3' into HEAD

solitaer_Game
Jenkins 3 years ago
parent
commit
cd2e0ac545
  1. 12
      src/main/java/solitaer/Card.java
  2. 26
      src/main/java/solitaer/MyMouseListener.java
  3. 4
      src/main/java/solitaer/SolitaerGamePanel.java
  4. 19
      src/main/java/solitaer/StartStack.java
  5. 5
      src/test/java/solitaer/StartStackTest.java

12
src/main/java/solitaer/Card.java

@ -40,6 +40,16 @@ public class Card extends JPanel {
return nr;
}
public boolean isred() {
return this.symbol == Symbol.Herz
|| this.symbol == Symbol.Karo;
}
public boolean isblack() {
return this.symbol == Symbol.Kreuz
|| this.symbol == Symbol.Pik;
}
private String getNrText() {
if (this.nr < 10) {
return "0" + this.nr;
@ -107,7 +117,7 @@ public class Card extends JPanel {
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
if (this.symbol == Symbol.Herz || this.symbol == Symbol.Karo)
if (this.isred())
g.setColor(Color.red);
else
g.setColor(Color.black);

26
src/main/java/solitaer/MyMouseListener.java

@ -30,17 +30,22 @@ public class MyMouseListener implements MouseInputListener {
System.out.println("DOWN");
Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
// Leeres StartFeld
if (com instanceof StartStack) {
System.out.println("Leer Start");
// // Leeres StartFeld
// if (com instanceof StartStack) {
// System.out.println("Leer Start");
//
// }
// // Karte, die in einem StartStack liegt
// else
if ((com instanceof Card && com.getParent() instanceof StartStack)
|| (com instanceof StartStack && ((StartStack) com).stackIsEmpty())) {
}
// Karte, die in einem StartStack liegt
else if (com instanceof Card && com.getParent() instanceof StartStack) {
if (saveStack.stackIsEmpty()) {
if (com instanceof Card && com.getParent() instanceof StartStack) {
tempCard = (Card) com;
tempStack = (StartStack) com.getParent();
if (saveStack.stackIsEmpty()) {
// Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um
if (!tempCard.isFaceUp()) {
if (tempStack.peekLastCard().equals(tempCard)) {
@ -59,8 +64,15 @@ public class MyMouseListener implements MouseInputListener {
}
}
}
// saveStack is NOT empty
else {
if(com instanceof StartStack) {
tempStack = (StartStack) com;
} else {
tempStack = (StartStack) com.getParent();
}
if (selectedStack == null) {
System.out.println("ERROR selectedStack in StartStack");
}

4
src/main/java/solitaer/SolitaerGamePanel.java

@ -55,8 +55,8 @@ public class SolitaerGamePanel extends JPanel {
StartStack c = new StartStack(375,125);
deck.getDeck().get(10).setFaceUp(true);
c.addCard((deck.getDeck().get(10)));
//deck.getDeck().get(20).setFaceUp(true);
c.addCard((deck.getDeck().get(20)));
this.add(c);

19
src/main/java/solitaer/StartStack.java

@ -3,7 +3,6 @@ package solitaer;
import java.awt.Color;
import java.awt.Graphics;
public class StartStack extends BaseStack {
private static final long serialVersionUID = 1L;
@ -23,24 +22,18 @@ public class StartStack extends BaseStack {
if (_topStack == null) {
// Nur der König kann auf einen leeren Stapel gelegt werden
return _playerCard.getNr() == 13;
} else if (!_topStack.isFaceUp()) {
return false;
} else {
return (// Nummer nur aufsteigend
_topStack.getNr() == _playerCard.getNr() + 1)
&&
(_topStack.getNr() == _playerCard.getNr() + 1) &&
// rot auf Schwarz
(
((_topStack.getSymbol() == Symbol.Herz || _topStack.getSymbol() == Symbol.Karo)
&& (_playerCard.getSymbol() == Symbol.Pik || _playerCard.getSymbol() == Symbol.Kreuz))
||
((_topStack.isred() && _playerCard.isblack()) ||
// schwarz auf rot
((_topStack.getSymbol() == Symbol.Pik || _topStack.getSymbol() == Symbol.Kreuz)
&& (_playerCard.getSymbol() == Symbol.Herz || _playerCard.getSymbol() == Symbol.Karo))
);
(_topStack.isblack() && _playerCard.isred())));
}
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
@ -54,6 +47,4 @@ public class StartStack extends BaseStack {
}
}
}

5
src/test/java/solitaer/StartStackTest.java

@ -29,8 +29,9 @@ class StartStackTest {
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)
Arguments.of("Ass-Herz auf 2-Kreuz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Kreuz, true), true),
Arguments.of("null auf null", null, null, false),
Arguments.of("Ass-Herz auf face-Down-2-Kreuz", new Card(2, Symbol.Herz, false), new Card(1, Symbol.Kreuz, true), false)
);
}

Loading…
Cancel
Save