Card.java
Home Up BelotConstants.java Card.java Cards.java RunInfo.java Player.java Game.java Belot.java

 

 

// -----------------------------------------------------------
//                           Card.java
//                         John Paxton
//                             CS 334
// -----------------------------------------------------------
// This file implements the basic behavior of
// card used in the game of Color Belot.
// -----------------------------------------------------------

class Card implements BelotConstants
{
        // -------------------------------
        // Constructor
        // -------------------------------    
	Card (int s, int r, int v, int sc)
	{
		suit = s;
		rank = r;
		value = v;
		sortCode = sc;
	}   
        // ------------------------------- 
        // comesAfter
        // ------------------------------- 
        // otherCard:  the other card being compared against
        // trump:      the trump suit
        // -------------------------------
        // Returns true if the first card should
        // appear in the sorted hand after "otherCard"
        // ------------------------------- 
	public boolean comesAfter (Card otherCard, int trump)
	{
		if ( (suit == trump) && (otherCard.suit != trump))
			return false;
		else if ( (suit != trump) && (otherCard.suit == trump))
			return true;
		else if ((suit != otherCard.suit) && (suit > otherCard.suit))
			return true;
		else if (suit != otherCard.suit)
			return false;
		else if (otherCard.rank == EIGHT)
			return false;
		else if (rank == EIGHT)
			return true;
		else if ( value < otherCard.value )
			return true;
		else 
			return false;
	}            
        // ------------------------------- 
        // isHigher
        // ------------------------------- 
        // otherCard:  the other card being compared against
        // trump:      the trump suit
        // -------------------------------
        // Returns true if the first card played
        // beats the "otherCard" played.
        // ------------------------------- 
	public boolean isHigher (Card otherCard, int trump)
	{
		if ((suit == trump) && (otherCard.suit != trump))
			return true;
		else if ((suit != trump) && (otherCard.suit == trump))
			return false;
		else if (suit != otherCard.suit)
			return true;
		else if ( value > otherCard.value )
			return true;
		else if (otherCard.rank == EIGHT)
			return true;
		else return false;
	}           
        // -------------------------------
        //  print
        // ------------------------------- 
        //  Prints the rand and suit of the card
        // ------------------------------- 

	public void print ()
	{
		System.out.println(RANK_NAMES[rank] + " " + TRUMP_NAMES[suit] + " " + value);
	}            
        // -------------------------------
        //  updateValue
        // -------------------------------
        //  trump:  the trump suit
        // ------------------------------- 
        //  The 9s and Js change values,
        //  depending on whether they are in
        //  trump or not.
        // ------------------------------- 
	public void updateValue (int trump)
	{
		if (rank == NINE)
		{
			if ((suit == trump) || (trump == EVERYTHING))
				value = NINE_OF_TRUMP_VALUE;
			else
				value = NINE_OF_NONTRUMP_VALUE;
		}
		else if (rank == JACK)
		{
			if ((suit == trump) || (trump == EVERYTHING))
				value = JACK_OF_TRUMP_VALUE;
			else
				value = JACK_OF_NONTRUMP_VALUE;
		}
	}            
        // -------------------------------
        //  Reader Methods
        // ------------------------------- 
	public int getValue()
	{
		return value;
	}    
	public int getSuit ()
	{
		return suit;
	}    
	public int getRank ()
	{
		return rank;
	}    
	public int getSortCode ()
	{
		return sortCode;
	}    
	private int suit;         // denotes suit of the card 
	private int rank;         // denotes rank of the card
	private int value;        // denotes value of card
	private int sortCode;     // used to sort card in hand
}