package oving5.card; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.ArrayList; public class Hand implements Iterable{ private List pairsList = new ArrayList(); private Card[] hand; private Card[] tempHand; private int cardCount; private int handPoints = 0; public Hand(Card[] cards) { tempHand = cards; copyHand(); cardCount = hand.length; } public Iterator iterator() { return Arrays.asList(hand).listIterator(); } public void copyHand() { hand = new Card[tempHand.length]; for(int i = 0; i < tempHand.length; i++) { Card card = tempHand[i]; hand[i] = card; } } public int getPoints() { return handPoints; } public Card getCard(int pos) { return hand[pos]; } public int getCardCount() { return cardCount; } public void sort() { Collections.sort(Arrays.asList(hand)); } public Card getHighestCard() { int highest = 0; int highestIndex = 0; for(int i = 0; i < hand.length; i++) { if(hand[i].face == 1) { handPoints += 14; return hand[i]; } else if(hand[i].face > highest) { highest = hand[i].face; highestIndex = i; } else if(hand[i].face == highest) { if(hand[i].suitValue < hand[highestIndex].suitValue) { highestIndex = i; } } } handPoints += highest; return hand[highestIndex]; } public List getPair() { for(int i = 0; i < getCardCount(); i++) { for(int j = i; j < getCardCount(); j++) { if(i != j) { if(hand[i].getFace() == hand[j].getFace()) { pairsList.add(hand[i]); handPoints += 20; if(hand[i].getFace() == 1) { handPoints += 14; } else { handPoints += hand[i].getFace(); } } } } } return pairsList; } public boolean hasPair() { if(getPair().size() > 0) { return true; } return false; } public Card highestPair() { List cards = getPair(); Card card; int highest = 0; int highestIndex = 0; for(int i = 0; i < cards.size(); i++) { if(cards.get(i).getFace() > highest) { highest = cards.get(i).getFace(); highestIndex = i; } } return card = cards.get(highestIndex); } }