Browse Source

Refactor Card and StartStack

feature_solitaer_fix_StartStack
Alexander Hartung 3 years ago
parent
commit
3ad5083c35
  1. 12
      src/main/java/solitaer/Card.java
  2. 9
      src/main/java/solitaer/StartStack.java

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

@ -39,6 +39,16 @@ public class Card extends JPanel {
public int getNr() { public int getNr() {
return nr; 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() { private String getNrText() {
if (this.nr < 10) { if (this.nr < 10) {
@ -107,7 +117,7 @@ public class Card extends JPanel {
g.setColor(Color.black); g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); 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); g.setColor(Color.red);
else else
g.setColor(Color.black); g.setColor(Color.black);

9
src/main/java/solitaer/StartStack.java

@ -26,14 +26,11 @@ public class StartStack extends BaseStack {
return false; return false;
} else { } else {
return (// Nummer nur aufsteigend return (// Nummer nur aufsteigend
_topStack.getNr() == _playerCard.getNr() + 1) &&
(_topStack.getNr() == _playerCard.getNr() + 1) &&
// rot auf Schwarz // 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 // schwarz auf rot
((_topStack.getSymbol() == Symbol.Pik || _topStack.getSymbol() == Symbol.Kreuz)
&& (_playerCard.getSymbol() == Symbol.Herz
|| _playerCard.getSymbol() == Symbol.Karo)));
(_topStack.isblack() && _playerCard.isred())));
} }
} }

Loading…
Cancel
Save