/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author A KUMA
 */
public class Game extends JFrame implements MouseListener {
    JButton game1,game2,game3;
    JPanel butons;
    boolean runMenu=true,camina=true;
    int y0,yLienzo=170;
    invF invF=new invF();
//    Invader invaders=new Invader(50,50);//invaders
    public Game(){
        //creando reguilla de juegos
        this.getContentPane().setLayout (new BorderLayout());
        //cuadricula de botones
        butons=new JPanel();
        butons.setLayout(new GridLayout(3,3));
        game1=new JButton("JUGAR");//inicializando botones
        game2=new JButton("AYUDA");
        game3=new JButton("SALIR");
        game3.setFocusable(false);
        game3.setBackground(Color.black);
        game3.setBorderPainted(false);
        game2.setFocusable(false);
        game2.setBackground(Color.black);
        game2.setBorderPainted(false);
        game1.setFocusable(false);
        game1.setBackground(Color.LIGHT_GRAY);
        game1.setBorderPainted(false);
        game3.addMouseListener(this);
        game2.addMouseListener(this);
        game1.addMouseListener(this);
        butons.add (game1);//anadiendo los botones
        butons.add (game2);
        butons.add (game3);

        this.add (new lienzo(),BorderLayout.CENTER);//de dibujos
        this.add ( butons,BorderLayout.WEST);//agrega botones
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Menu Space Invaders");
        pack();
        setVisible(true);
        this.setResizable(false);
        
        invF.run();
    }
    private void salir(){
        runMenu=false;
        System.exit(0);
    }
    @Override
    public void mouseClicked(MouseEvent ae) {
        if(ae.getSource()==game1){
            new SpaceInvaders(false);//inicia juego
        }else{
            if(ae.getSource()==game2){
                new about();
            }else{
                if(ae.getSource()==game3){salir();}//sale!! x-P
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent me) {
    }

    @Override
    public void mouseReleased(MouseEvent me) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseEntered(MouseEvent me) {
        Sound.selec.play();
        if(me.getSource()==game1){
            game1.setBackground(Color.LIGHT_GRAY);
            game2.setBackground(Color.black);
            game3.setBackground(Color.black);
            y0=0;
        }else{
            if(me.getSource()==game2){
                y0=yLienzo/3;
                game1.setBackground(Color.black);
                game2.setBackground(Color.LIGHT_GRAY);
                game3.setBackground(Color.black);
            }else{
                if(me.getSource()==game3){
                    y0=2*yLienzo/3;
                    game1.setBackground(Color.black);
                    game2.setBackground(Color.black);
                    game3.setBackground(Color.LIGHT_GRAY);}
            }
        }
    }

    @Override
    public void mouseExited(MouseEvent me) {
       //inv dibagan
    }
    class lienzo  extends JPanel{
        public lienzo(){
            this.setBackground(Color.BLACK);
            this.setPreferredSize(new Dimension(55,yLienzo));
        }
        @Override
        public void paint(Graphics g){  
         super.paint(g);
         
        if(camina){Invader.dibujaInv_a0(5,y0,5,6,g);}
        else{Invader.dibujaInv_a1(5,y0,5,6,g);}
        }
    }
    private class invF extends Thread{
        @Override
        public void run(){
            while(runMenu){
                repaint();
                try {
                    sleep(70);
                } catch (InterruptedException ex) {}
            }
        }
    }
    private class about extends JFrame{
        public about(){
        this.getContentPane().setLayout (new BorderLayout());

        this.add(new lienzoA(),BorderLayout.CENTER);
        //this.add(new JButton("epa"));
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
        pack();
        setVisible(true);
        this.setResizable(false);
        }
        class lienzoA extends JPanel{
            String mostrar0,mostrar1,mostrar2,mostrar3,mostrar4;
            public lienzoA(){
            this.setBackground(Color.BLACK);
            this.setPreferredSize(new Dimension(375, 180));
            }
            
            @Override
            public void paint(Graphics g){
                super.paint(g);
                Font boldFont = new Font("Serif", Font.ITALIC, 18);
                g.setFont(boldFont);
                mostrar0="1.- Utiliza las flechas para moverte";
                mostrar1="2.- Utiliza la barra espaciadora para disparar.";
                mostrar3="'Todos los derecho reservados'";
                mostrar4="Javier Gonzalez Gomez";
                mostrar2="3.- Enjoy";
                g.setColor(Color.WHITE);
                g.drawString(mostrar0, 20, 30);
                g.drawString(mostrar1, 20, 65);
                g.drawString(mostrar2, 20, 100);
                g.drawString(mostrar4, 80, 175);
                g.setColor(Color.RED);
                g.drawString(mostrar3, 60, 140);
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Game();
    }
}
