Hello all.

I'm a high school student in a beginning Java class. I find programming really interesting but...well, our teacher literally doesn't do a thing other than give us a project to program and say, "go do it." Basically all anybody in the class is due to themselves and collaborating with other students. So my knowledge of Java, especially syntax and the reasons for stuff happening, is spotty at best.

With that in mind, here's where I am right now: I'm trying to program the card game Hearts. Right now what I've got is all four hands being able to play a card in the correct order (all by the user, no AI). All hands must follow the suit of the first unless they don't have that suit, and the player of the highest card (aces are highest) wins the suit. All of that stuff works. But I've been working on the newest prototype assignment for almost two weeks now and I'm clueless as to how to proceed.

Now for this new prototype, I have to add in this stuff:

1. The player holding the 2 of clubs must play first, and must play the 2 of clubs
2. Obtaining a heart by winning a trick scores a point.
3. Obtraining the queen of spades by winning a trick scores 13 points.
4. Hearts cannot be broken on the first trick.
5. Hearts cannot be lead until hearts are broken.
6. After all tricks have been played, the game can be continued or ended.
7. When the game is ended, the player with the fewest points is the winner.

I don't anticipate 2,3,6, or 7 being huge problems. But I'm stuck on 1 right now and can't even figure that out!

Here's my code:

Application Class:
import javax.swing.JFrame;
import java.awt.*;
/**
 * Write a description of class Application here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Application extends JFrame
{
   public static void main( String [] args )
   {
       Application app = new Application();
 
       app.setBounds( 300, 100, 700, 600 );
 
       app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
 
       app.setVisible( true );
 
   }
   public Application()
   {
       super( "GUI Framework" ); //Sets the window title.
 
       AppPanel panel = new AppPanel();
 
       Container c = getContentPane();
       c.add( panel );
   }
}

AppPanel Class:
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.lang.String;
import java.awt.Color;
import java.awt.Point;
import javax.swing.Timer;
/**
 * Write a description of class AppPanel here.
 * 
 * @author Roshan Krishnan 
 * @version (a version number or a date)
 */
public class AppPanel extends JPanel implements MouseListener, ActionListener
{
	// PROPERTIES
	Card [] deck;
	Card [] handOne;
	Card [] handTwo;
	Card [] handThree;
	Card [] handFour;
	private Card tempOne, tempTwo, tempThree, tempFour;
	private Timer timer;
	JButton button;
	JButton clearButton;
	int x = 0;
	int card = 0;
	int counter = 0;
	int wrongSuit = 0;
	String suitWrong = Integer.toString(wrongSuit);
	int round = 0;
	String compare = "";
	boolean followOne;
	boolean followTwo;
	boolean followThree;
	boolean followFour;
 
	// METHODS
	public AppPanel()
	{
		button = new JButton( "Deal" );
		add( button );
		button.addActionListener(this);
		clearButton = new JButton( "Clear" );
		add( clearButton );
		clearButton.addActionListener(this);
		addMouseListener( this );
		clearButton.setVisible(false);
		deck = new Card[52];
		handOne = new Card[13];
		handTwo = new Card[13];
		handThree = new Card[13];
		handFour = new Card[13];
 
		for( int i = 0; i < 52; i++ )
		{
			x = x + 15;
			deck[i] = new Card( x, 100, 72, 100, i );
		}
 
		shuffle();
		bubblesort();
		repaint();
 
	}
	public void paintComponent( Graphics g )
	{
	    super.paintComponent(g);
	    for( int i = 0; i < handOne.length; i++ )
	    {
	    	handOne[i].draw( g );
	    }
	    for( int i = 0; i < handTwo.length; i++ )
	    {
	    	handTwo[i].draw( g );
	    }
	    for( int i = 0; i < handThree.length; i++ )
	    {
	    	handThree[i].draw( g );
	    }
	    for( int i = 0; i < handFour.length; i++ )
	    {
	    	handFour[i].draw( g );
	    }
	}
	public void bubblesort()
	{
		int h = handOne.length;
		for( int pass = 1; pass < h; pass++ )
		{
			for( int i = 0; i < (h - pass); i++ )
			{
				if( handOne[i].getValue() > handOne[i + 1].getValue() )
				{
					Card temp = handOne[i];
					handOne[i] = handOne[i + 1];
					handOne[i + 1] = temp;
				}
			}
		}
		int x = 225;
		for( int i = 0; i < handOne.length; i++ )
		{
			handOne[i].setLocation(  x, 400 );
			x = x + 15;
		}
 
		int h2 = handTwo.length;
		for( int pass = 1; pass < h2; pass++ )
		{
			for( int i = 0; i < (h2 - pass); i++ )
			{
				if( handTwo[i].getValue() > handTwo[i + 1].getValue() )
				{
					Card temp = handTwo[i];
					handTwo[i] = handTwo[i + 1];
					handTwo[i + 1] = temp;
				}
			}
		}
		int x2 = 225;
		for( int i = 0; i < handTwo.length; i++ )
		{
			handTwo[i].setLocation( x2, 100 );
			x2 = x2 + 15;
		}
 
		int h3 = handThree.length;
		for( int pass = 1; pass < h3; pass++ )
		{
			for( int i = 0; i < (h3 - pass); i++ )
			{
				if( handThree[i].getValue() > handThree[i + 1].getValue() )
				{
					Card temp = handThree[i];
					handThree[i] = handThree[i + 1];
					handThree[i + 1] = temp;
				}
			}
		}
		int y3 = 100;
		for( int i = 0; i < handThree.length; i++ )
		{
			handThree[i].setLocation( 50, y3 );
			y3 = y3 + 25;
		}
 
		int h4 = handFour.length;
		for( int pass = 1; pass < h4; pass++ )
		{
			for( int i = 0; i < (h4 - pass); i++ )
			{
				if( handFour[i].getValue() > handFour[i + 1].getValue() )
				{
					Card temp = handFour[i];
					handFour[i] = handFour[i + 1];
					handFour[i + 1] = temp;
				}
			}
		}
		int y4 = 100;
		for( int i = 0; i < handFour.length; i++ )
		{
			handFour[i].setLocation( 550, y4 );
			y4 = y4 + 25;
		}
	}
	public void shuffle ()
	{
	    Card temp;
	    for( int k = 0; k < 1000; k++ )
	    {
	        int i = (int)(Math.random()*52);
	        int j = (int)(Math.random()*52);
	        temp = deck[i];
	        deck[i] = deck[j];
	        deck[j] = temp;
 
	    }
 
	    for( int i = 0; i < 13; i++ )
		{
			int index = i * 4;
			handOne[i] = deck[index];
		}
 
	    for( int i = 0; i < 13; i++ )
		{
			int index = i * 4 + 1;
			handTwo[i] = deck[index];
		}
 
	    for( int i = 0; i < 13; i++ )
		{
			int index = i * 4 + 2;
			handThree[i] = deck[index];
		}
	    for( int i = 0; i < 13; i++ )
		{
			int index = i * 4 + 3;
			handFour[i] = deck[index];
		}
	}
	public void followCards()
	{
 
		followOne = false;
		followTwo = false;
		followThree = false;
		followFour = false;
		for( int i = 0; i < 13; i++ )
		{
			if( handTwo[i].getSuit().equals(compare) && handTwo[i].notDead() )
			{
				followTwo= true;
			}
			if( handFour[i].getSuit().equals(compare) && handFour[i].notDead() )
			{
				followFour = true;
			}
			if( handOne[i].getSuit().equals(compare) && handOne[i].notDead() )
			{
				followOne = true;
			}
			if( handThree[i].getSuit().equals(compare) && handThree[i].notDead() )
			{
				followThree = true;
			}
		}
	}
	public void mouseClicked( MouseEvent e )
	{
 
	}
	public void mouseEntered( MouseEvent e )
	{
 
	}
	public void mouseExited( MouseEvent e )
	{
 
	}
	public void mousePressed( MouseEvent e )
	{
		int getx = e.getX();
		int gety = e.getY();
		int value;
		if (round < 4)
		{
		for( int i = 0; i < 13; i++ )
		{
			if( counter == 0 )
			{
				if( i == clickArea( handTwo ) )
				{
					value = 2;
				}
				else
				{
					value = 1;
				}
				if( handTwo[i].boundsCheck( getx, gety, value ) && handTwo[i].notDead() )
				{
					if( round == 0 )
					{
						compare = handTwo[i].getSuit();
						followCards();
					}
					if( followTwo == false )
					{
						handTwo[i].setLocation( 300, 200 );
						tempTwo = handTwo[i];
						repaint();
						round++;
						tempTwo.setValue(0);
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 1;
						}
					}
					else if( handTwo[i].getSuit().equals(compare) )
					{
						handTwo[i].setLocation( 300, 200 );
						tempTwo = handTwo[i];
						repaint();
						round++;
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 1;
						}
					}
				}	
			}
		}
		for( int i = 0; i < 13; i++ )
		{
			if( counter == 1 )
			{
				if( i == clickArea( handFour ) )
				{
					value = 2;
				}
				else
				{
					value = 0;
				}
				if( handFour[i].boundsCheck( getx, gety, value ) && handFour[i].notDead() )
				{
					if( round == 0 )
					{
						compare = handFour[i].getSuit();
						followCards();
					}
					if( followFour == false )
					{
						handFour[i].setLocation( 375, 250 );
						tempFour = handFour[i];
						repaint();
						round++;
						tempFour.setValue(0);
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 2;
						}
					}
					else if( handFour[i].getSuit().equals(compare) )
					{
						handFour[i].setLocation( 375, 250 );
						tempFour = handFour[i];
						repaint();
						round++;
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 2;
						}
					}
				}
			}
		}
		for( int i = 0; i < 13; i++ )
		{
			if( counter == 2 )
			{
				if( i == clickArea( handOne ) )
				{
					value = 2;
				}
				else
				{
					value = 1;
				}
				if( handOne[i].boundsCheck( getx, gety, value ) && handOne[i].notDead() )
				{
					if( round == 0 )
					{
						compare = handOne[i].getSuit();
						followCards();
					}
					if( followOne == false )
					{
						handOne[i].setLocation( 300, 300 );
						tempOne = handOne[i];
						repaint();
						round++;
						tempOne.setValue(0);
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 3;
						}
					}
					else if( handOne[i].getSuit().equals(compare) )
					{
						handOne[i].setLocation( 300, 300 );
						tempOne = handOne[i];
						repaint();
						round++;
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 3;
						}
					}
				}
			}
		}
		for( int i = 0; i < 13; i++ )
		{
			if( counter == 3 )
			{
				if( i == clickArea( handThree ) )
				{
					value = 2;
				}
				else
				{
					value = 0;
				}
				if( handThree[i].boundsCheck( getx, gety, value ) && handThree[i].notDead() )
				{
					if( round == 0 )
					{
						compare = handThree[i].getSuit();
						followCards();
					}
					if( followThree == false )
					{
						handThree[i].setLocation( 225, 250 );
						tempThree = handThree[i];
						repaint();
						round++;
						tempThree.setValue(0);
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 0;
						}
					}
					else if( handThree[i].getSuit().equals(compare) )
					{
						handThree[i].setLocation( 225, 250 );
						tempThree = handThree[i];
						repaint();
						round++;
						if( round == 4 )
						{
							counter = 4;
						}
						else
						{
							counter = 0;
						}
					}
				}
			}
		}
		}
		if( round == 4 )
		{
			clearButton.setVisible(true);
		}
		System.out.println( "Round: " + round );
		System.out.println( "Counter: " + counter);
	}
	public int clickArea( Card [] Array )
	{
		int value = 0;
		for( int i = 0; i < 13; i++ )
		{
			if( Array[i].notDead() && value < i )
			{
				value = i;
			}
		}
		return value;
	}
	public void mouseReleased( MouseEvent e )
	{
 
	}
	public void actionPerformed(ActionEvent e)
	{
		if( e.getSource() == button )
		{
			for( int i = 0; i < 52; i++ )
			{
				x = x + 15;
				deck[i] = new Card( x, 100, 72, 100, i );
			}
			shuffle();
			bubblesort();
			repaint();
			counter = 0;
		}
		if( e.getSource() == clearButton )
		{
			round = 0;
			tempOne.killCard();
			tempTwo.killCard();
			tempThree.killCard();
			tempFour.killCard();
			bubblesort();
			repaint();
 
			// assumes temp[0] was the first card played during the trick
			/*int winner = 0;
			for(int i = 1; i < 4; i ++)
			{
				if( temp[i].getSuit.equals(compare) )
				{
					if( temp[i].getValue() > temp[winner].getValue() )
					{
						winner = i;
					}
				}
			}*/
 
 
			if( tempTwo.getValue() > tempThree.getValue() && tempTwo.getValue() > tempFour.getValue() && tempTwo.getValue() > tempOne.getValue() )
			{
				counter = 0;
			}
			if( tempFour.getValue() > tempThree.getValue() && tempFour.getValue() > tempTwo.getValue() && tempFour.getValue() > tempOne.getValue() )
			{	
				counter = 1;
			}
			if( tempOne.getValue() > tempThree.getValue() && tempOne.getValue() > tempFour.getValue() && tempOne.getValue() > tempTwo.getValue() )
			{
				counter = 2;
			}
			if( tempThree.getValue() > tempTwo.getValue() && tempThree.getValue() > tempFour.getValue() && tempThree.getValue() > tempOne.getValue() )
			{
				counter = 3;
			}
		}
 
	}
}

