From f66651cdd6cf6d7449428caae712eeeba8300194 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 25 Mar 2016 07:50:26 +0100 Subject: Refactoring decks to be more flexible --- src/eu/equalparts/cardbase/decks/Deck.java | 14 +++++++++++++- src/eu/equalparts/cardbase/decks/ReferenceDeck.java | 16 +++++----------- src/eu/equalparts/cardbase/decks/StandaloneDeck.java | 8 +++++--- 3 files changed, 23 insertions(+), 15 deletions(-) (limited to 'src/eu/equalparts/cardbase/decks') 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 cardReferences = new HashMap(); + + public void addCard(Integer cardHash, Integer count) { + cardReferences.put(cardHash, count); + } + public Map 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 cardReferences = new HashMap(); - 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 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 cardData = new HashMap(); - private Map cards = new HashMap(); - private Map counts = new HashMap(); - + public Map getCardData() { + return Collections.unmodifiableMap(cardData); + } } -- cgit v1.2.3