commit 8b5481159a63ae3caf7165d224ec65d307d90171 parent 40faa594d78dc3fea55978f5ca90571665eea5aa Author: Michael Neuper <73108749+michaelneuper@users.noreply.github.com> Date: Sat, 8 Oct 2022 09:15:35 +0200 add reloadDeckFromDiscard method Diffstat:
| M | src/model/Deck.java | | | 22 | ++++++++++++++++++++++ |
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/model/Deck.java b/src/model/Deck.java @@ -130,6 +130,28 @@ public class Deck { public void addCards(ArrayList<Card> cards) { deck.addAll(cards); } + + /** + * returns the arraylist containing all the cards in the deck + * + * @return deck arraylist to be returned + */ + public ArrayList<Card> getCards() { + return deck; + } + + /** + * Take all the cards from a discarded deck and place them in this deck, shuffled + * Clear the old deck + * + * @param discard deck cards are coming from + */ + public void reloadDeckFromDiscard(Deck discard) { + this.addCards(discard.getCards()); + this.shuffle(); + discard.emptyDeck(); + System.out.println("Ran out of cards, creating new deck from discard pile & shuffling deck"); + } @Override public String toString() {