Browse Source

Fix MouseInput StartStack

feature_solitaer_fix_StartStack
Alexander Hartung 3 years ago
parent
commit
5f6b3bbfff
  1. 58
      src/main/java/solitaer/MyMouseListener.java
  2. 4
      src/main/java/solitaer/SolitaerGamePanel.java

58
src/main/java/solitaer/MyMouseListener.java

@ -30,37 +30,49 @@ public class MyMouseListener implements MouseInputListener {
System.out.println("DOWN"); System.out.println("DOWN");
Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
// 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) {
tempCard = (Card) com;
tempStack = (StartStack) com.getParent();
// // 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())) {
if (saveStack.stackIsEmpty()) { if (saveStack.stackIsEmpty()) {
// Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um
if (!tempCard.isFaceUp()) {
if (tempStack.peekLastCard().equals(tempCard)) {
tempCard.setFaceUp(true);
tempCard.repaint();
}
}
// Card faceUp
else {
// move all Cards below the selected Card to Save
int index = tempStack.indexOfCard(tempCard);
while (tempStack.stackSize() - 1 >= index) {
saveStack.addCard(tempStack.removeLastCard());
if (com instanceof Card && com.getParent() instanceof StartStack) {
tempCard = (Card) com;
tempStack = (StartStack) com.getParent();
// Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um
if (!tempCard.isFaceUp()) {
if (tempStack.peekLastCard().equals(tempCard)) {
tempCard.setFaceUp(true);
tempCard.repaint();
}
} }
selectedStack = tempStack;
// Card faceUp
else {
// move all Cards below the selected Card to Save
int index = tempStack.indexOfCard(tempCard);
while (tempStack.stackSize() - 1 >= index) {
saveStack.addCard(tempStack.removeLastCard());
}
selectedStack = tempStack;
}
} }
} }
// saveStack is NOT empty // saveStack is NOT empty
else { else {
if(com instanceof StartStack) {
tempStack = (StartStack) com;
} else {
tempStack = (StartStack) com.getParent();
}
if (selectedStack == null) { if (selectedStack == null) {
System.out.println("ERROR selectedStack in StartStack"); 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); 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); this.add(c);

Loading…
Cancel
Save