Jenkins
3 years ago
7 changed files with 187 additions and 24 deletions
-
63src/main/java/solitaer/AblageStack.java
-
12src/main/java/solitaer/BaseStack.java
-
44src/main/java/solitaer/MyMouseListener.java
-
2src/main/java/solitaer/SaveStack.java
-
28src/main/java/solitaer/SolitaerGamePanel.java
-
2src/main/java/solitaer/StartStack.java
-
46src/test/java/solitaer/AblageStackTest.java
@ -0,0 +1,63 @@ |
|||
package solitaer; |
|||
|
|||
import java.awt.Color; |
|||
import java.awt.Font; |
|||
import java.awt.Graphics; |
|||
|
|||
public class AblageStack extends BaseStack { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
private Symbol sym; |
|||
|
|||
public AblageStack(int _x, int _y, Symbol _sym) { |
|||
super(false); |
|||
super.setLocation(_x, _y); |
|||
super.setSize(IMAGE_WIDTH, STACK_HIGHT); |
|||
super.setOpaque(false); |
|||
super.setLayout(null); |
|||
|
|||
this.sym = _sym; |
|||
} |
|||
|
|||
@Override |
|||
protected boolean cardCheck(Card _topStack, Card _playerCard) { |
|||
if(_topStack == null && _playerCard == null) { |
|||
return false; |
|||
} |
|||
if(_playerCard.getSymbol() != this.sym) { |
|||
return false; |
|||
} else if(_topStack == null) { |
|||
//nur ein Ass darf auf einen Leeren Stabel gelegt werden |
|||
return _playerCard.getNr() == 1; |
|||
} else { |
|||
return _topStack.getNr() == _playerCard.getNr() - 1; |
|||
} |
|||
|
|||
} |
|||
|
|||
@Override |
|||
protected void paintComponent(Graphics g) { |
|||
// TODO Auto-generated method stub |
|||
super.paintComponent(g); |
|||
if (stackIsEmpty()) { |
|||
g.setColor(Color.gray); |
|||
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); |
|||
|
|||
g.setColor(Color.black); |
|||
g.drawRect(0, 0, this.getWidth()-1, IMAGE_HIGHT-1); |
|||
|
|||
if (this.sym == Symbol.Herz || this.sym == Symbol.Karo) |
|||
g.setColor(Color.red); |
|||
else |
|||
g.setColor(Color.black); |
|||
|
|||
int fontSize = 20; |
|||
Font f = new Font(Font.MONOSPACED, Font.BOLD, fontSize); |
|||
g.setFont(f); |
|||
|
|||
String text = this.sym.toString(); |
|||
g.drawString(text, 5, this.IMAGE_HIGHT/2); |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
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 AblageStackTest { |
|||
|
|||
@ParameterizedTest |
|||
@MethodSource("testAblageStackTestDaten") |
|||
void testRulesetAblageStack(String msg, Card _stapel, Card _spieler, boolean _expectedResult) { |
|||
AblageStack stack = new AblageStack(0, 0, Symbol.Kreuz); |
|||
assertEquals(_expectedResult, stack.cardCheck(_stapel, _spieler), msg); |
|||
} |
|||
|
|||
private static Stream<Arguments> testAblageStackTestDaten(){ |
|||
return Stream.of( |
|||
Arguments.of("Ass-Kreuz auf Leeres Kreuz-Feld", |
|||
null, |
|||
null, false), |
|||
Arguments.of("Ass-Kreuz auf Leeres Kreuz-Feld", |
|||
null, |
|||
new Card(1, Symbol.Kreuz, true), true), |
|||
Arguments.of("02-Kreuz auf Leeres Kreuz-Feld", |
|||
null, |
|||
new Card(2, Symbol.Kreuz, true), false), |
|||
Arguments.of("Ass-Herz auf Leeres Kreuz-Feld", |
|||
null, |
|||
new Card(1, Symbol.Herz, true), false), |
|||
Arguments.of("05-Kreuz auf 04-Kreuz", |
|||
new Card(4, Symbol.Kreuz, true), |
|||
new Card(5, Symbol.Kreuz, true), true), |
|||
Arguments.of("05-Herz auf 04-Kreuz", |
|||
new Card(4, Symbol.Kreuz, true), |
|||
new Card(5, Symbol.Herz, true), false), |
|||
Arguments.of("Ass-Kreuz auf König-Kreuz", |
|||
new Card(13, Symbol.Kreuz, true), |
|||
new Card(1, Symbol.Kreuz, true), false) |
|||
); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue