//Name: TO DO: Fill this comment in
//Date: TO DO: Fill this comment in
//Purpose: TO DO: Fill this comment in
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
public class CardGameApp extends Applet implements ActionListener
{
    //For screens
    Panel p_card;
    Panel card1, card2, card3, card4;
    CardLayout cdLayout = new CardLayout ();

    //game screen
    JButton card;
    JLabel instruct1, instruct2, output;

    //settings screen
    JTextField nameTF1, nameTF2, nameTF3, nameTF4;
    String name1 = "Player 1", name2 = "Player 2",
	name3 = "Player 3", name4 = "Player 4";

    //Formatting
    int screenWidth = 350;
    int screenHeight = 500;
    Color backgroundColour = Color.white;
    Color buttonColour = Color.lightGray;
    Color buttonText = new Color (0, 0, 0);
    Color titleColour = Color.black;
    Font titleFont = new Font ("Arial", Font.PLAIN, 30);
    Font promptFont = new Font ("Arial", Font.PLAIN, 20);
    Dimension boardSquare = new Dimension (80, 80);

    public void init ()
    {
	p_card = new Panel ();
	p_card.setLayout (cdLayout);
	opening ();
	instructions ();
	settings ();
	gameScreen ();
	resize (screenWidth, screenHeight);
	setLayout (new BorderLayout ());
	add ("Center", p_card);
    }


    public void opening ()
    { //TO DO: Fill this comment in
	card1 = new Panel ();
	card1.setBackground (backgroundColour);
	JLabel title = new JLabel ("The Card Game!");
	title.setFont (new Font ("Arial", Font.PLAIN, 30));
	title.setForeground (titleColour);
	JButton next = new JButton ("Enter");
	next.setPreferredSize (new Dimension (screenWidth - 50, 50));
	next.setActionCommand ("2");
	next.addActionListener (this);
	next.setBackground (buttonColour);
	next.setForeground (buttonText);
	card1.add (title);
	card1.add (next);
	p_card.add ("1", card1);
    }


    public void instructions ()
    { //TO DO: Fill this comment in
	card2 = new Panel ();
	card2.setBackground (backgroundColour);
	JLabel title = new JLabel ("The Instructions");
	title.setFont (titleFont);
	title.setForeground (titleColour);
	Panel p = new Panel ();
	JButton settings = new JButton ("Settings");
	settings.setActionCommand ("3");
	settings.addActionListener (this);
	settings.setPreferredSize (new Dimension (150, 50));
	settings.setBackground (buttonColour);
	settings.setForeground (buttonText);
	JButton gameScreen = new JButton ("Game");
	gameScreen.setActionCommand ("4");
	gameScreen.addActionListener (this);
	gameScreen.setPreferredSize (new Dimension (150, 50));
	gameScreen.setBackground (buttonColour);
	gameScreen.setForeground (buttonText);

	card2.add (title);
	p.add (settings);
	p.add (gameScreen);
	card2.add (p);
	p_card.add ("2", card2);
    }


    public void settings ()
    { //TO DO: Fill this comment in
	card3 = new Panel ();
	card3.setBackground (backgroundColour);
	JLabel title = new JLabel ("Choose player names:");
	title.setFont (titleFont);
	title.setForeground (titleColour);
	Panel p = new Panel ();
	JLabel namePmt = new JLabel ("Player 1 name:");
	namePmt.setFont (promptFont);
	nameTF1 = new JTextField (10);
	nameTF1.setFont (promptFont);
	Panel p2 = new Panel ();
	JLabel namePmt2 = new JLabel ("Player 2 name:");
	namePmt2.setFont (promptFont);
	nameTF2 = new JTextField (10);
	nameTF2.setFont (promptFont);
	JLabel namePmt3 = new JLabel ("Player 3 name:");
	namePmt3.setFont (promptFont);
	nameTF3 = new JTextField (10);
	nameTF3.setFont (promptFont);
	JLabel namePmt4 = new JLabel ("Player 4 name:");
	namePmt4.setFont (promptFont);
	nameTF4 = new JTextField (10);
	nameTF4.setFont (promptFont);

	JButton entrance = new JButton ("To the game");
	entrance.setActionCommand ("getNames");
	entrance.addActionListener (this);
	entrance.setPreferredSize (new Dimension (screenWidth - 50, 50));
	entrance.setBackground (buttonColour);
	entrance.setForeground (buttonText);

	JLabel spacer = new JLabel ("");
	spacer.setPreferredSize (new Dimension (screenWidth - 5, 1));
	JLabel spacer2 = new JLabel ("");
	spacer2.setPreferredSize (new Dimension (screenWidth - 5, 1));
	JLabel spacer3 = new JLabel ("");
	spacer2.setPreferredSize (new Dimension (screenWidth - 5, 1));
	JLabel spacer4 = new JLabel ("");
	spacer4.setPreferredSize (new Dimension (screenWidth - 5, 1));
	JLabel spacer5 = new JLabel ("");
	spacer5.setPreferredSize (new Dimension (screenWidth - 5, 1));

	card3.add (title);
	card3.add (spacer);
	card3.add (namePmt);
	card3.add (nameTF1);
	card3.add (spacer2);
	card3.add (namePmt2);
	card3.add (nameTF2);
	card3.add (spacer3);
	card3.add (namePmt3);
	card3.add (nameTF3);
	card3.add (spacer4);
	card3.add (namePmt4);
	card3.add (nameTF4);
	card3.add (spacer5);
	card3.add (entrance);
	p_card.add ("3", card3);
    }


    public void gameScreen ()
    { //TO DO: Fill this comment in
	card4 = new Panel ();
	card4.setBackground (backgroundColour);
	JLabel title = new JLabel ("Card Game");
	title.setFont (titleFont);
	title.setForeground (titleColour);

	JButton card = new JButton (createImageIcon ("blank.png"));
	card.addActionListener (this);
	card.setActionCommand ("pop");
	card.setBorder (null);
	card.setPreferredSize (new Dimension (190, 140));

	//TO DO: Fill this comment in
	JButton reset = new JButton ("Reset");
	reset.addActionListener (this);
	reset.setActionCommand ("reset");
	reset.setPreferredSize (new Dimension (100, 30));
	reset.setBackground (buttonColour);
	reset.setForeground (buttonText);

	JButton instruct = new JButton ("Instructions");
	instruct.addActionListener (this);
	instruct.setActionCommand ("instruct");
	instruct.setPreferredSize (new Dimension (120, 30));
	instruct.setBackground (buttonColour);
	instruct.setForeground (buttonText);

	JButton settings = new JButton ("Settings");
	settings.addActionListener (this);
	settings.setActionCommand ("settings");
	settings.setPreferredSize (new Dimension (100, 30));
	settings.setBackground (buttonColour);
	settings.setForeground (buttonText);

	JLabel spacer = new JLabel ("");
	spacer.setPreferredSize (new Dimension (screenWidth - 5, 1));
	JLabel spacer2 = new JLabel ("");
	spacer2.setPreferredSize (new Dimension (screenWidth - 5, 1));

	card4.add (title);
	card4.add (card);
	card4.add (spacer2);
	card4.add (reset);
	card4.add (instruct);
	card4.add (settings);
	p_card.add ("4", card4);
    }



    public void actionPerformed (ActionEvent e)
    { //TO DO: Fill this comment in
	if (e.getActionCommand ().equals ("1"))
	    cdLayout.show (p_card, "1");
	else if (e.getActionCommand ().equals ("2"))
	    cdLayout.show (p_card, "2");
	else if (e.getActionCommand ().equals ("3"))
	    cdLayout.show (p_card, "3");
	else if (e.getActionCommand ().equals ("4"))
	    cdLayout.show (p_card, "4");

	//TO DO: Fill this comment in
	else if (e.getActionCommand ().equals ("getNames"))
	{
	    cdLayout.show (p_card, "4");
	}
	else if (e.getActionCommand ().equals ("settings"))
	{
	    cdLayout.show (p_card, "3");
	}
	else if (e.getActionCommand ().equals ("instruct"))
	{
	    cdLayout.show (p_card, "2");
	}

	//TO DO: Fill this comment in
	else if (e.getActionCommand ().equals ("reset"))
	{

	}


    } //end AP


    protected static ImageIcon createImageIcon (String path)
    {
	java.net.URL imgURL = CardGameApp.class.getResource (path);
	if (imgURL != null)
	{
	    return new ImageIcon (imgURL);
	}


	else
	{
	    System.err.println ("Couldn't find file: " + path);
	    return null;
	}
    }
}
