package com.backfire.arithmetic;

/**
 * @Title: Card.java
 * @Package com.backfire.card
 * @Description:
 * @author Potter
 * @date 2013-9-29 下午4:36:02
 * @version V2.0
 * @param <T>
 */
public class Card implements Color, Point, Cloneable {
	/** 牌颜色 **/
	private int color;
	/** 牌点数 **/
	private int point;
	/** 原牌 **/
	private Card originalCard;
	/** 是否癞子 **/
	private boolean isLaiZi; // 确定是否是癞子牌
	/** 是否小癞子 **/
	private boolean isSmallLaizi;
	
	public Card(){
		
	}

	public Card(int color, int point) {
		this.color = color;
		this.point = point;
		this.originalCard = null;
		this.isLaiZi = false;
		this.isSmallLaizi = false;
	}

	public Card(int color, int point,boolean isLaizi) {
		this.color = color;
		this.point = point;
		this.originalCard = null;
		this.isLaiZi = isLaizi;
		this.isSmallLaizi = false;
	}

	public Card(Card other) {
		color = other.getColor();
		point = other.getPoint();
		isLaiZi = other.isLaiZi();
		isSmallLaizi = other.isSmallLaizi();
		originalCard = other.getOriginalCard();
	}
	
	@Override
	public String toString() {
		String flower=(true==isLaiZi?"&":"");
		return "[" + point +flower+ "]";
	}
	
	/*@Override
	public String toString() {
		return "[point=***" + point + "***]";
	}*/

	/**
	 * @param other
	 * @return 0:相等 1:大于 -1:小于
	 */
	public int comparePoint(Card other) {
		if (point == other.getPoint() && color == other.getColor())
			return 0;
		else if (point > other.getPoint())
			return 1;
		else
			return -1;
	}

	/**
	 * 是否相同牌:点数和花色都相同
	 * 
	 * @param other
	 * @return
	 */
	public boolean isEqualTo(Card other) {
		return color == other.getColor() && point == other.getPoint();
	}

	public boolean isSamePoint(Card other) {
		return point == other.getPoint();
	}

	public String description() {
		String colorStr;
		switch (color) {
		case Dimond:
			colorStr = "Dimond ";
			break;
		case Club:
			colorStr = "Club ";
			break;
		case Heart:
			colorStr = "Heart ";
			break;
		case Spade:
			colorStr = "Spade ";
			break;
		default:
			colorStr = "Invalid Color:[%d]" + color;
		}

		String pointStr = null;
		if (point >= Point3 && point < PointJ) {
			pointStr = "" + point;
		} else if (point >= PointJ && point <= PointBigJoker) {
			switch (point) {
			case PointJ:
				pointStr = "J";
				break;
			case PointQ:
				pointStr = "Q";
				break;
			case PointK:
				pointStr = "K";
				break;
			case PointA:
				pointStr = "A";
				break;
			case Point2:
				pointStr = "2";
				break;
			case PointSmallJoker:
				pointStr = "Joker S";
				colorStr = "";// 小鬼不看花色
				break;
			case PointBigJoker:
				pointStr = "Joker B";
				break;
			default:
				break;
			}
		} else {
			pointStr = "Invalid Point:[" + point + "]";
		}
		return colorStr + pointStr;
	}

	public void setSmallLaizi(boolean isSmallLaizi) {
		this.isSmallLaizi = isSmallLaizi;
	}

	public boolean isSmallLaizi() {
		return isSmallLaizi;
	}

	public boolean isFlower() {
		boolean result = false;
		if (point == PointJ || point == PointQ || point == PointK) {
			result = true;
		}
		return result;
	}

	/**
	 * 设置成癞子牌
	 * 
	 * @param bIsLaiZi
	 */
	public void setIsLaiZi(boolean bIsLaiZi) {
		this.isLaiZi = bIsLaiZi;
		originalCard = new Card(color, point);
	}

	public void setIsLaiZi(boolean isLaiZi, Card LaiZiCard) {
		this.isLaiZi = isLaiZi;
		originalCard = new Card(LaiZiCard);
	}

	public boolean isLaiZi() {
		return isLaiZi;
	}

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	public int getPoint() {
		return point;
	}

	public void setPoint(int point) {
		this.point = point;
	}

	public Card getOriginalCard() {
		return originalCard;
	}

	public void setOriginalCard(Card originalCard) {
		this.originalCard = originalCard;
	}

	public void setLaiZi(boolean isLaiZi) {
		this.isLaiZi = isLaiZi;
	}

	public static int getPoint(int idx) {
		int point = PointError;
		switch (idx) {
		case 0:
			point = Point0;
			break;
		case 1:
			point = Point3;
			break;
		case 2:
			point = Point4;
			break;
		case 3:
			point = Point5;
			break;
		case 4:
			point = Point6;
			break;
		case 5:
			point = Point7;
			break;
		case 6:
			point = Point8;
			break;
		case 7:
			point = Point9;
			break;
		case 8:
			point = Point10;
			break;
		case 9:
			point = PointJ;
			break;
		case 10:
			point = PointQ;
			break;
		case 11:
			point = PointK;
			break;
		case 12:
			point = PointA;
			break;
		case 13:
			point = Point2;
			break;
		case 14:
			point = PointSmallJoker;
			break;
		case 15:
			point = PointBigJoker;
			break;
		}
		return point;
	}
	/**
	 * 可以会有问题？Card::Point(point);
	 * @param point
	 * @return
	 */
	public static int changePoint(int point){
		return point;
	}
};

interface Point {
	public static int Point0 = 0;
	public static int Point3 = 3;
	public static int Point4 = 4;
	public static int Point5 = 5;
	public static int Point6 = 6;
	public static int Point7 = 7;
	public static int Point8 = 8;
	public static int Point9 = 9;
	public static int Point10 = 10;
	public static int PointJ = 11;
	public static int PointQ = 12;
	public static int PointK = 13;
	public static int PointA = 14;
	public static int Point2 = 15;
	public static int PointSmallJoker = 16;// @brief 小王
	public static int PointBigJoker = 17; // @brief 大王
	public static int PointError = 11111;

}

interface Color {
	// @brief 方块
	public static int Dimond = 1;
	// @brief 梅花
	public static int Club = 2;
	// @brief 红桃
	public static int Heart = 3;
	// @brief 黑桃
	public static int Spade = 4;
};