/*
 * Created on Apr 6, 2005
 *
 */

/**
 * @author Nicole Sullivan
 *
 */
public class PaquetDeCartes extends java.lang.Object{
	//===============================================================
	//  variables d'instance
	//===============================================================
	Carte [] lesCartes;
	int longueur;
	//===============================================================
	//  the constructor
	//===============================================================
	
	public PaquetDeCartes(){
		this.longueur = 0;
		this.lesCartes = new Carte[32];
	}
	//===============================================================
	//  methods
	//===============================================================
	
	//  prendIeme - removes a card from the pack and shifts the remaining cards
	//  down one place.  (also adjusts longeur to match new length)
	//  i: the card to remove
	public Carte prendIeme(int i){
		Carte Card = this.lesCartes[i];
		for (int c = i; c<this.longueur-1; c++){
			this.lesCartes[c] = this.lesCartes[c+1];
		}
		this.longueur--;
		return Card;
	}
	//  ajoute - adds a card to the end of a pack of cards (also adjusts longeur to match new length)
	//  c: the card to add to the pack
	public void ajoute(Carte c){
		this.lesCartes[this.longueur] = c;
		this.longueur++;
	}
	//  affiche -- affiches the contents of a PQDeCartes to the screen	
	public void affiche(){
		for (int i=0; i<this.longueur; i++){
			Terminal.ecrireString("" + this.lesCartes[i].couleur.nom + " " + this.lesCartes[i].figure.nom + ", ");
		}
		Terminal.sautDeLigne();
	}
	//  Checks for the highest card and returns its indice
	//  trump:  color of the trump/atout
	int highestCard(Couleur trump){
		int cardNumber = -1;
		int highest = -1;
		for (int c=0; c<this.longueur; c++){
			if (Arbitre.pointsCarte(this.lesCartes[c], trump) > highest){
				highest = Arbitre.pointsCarte(this.lesCartes[c], trump); 
				cardNumber = c;
			}
		}
		return cardNumber;
	}
	//  Determine if player has a trump
	//  trump: color to check for
	boolean haveTrump(Couleur trump){
		for (int c=0; c<this.longueur; c++){
			if (this.lesCartes[c].couleur.nom == trump.nom){
				return true;
			}
		}return false;
	}
}
