package lab2;
import javax.swing.*;
/********************************************************************
* Represents a Playing Card:
* Each card has a value (Ace through King) and a suit (spades, clubs, diamonds, hearts)
* Invalid ranks and suits are treated as jokers.
*
* @author Dr. Hughes
*/
public class Card
{
private static String valSymbols = "wa23456789tjqk";
private static String[] valNames = {"Joker","Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
private static String suitSymbols = "wscdh";
private static String[] suitNames = {"Joker","Spades","Clubs","Diamonds","Hearts"};
private int suit;
private int value;
private String imgFileName;
/**
* Creates a card - Invalid cards are treated as Jokers.
* Use this constructor to create an individual card based on characters
*@param v the value of the card - expressed as a character w,a,2,3,4,5,6,7,8,9,t,j,q,k (w = wild)
*@param s the suit of the card - expressed as a character w,s,c,d,h (w = wild)
*/
public Card (char v, char s)
{
suit = suitSymbols.indexOf(s);
value = valSymbols.indexOf(v);
imgFileName = "GPLcards/"+ v+ s+ ".gif";
if((suit == -1)||(value==-1))
{
suit = 0;
value = 0;
imgFileName = "GPLcards/j.gif";
}
}
/**
* Creates a card - Invalid cards are treated as Jokers.
* Use this constructor to create an block of cards using integers from a loop.
*@param v the value of the card - expressed as a character w,a,2,3,4,5,6,7,8,9,t,j,q,k (w = wild)
*@param s the suit of the card - expressed as a character w,s,c,d,h (w = wild)
*/
public Card (int v, int s)
{
char val;
char su;
suit = s;
value = v;
val = valSymbols.charAt(v);
su = suitSymbols.charAt(s);
imgFileName = "GPLcards/"+ val+ su+ ".gif";
System.out.println(imgFileName);
if((suit == 0)||(value==0))
{
imgFileName = "GPLcards/j.gif";
}
}
/**
* Returns a text version of the card.
* @return the text version of the card
*/
public String toString()
{
String theCard = "";
if ((suit==0)||(value==0))
theCard = "Joker";
else
theCard = valNames[value]+suitNames[suit];
return theCard;
}
/**
* Returns a graphic version of the card.
* ImageIcons can be applied to a JLabel
* @return the image version of the card
*/
public ImageIcon getImage()
{
return new ImageIcon(imgFileName);
}
public static ImageIcon getBlankIcon()
{
return new ImageIcon("GPLcards/n.gif");
}
}