//
//  PlayPanel.java
//  cribbage
//
//  Created by Nathan Haug on Sun Apr 25 2004.
//  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class PlayPanel extends JPanel{

	JLabel cards[] = new JLabel[12];
	JLabel scoreCount = new JLabel();
	JPanel cardPanel = new JPanel();
	int playTotal = 0;
	int numCards = 0;

	public PlayPanel(){
		// Define this layout
		FlowLayout mainLayout = new FlowLayout(FlowLayout.LEFT,5,0);
		this.setLayout(mainLayout);
	
		// Define the card layout
		FlowLayout cardLayout = new FlowLayout(FlowLayout.LEFT,5,0);
		cardPanel.setLayout(cardLayout);
		
		// Add the components
		add(cardPanel, "Center");
		add(scoreCount, "South");
	}

public void putCard(Card playedCard) {
		// Add the new card, using our static function getCardGraphic in CardGraphics class
		ImageIcon cardImage = CardGraphics.getCardGraphic(playedCard);
		cards[numCards] = new JLabel(cardImage);
		cards[numCards].setBorder(LineBorder.createBlackLineBorder());
		cardPanel.add( cards[numCards] );
		numCards++;
		
		// Update the count
		if (playedCard.getRank() < 11)
			playTotal += playedCard.getRank();
		else
			playTotal += 10;
			
		scoreCount.setText("Current play total: "+playTotal);
		
		validate();
		repaint();
	}

	public void clearPlay() {
		numCards = 0;
		playTotal = 0;
		JLabel cards[] = new JLabel[12];
		cardPanel.removeAll();
		scoreCount.setText("");
	}
	
	public void setPlayText(String text) {
		scoreCount.setText(text);
	}
}