From 65c85aacf057439f34322c352d7a0b126f711b9e Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 12 Nov 2024 22:34:46 +0100 Subject: [PATCH] started UC-gameplay-15 --- .../java/pp/monopoly/model/card/Card.java | 23 +++++++++++++ .../pp/monopoly/model/card/DeckHelper.java | 34 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/Card.java create mode 100644 Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/Card.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/Card.java new file mode 100644 index 0000000..95e07d1 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/Card.java @@ -0,0 +1,23 @@ +package pp.monopoly.model.card; + +public class Card { + private final String description; + private final String keyword; + + Card(String description, String keyword) { + this.description = description; + this.keyword = keyword; + } + + public void accept(DeckHelper visitor) { + visitor.visit(this); + } + + String getDescription() { + return description; + } + + String getKeyword() { + return keyword; + } +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java new file mode 100644 index 0000000..a270fd6 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java @@ -0,0 +1,34 @@ +package pp.monopoly.model.card; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Queue; + +import pp.monopoly.model.CardVisitor; + +public class DeckHelper implements CardVisitor{ + + private static Queue cards; + + private DeckHelper() { + + } + + @Override + public Void visit(Card c) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'visit'"); + } + + private void shuffle() { + List cardList = new ArrayList<>(cards); + Collections.shuffle(cardList); + cards.clear(); + cards.addAll(cardList); + } + + public static Card drawCard() { + return cards != null ? cards.poll() : null; + } +}