Back to project page ScoponeDaPolso.
The source code is released under:
GNU General Public License
If you think the Android project ScoponeDaPolso listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.gdg.bari.entities; // w w w . j a v a 2 s. c om import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Set; /** * Created by tiziano on 09/11/14. */ public class Deck { private HashMap<Integer, Card> cardMap; //private Set<Card> cardsOnTable; private static final String TAG = Deck.class.getSimpleName(); public List<Card> getPlayerCardList(String playerId){ List<Card> cardList = new ArrayList<Card>(); Set<Integer> cardMapKeySet = cardMap.keySet(); for(int key : cardMapKeySet){ Card card = cardMap.get(key); if(card.getOwner().equals(playerId) && card.getStatus() == Constants.STATUS_IN_HAND){ cardList.add(card); } } return cardList; } public Deck(List<String> players){ cardMap = new HashMap<Integer, Card>(); List<Card> cardList = new ArrayList<Card>(); for(String seed : Constants.SEEDS){ for(int i = 1; i <=10; i++){ cardList.add(new Card(seed, i)); } } Collections.shuffle(cardList); for(int i = 0; i < players.size(); i++){ for(int j = i * 10; j < 10 + (i * 10); j++){ cardList.get(j).setOwner(players.get(i)); cardList.get(j).setStatus(Constants.STATUS_IN_HAND); cardMap.put(cardList.get(j).hashCode(), cardList.get(j)); } } } public HashMap<Integer, Card> getCardMap() { return cardMap; } public void update(Card card){ Card cardToUpd = cardMap.get(card.hashCode()); cardToUpd.setOwner(card.getOwner()); cardToUpd.setStatus(card.getStatus()); } public int getNumberOfCardsOwnedByPlayer(String playerId){ int sum = 0; Set<Integer> cardMapKeyList = cardMap.keySet(); for(Integer cardMapKey: cardMapKeyList){ if(cardMap.get(cardMapKey).getOwner().equals(playerId)) sum++; } return sum; } public int getNumberOfDenariCardsOwnedByPlayer(String playerId){ int sum = 0; Set<Integer> cardMapKeyList = cardMap.keySet(); for(Integer cardMapKey: cardMapKeyList){ Card card = cardMap.get(cardMapKey); if(card.getOwner().equals(playerId) && card.getSeed().equals(Constants.SEED_DENARI)) sum++; } return sum; } }