Card Class
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Point;
import java.awt.Image;
 
import javax.swing.ImageIcon;
/**
 * Write a description of class Card here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Card
{
    //---PROPERTIES---
    Rectangle bounds;
    Image img;
    String suit = "";;
    int intSuit; 
    int width;
    int c;
    int c2 = 14;
    private boolean visible = true;
    boolean dead = false;
 
    //---METHODS---
    public Card(int x, int y, int width2, int height, int card )
    {
    	width = width2;
    	c = card % 13 + 1;
    	if( card >= 0 && card < 13)
    	{
    		suit = "S";
    		intSuit = 0;
    	}
    	else if( card >= 13 && card < 26 )
    	{
    		suit = "C";
    		intSuit = 1;
    	}
    	else if( card >= 26 && card < 39 )
    	{
    		suit = "H";
    		intSuit = 2;
    	}
    	else if( card >= 39 && card < 52 )
    	{
    		suit = "D";
    		intSuit = 3;
    	}	
    	img = new ImageIcon( "images/" + ( card % 13 + 1) + suit + ".png" ).getImage();
        bounds = new Rectangle( x, y, width, height );     
    }
    public Point getLocation()
    {
        return bounds.getLocation();
    }
    public void setLocation( int x, int y )
    {
        bounds.x = x;
        bounds.y = y;
    }
    public void draw( Graphics g )
    {
    	if( !dead )
    	{
    		if( visible )
    		{
    			g.drawImage( img, bounds.x, bounds.y, null );
    		}
    	}
    }
    public boolean notDead()
    {
    	return !dead;
    }
    public void killCard()
    {
    	dead = true;
    }
    public boolean boundsCheck( int x, int y, int vertical )
    {
    	if(vertical ==  0)
    	{
        if( bounds.x < x && x < bounds.x + bounds.width )
        {
            if( bounds.y < y && y < bounds.y + 25 )
            {
                return true;
            }
        }
    	}
    	else if( vertical == 1)
    	{
    		if( bounds.x < x && x < bounds.x + 15 )
            {
                if( bounds.y < y && y < bounds.y + bounds.height )
                {
                    return true;
                }
            }
    	}
    	else if( vertical == 2 )
    	{
    		if( bounds.x < x && x < bounds.x + bounds.width )
            {
                if( bounds.y < y && y < bounds.y + bounds.height )
                {
                    return true;
                }
            }
    	}
        return false;
    }
	public int getValue() 
	{
		if (c == 1)
		{
			return c2;
		}
		else
		{	
			return c;
		}
	}
	public void setValue(int wrongSuit)
	{
		c = wrongSuit;
		c2 = wrongSuit;
	}
	public String getSuit()
	{
		return suit;
	}
 
}

I realize my code may be counterintuitive and inefficient in some ways but that's just me not knowing the language...I really don't have time to rewrite stuff so unfortunately I'm just going to have to go with what I've written.

Anyway, as far as the 2 of clubs thing goes, what I've been trying to do is add in a method "checkStart" or something that checks the suit and value of each hand, and if the two of clubs is in that hand, the int "counter" switches appropriately to move the turn to that hand. However, that's not really working...I'm not sure where I can call the method where it won't be called every time I click a card or deal, which is what's happening now. Also, I don't know how to, upon switching the counter to the hand with the 2 of clubs, restrict that hand to only be able to play the 2 of clubs.

Sorry if this is in the wrong place or something...chalk it up to being a noob. But I'd appreciate some help!