Jenkins
3 years ago
5 changed files with 187 additions and 3 deletions
-
66src/main/java/solitaer/GeberStack.java
-
35src/main/java/solitaer/MyMouseListener.java
-
24src/main/java/solitaer/SolitaerGamePanel.java
-
38src/main/java/solitaer/WasteStack.java
-
25src/test/java/solitaer/GeberStackTest.java
@ -0,0 +1,66 @@ |
|||||
|
package solitaer; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import java.awt.Graphics; |
||||
|
|
||||
|
public class GeberStack extends BaseStack { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
private WasteStack wasteStack; |
||||
|
|
||||
|
public GeberStack(int _x, int _y, WasteStack _waste) { |
||||
|
super(false); |
||||
|
super.setLocation(_x, _y); |
||||
|
super.setSize(IMAGE_WIDTH, STACK_HIGHT); |
||||
|
super.setOpaque(false); |
||||
|
super.setLayout(null); |
||||
|
|
||||
|
this.wasteStack = _waste; |
||||
|
} |
||||
|
|
||||
|
public WasteStack getWastStack() { |
||||
|
return wasteStack; |
||||
|
} |
||||
|
|
||||
|
public void swapWasteGeber() { |
||||
|
while(wasteStack.stackIsEmpty() == false) { |
||||
|
moveCardTurnFace(wasteStack, this, false); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void moveToWaste() { |
||||
|
moveCardTurnFace(this, wasteStack, true); |
||||
|
} |
||||
|
|
||||
|
private void moveCardTurnFace(BaseStack _removeStack, BaseStack _addStack, boolean _face) { |
||||
|
Card card = _removeStack.removeLastCard(); |
||||
|
card.setFaceUp(_face); |
||||
|
_addStack.addCard(card); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
protected boolean cardCheck(Card _topStack, Card _playerCard) { |
||||
|
// TODO Auto-generated method stub |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void paintComponent(Graphics g) { |
||||
|
// TODO Auto-generated method stub |
||||
|
super.paintComponent(g); |
||||
|
if (stackIsEmpty()) { |
||||
|
g.setColor(Color.pink); |
||||
|
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); |
||||
|
|
||||
|
g.setColor(Color.black); |
||||
|
g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1); |
||||
|
|
||||
|
String text = "Start\nAgain"; |
||||
|
g.drawString(text, 5, this.IMAGE_HIGHT/2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
package solitaer; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import java.awt.Graphics; |
||||
|
|
||||
|
public class WasteStack extends BaseStack { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
public WasteStack(int _x, int _y) { |
||||
|
super(false); |
||||
|
super.setLocation(_x, _y); |
||||
|
super.setSize(IMAGE_WIDTH, STACK_HIGHT); |
||||
|
super.setOpaque(false); |
||||
|
super.setLayout(null); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected boolean cardCheck(Card _topStack, Card _playerCard) { |
||||
|
// TODO Auto-generated method stub |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void paintComponent(Graphics g) { |
||||
|
// TODO Auto-generated method stub |
||||
|
super.paintComponent(g); |
||||
|
if (stackIsEmpty()) { |
||||
|
g.setColor(Color.lightGray); |
||||
|
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); |
||||
|
|
||||
|
g.setColor(Color.black); |
||||
|
g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
package solitaer; |
||||
|
|
||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||
|
|
||||
|
import org.junit.jupiter.api.Test; |
||||
|
|
||||
|
class GeberStackTest { |
||||
|
|
||||
|
@Test |
||||
|
void testswapGeberWaste001() { |
||||
|
WasteStack waste = new WasteStack(0, 0); |
||||
|
GeberStack geber = new GeberStack(0, 0, waste); |
||||
|
|
||||
|
for (int i = 1; i < 14; i++) { |
||||
|
waste.addCard(new Card(0, Symbol.Pik, false)); |
||||
|
} |
||||
|
|
||||
|
int expectedResult = waste.stackSize(); |
||||
|
|
||||
|
geber.swapWasteGeber(); |
||||
|
|
||||
|
assertEquals(geber.stackSize(), expectedResult, "same Size"); |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue