/**
*Programme cree par The Clusters
*Classe principale en GUI du jeu "Chkoba"
*@author The Clusters
*@version 1.0
**/

package chkoba;

import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import chkoba.*;

/**
*	Classe Index
*/

public class Index extends JFrame implements ActionListener 
{
	private Image image;
	private RoundButton boutonCreer, boutonJoindre, boutonStatistiques, boutonConfiguration, boutonAffichage, boutonQuitter;
	private Graphics g;
		
	public Index() 
	{
		try
		{
			File config=new File("config.txt");
			if ( ! config.exists() )
			{
				PrintWriter configTxt = new PrintWriter( new FileWriter("config.txt"),true );
				configTxt.println("Gregory\tGeorge\tSebastien\tJulie\t2");
				configTxt.close();
			}
			
			File stat = new File("stat.txt");
			if ( ! stat.exists() )
			{
				PrintWriter statTxt = new PrintWriter( new FileWriter("stat.txt"),true );
				statTxt.println("0\t0\t0\t0\t0\t0\t0\t0\t0");
				statTxt.close();
			}
			
			File affiche=new File("affichage.txt");
			if ( ! affiche.exists() )
			{
				PrintWriter afficheTxt = new PrintWriter( new FileWriter("affichage.txt"),true );
				afficheTxt.println("4");
				afficheTxt.close();
			}
		}		
		catch ( IOException io)
		{
			System.out.println("Creation des fichiers config.txt et affichage.txt");
		}
		
		setTitle("Menu");
		setLocation(50,100);
		setLayout(null);
		setResizable(false);
		setSize(800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setIconImage(Toolkit.getDefaultToolkit().getImage(Index.class.getResource("./icone.png")));
		
		AfficherCarte af = new AfficherCarte("./Skin/index copie.png");
		add(af);
		
		repaint();
		
		ImageIcon ic = new ImageIcon("./Skin/BouttonIndex/New.png");
		boutonCreer = new RoundButton("boutonCreer");
		boutonCreer.setSize(84,72);
		boutonCreer.setIcon(ic);
		boutonCreer.contains(75,75);
		boutonCreer.setLocation(512,33);
		boutonCreer.addActionListener(this);
		add(boutonCreer);
		
		ImageIcon ic1 = new ImageIcon("./Skin/BouttonIndex/jeSaisPasQuoi.png");
		boutonJoindre = new RoundButton("boutonCreer");
		boutonJoindre.setSize(84,72);
		boutonJoindre.setIcon(ic1);
		boutonJoindre.contains(75,75);
		boutonJoindre.setLocation(512,124);
		boutonJoindre.addActionListener(this);
		add(boutonJoindre);
		
		ImageIcon ic2 = new ImageIcon("./Skin/BouttonIndex/jeSaisPasQuoi2.png");
		boutonStatistiques = new RoundButton("boutonCreer");
		boutonStatistiques.setSize(84,72);
		boutonStatistiques.setIcon(ic2);
		boutonStatistiques.contains(75,75);
		boutonStatistiques.setLocation(512,215);
		boutonStatistiques.addActionListener(this);
		add(boutonStatistiques);
		
		ImageIcon ic3 = new ImageIcon("./Skin/BouttonIndex/difficult.png");
		boutonConfiguration = new RoundButton("boutonCreer");
		boutonConfiguration.setSize(84,72);
		boutonConfiguration.setIcon(ic3);
		boutonConfiguration.contains(75,75);
		boutonConfiguration.setLocation(512,306);
		boutonConfiguration.addActionListener(this);
		add(boutonConfiguration);
		
		ImageIcon ic4 = new ImageIcon("./Skin/BouttonIndex/carte.png");
		boutonAffichage = new RoundButton("boutonCreer");
		boutonAffichage.setSize(84,72);
		boutonAffichage.setIcon(ic4);
		boutonAffichage.contains(75,75);
		boutonAffichage.setLocation(512,397);
		boutonAffichage.addActionListener(this);
		add(boutonAffichage);
		
		ImageIcon ic5 = new ImageIcon("./Skin/BouttonIndex/quitter.png");
		boutonQuitter = new RoundButton("boutonCreer");
		boutonQuitter.setSize(84,72);
		boutonQuitter.setIcon(ic5);
		boutonQuitter.contains(75,75);
		boutonQuitter.setLocation(512,488);
		boutonQuitter.addActionListener(this);
		add(boutonQuitter);
		
		setVisible(true);

	}
	
	public void actionPerformed(ActionEvent e)
	{
		if (e.getSource() == boutonJoindre)
		{	
			setVisible(false);
			new Joindre(this);
		}
		else if (e.getSource() == boutonCreer)
			{
				setVisible(false);
				new Cree(this);
			}
			else if (e.getSource() == boutonQuitter)
				{
					JOptionPane conf = new JOptionPane();
					int res = 0;
					res = conf.showConfirmDialog(null,"Voulez vous vraiment quitter ?","Attention", conf.WARNING_MESSAGE); 			
					if (res == 0)
						System.exit(0);						
				}
				else if (e.getSource() == boutonStatistiques)
					{	
						new Stat(this);
					}
					else if (e.getSource() == boutonConfiguration)
						{	
							new Config(this);
						}
						else if (e.getSource() == boutonAffichage)
							{	
								new Affichage(this);
							}
	}
	
	public static void main(String [] arg) 
	{
		new Index();
	}
}

