diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-03-25 07:50:26 +0100 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-03-25 07:50:26 +0100 |
commit | f66651cdd6cf6d7449428caae712eeeba8300194 (patch) | |
tree | 37678672ad8c9794791f9a222b8e7ab32a141506 /src/eu/equalparts/cardbase/decks | |
parent | 5878fd7a3d5cbe80b7ead67b1aa75fc55ff06697 (diff) |
Refactoring decks to be more flexible
Diffstat (limited to 'src/eu/equalparts/cardbase/decks')
-rw-r--r-- | src/eu/equalparts/cardbase/decks/Deck.java | 14 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/decks/ReferenceDeck.java | 16 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/decks/StandaloneDeck.java | 8 |
3 files changed, 23 insertions, 15 deletions
diff --git a/src/eu/equalparts/cardbase/decks/Deck.java b/src/eu/equalparts/cardbase/decks/Deck.java index 1f28d60..7a7b819 100644 --- a/src/eu/equalparts/cardbase/decks/Deck.java +++ b/src/eu/equalparts/cardbase/decks/Deck.java @@ -1,12 +1,24 @@ package eu.equalparts.cardbase.decks; -public abstract class Deck { +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +public abstract class Deck { public String name = "Unnamed Deck"; public int plains = 0, islands = 0, swamps = 0, mountains = 0, forests = 0; + + private Map<Integer, Integer> cardReferences = new HashMap<Integer, Integer>(); + + public void addCard(Integer cardHash, Integer count) { + cardReferences.put(cardHash, count); + } + public Map<Integer, Integer> getCardReferences() { + return Collections.unmodifiableMap(cardReferences); + } } diff --git a/src/eu/equalparts/cardbase/decks/ReferenceDeck.java b/src/eu/equalparts/cardbase/decks/ReferenceDeck.java index 2303f24..ab9abf8 100644 --- a/src/eu/equalparts/cardbase/decks/ReferenceDeck.java +++ b/src/eu/equalparts/cardbase/decks/ReferenceDeck.java @@ -1,16 +1,11 @@ package eu.equalparts.cardbase.decks; -import java.util.HashMap; -import java.util.Map; - -import eu.equalparts.cardbase.cards.Card; +import java.util.Map.Entry; public class ReferenceDeck extends Deck { - - public Map<Integer, Integer> cardReferences = new HashMap<Integer, Integer>(); - public ReferenceDeck() { - + public ReferenceDeck(String deckName) { + this.name = deckName; } public ReferenceDeck(StandaloneDeck deck) { @@ -21,9 +16,8 @@ public class ReferenceDeck extends Deck { this.mountains = deck.mountains; this.forests = deck.forests; - // TODO sort this out - for (Card card : deck.cards) { - cardReferences.put(card.hashCode(), 1); + for (Entry<Integer, Integer> entry : deck.getCardReferences().entrySet()) { + getCardReferences().put(entry.getKey(), entry.getValue()); } } diff --git a/src/eu/equalparts/cardbase/decks/StandaloneDeck.java b/src/eu/equalparts/cardbase/decks/StandaloneDeck.java index f015a91..d66311d 100644 --- a/src/eu/equalparts/cardbase/decks/StandaloneDeck.java +++ b/src/eu/equalparts/cardbase/decks/StandaloneDeck.java @@ -1,13 +1,15 @@ package eu.equalparts.cardbase.decks; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import eu.equalparts.cardbase.cards.Card; public class StandaloneDeck extends Deck { + private Map<Integer, Card> cardData = new HashMap<Integer, Card>(); - private Map<Integer, Card> cards = new HashMap<Integer, Card>(); - private Map<Integer, Integer> counts = new HashMap<Integer, Integer>(); - + public Map<Integer, Card> getCardData() { + return Collections.unmodifiableMap(cardData); + } } |