// Arup Guha
// 3/3/2017
// Solution to Junior Knights OOP Problem War (CollectionOfCards class)

import java.util.*;

public class CollectionOfCards {

	private ArrayList<Card> myCards;
	private int roundsWon;

	// Creates an empty Collection of Cads.
	public CollectionOfCards() {
		myCards = new ArrayList<Card>();
		roundsWon = 0;
	}

	// Clears out this collection and fills it with all of the cards
	// in the deck.
	public void fillDeck() {

		// Empties out previous contents.
		myCards.clear();

		// Just loop through each possibility of suit and kind, and add it.
		for (int i=0; i<Card.SUITS.length; i++)
			for (int j=0; j<Card.KINDS.length; j++)
				myCards.add(new Card(i, j));
	}

	// Adds c to the end of this collection.
	public void addCard(Card c) {
		myCards.add(c);
	}

	// Removes c from the top of this collection.
	public Card removeFromTop() {
		return myCards.remove(0);
	}

	// Returns a String representation of the collection.
	public String toString() {
		String res = "[";
		for (int i=0; i<myCards.size()-1; i++)
			res = res + myCards.get(i) + ", ";
		res = res + myCards.get(myCards.size()-1) + "]";
		return res;
	}

	// Adds a win of a round to this collection.
	public void wonRound() {
		roundsWon++;
	}

	// Only to be used for the deck, not for players' cards.
	public void shuffle() {
		Collections.shuffle(myCards);
	}

	// Returns the number of cards in this collection.
	public int size() {
		return myCards.size();
	}

	public int numWins() {
		return roundsWon;
	}

	// Returns true iff this player can play.
	public boolean canPlay() {
		return size() > 0;
	}
}