From b2be476c381ec84dd50bf186bfb6d68005fc83ea Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 21:28:35 +0100 Subject: [PATCH] Refactor GeberStack --- src/main/java/solitaer/GeberStack.java | 15 ++++++++++++--- src/main/java/solitaer/MyMouseListener.java | 14 +++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/solitaer/GeberStack.java b/src/main/java/solitaer/GeberStack.java index a974883..41aa66a 100644 --- a/src/main/java/solitaer/GeberStack.java +++ b/src/main/java/solitaer/GeberStack.java @@ -25,12 +25,21 @@ public class GeberStack extends BaseStack { public void swapWasteGeber() { while(wasteStack.stackIsEmpty() == false) { - Card card = wasteStack.removeLastCard(); - card.setFaceUp(false); - this.addCard(card); + 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) { diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 2e227a2..695a440 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -106,30 +106,22 @@ public class MyMouseListener implements MouseInputListener { } // GeberStack - else if (com.getParent() instanceof GeberStack || com instanceof 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 - tempCard = tempStack.removeLastCard(); - tempCard.setFaceUp(true); - ((GeberStack) this.tempStack).getWastStack() - .addCard(tempCard); - + ((GeberStack) this.tempStack).moveToWaste(); } - } - } private void clearSaveStack(BaseStack _ziel) { // Alles wieder auf den Ursprünglichen Stack packen