Browse Source

Merge commit '8b93f0414429295fcd4fc0e20a3eb6e1f0cab381' into HEAD

solitaer_Game
Jenkins 3 years ago
parent
commit
f53b5d0685
  1. 66
      src/main/java/solitaer/GeberStack.java
  2. 35
      src/main/java/solitaer/MyMouseListener.java
  3. 24
      src/main/java/solitaer/SolitaerGamePanel.java
  4. 38
      src/main/java/solitaer/WasteStack.java
  5. 25
      src/test/java/solitaer/GeberStackTest.java

66
src/main/java/solitaer/GeberStack.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);
}
}
}

35
src/main/java/solitaer/MyMouseListener.java

@ -105,7 +105,42 @@ public class MyMouseListener implements MouseInputListener {
} }
} }
// GeberStack
else if (com.getParent() instanceof GeberStack || com instanceof GeberStack) {
System.out.println("GeberStack");
if (com instanceof GeberStack) {
tempStack = (GeberStack) com;
} else {
tempStack = (GeberStack) com.getParent();
}
if (tempStack.stackIsEmpty()) {
// Move all from Waste to Geber
((GeberStack) this.tempStack).swapWasteGeber();
} else {
// Move next card to Waste
((GeberStack) this.tempStack).moveToWaste();
}
}
// WasteStack
else if (com.getParent() instanceof WasteStack || com instanceof WasteStack) {
System.out.println("WasteStack");
if (com instanceof WasteStack) {
tempStack = (WasteStack) com;
} else {
tempStack = (WasteStack) com.getParent();
}
if (saveStack.stackIsEmpty()) {
// Move Top Card from AblageStack in Save
if (tempStack.stackIsEmpty() == false) {
saveStack.addCard(tempStack.removeLastCard());
selectedStack = tempStack;
}
} else {
clearSaveStack(selectedStack);
}
}
} }
private void clearSaveStack(BaseStack _ziel) { private void clearSaveStack(BaseStack _ziel) {

24
src/main/java/solitaer/SolitaerGamePanel.java

@ -55,8 +55,8 @@ public class SolitaerGamePanel extends JPanel {
StartStack c = new StartStack(375,125); StartStack c = new StartStack(375,125);
deck.getDeck().get(13).setFaceUp(true);
c.addCard((deck.getDeck().get(12)));
deck.getDeck().get(10).setFaceUp(true);
c.addCard((deck.getDeck().get(10)));
this.add(c); this.add(c);
@ -77,6 +77,26 @@ public class SolitaerGamePanel extends JPanel {
this.add(a4); this.add(a4);
WasteStack w = new WasteStack(85, 10);
GeberStack g = new GeberStack(10, 10, w);
deck.getDeck().get(34).setFaceUp(true);
w.addCard(deck.getDeck().get(34));
deck.getDeck().get(35).setFaceUp(true);
w.addCard(deck.getDeck().get(35));
deck.getDeck().get(36).setFaceUp(true);
w.addCard(deck.getDeck().get(36));
deck.getDeck().get(37).setFaceUp(true);
w.addCard(deck.getDeck().get(37));
g.addCard(deck.getDeck().get(38));
this.add(w);
this.add(g);
} }

38
src/main/java/solitaer/WasteStack.java

@ -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);
}
}
}

25
src/test/java/solitaer/GeberStackTest.java

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