import javax.swing.JFrame;
import javax.swing.*;
import java.awt.Container;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.*;
import java.awt.event.*;
/**
 *  GameMain
 *  <p>
 *  Numen
 */
public class GameMain {
   public static void main(String[] args) {
      GameMain_GUI gui = new GameMain_GUI();
      gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      //gui.setExtendedState(JFrame.MAXIMIZED_BOTH);
      gui.setVisible(true); 
   }
}
/**
 *  GameMain_GUI
 *  <p>
 *  Interfaz de usuario general para el juego
 */
class GameMain_GUI extends JFrame {
   private Board b;
/**
	*	Construstor de GameMain_GUI
	*	Crea un menu 
	*	Crea objetos y comienza el juego
	*/
   public GameMain_GUI() {
      setTitle("Numen Alpha");
      setSize(MyWorldView.WIDTH, MyWorldView.HEIGHT+50);  // height+50 to account for menu height
      MyWorld world = new MyWorld();
      add(world.getView()); // it is equivalent to getContentPane().add(...);
      //EditMenuListener eListener = new EditMenuListener(world);
      WorldControlMenuListener wcListener = new WorldControlMenuListener(world);
      setJMenuBar(createLabMenuBar(wcListener));
      
     
      
      
      for (int i=0;i<8;i++){  //Aqui se crea la matriz de casillas para hacer el tamaņo del tablero
			for (int j=0;j<14;j++) {
				Vector2D vec = new Vector2D(i,j);
				b = new Board( (MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i, vec);
				world.addElement(b);
            
		
      if (i==5 && j==0){
      
      KingBlack kb =  new KingBlack(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j , (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea rey negro
	   world.addElement(kb);
      b.addPiece(kb);
      }
      if (i==5 && j==13){
		KingWhite kw =  new KingWhite(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea un rey blanco
		world.addElement(kw);
      b.addPiece(kw);}
      
      if (i==0 && j==0){
      HorseBlack hb =  new HorseBlack(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i ),new Vector2D(i,j));// crea un caballo negro
	   world.addElement(hb);
      b.addPiece(hb);}
      
      if (i==0 && j==13){
		HorseWhite hw =  new HorseWhite(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea un caballo blanco
		world.addElement(hw);
      b.addPiece(hw);}
      
      if (i==2 && j==0){
      TowerBlack tb =  new TowerBlack(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea una torre negra
	   world.addElement(tb);
      b.addPiece(tb);}
      
      if (i==2 && j==13){
		TowerWhite tw =  new TowerWhite(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea una torre blanca
		world.addElement(tw);
      b.addPiece(tw);}
      
      if (i==4 && j==0){
      QueenBlack qb =  new QueenBlack(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea una reina negra
	   world.addElement(qb);
      b.addPiece(qb);}
      
      if (i==4 && j==13){
		QueenWhite qw =  new QueenWhite(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea una reina blanca
		world.addElement(qw);
      b.addPiece(qw);}
      
      if (i==7 && j==0){
      BishopBlack bb =  new BishopBlack(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea un alfil negro
	   world.addElement(bb);
      b.addPiece(bb);}
      
      if (i==7 && j==13){
		BishopWhite bw =  new BishopWhite(new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*j, (MyWorldView.HEIGHT - 620)/2 + 70*i),new Vector2D(i,j));// crea un alfil blanco
		world.addElement(bw);
      b.addPiece(bw);}
      
      }}
      BotonPass bp = new BotonPass((MyWorldView.WIDTH-1024)/2 + 70*7, (MyWorldView.HEIGHT - 620)/2 + 70*8);
      InfoView info = new InfoView (new Vector2D((MyWorldView.WIDTH-1024)/2 + 70*20, (MyWorldView.HEIGHT - 620)/2 + 70*20));
      world.setInfo(info);
      world.addElement(bp);
		world.repaintView();
		world.start();
   }
   private JMenuBar createLabMenuBar(WorldControlMenuListener wl) {
      JMenuBar mb = new JMenuBar();
      
      JMenu menu = new JMenu("Juego");
      mb.add(menu);
      
      JMenuItem menuItem = new JMenuItem("Reset");
      menuItem.addActionListener(wl);
      menu.add(menuItem);
      
      menu = new JMenu ("Ver");
      mb.add(menu);
      
      menuItem = new JMenuItem("Reglas");
      menu.add(menuItem);
      menuItem.addActionListener(wl);
      
      JMenuItem menuItem2 = new JMenuItem("Cartas");
      menu.add(menuItem2);
      menuItem2.addActionListener(wl);
      
      JMenuItem menuItem3 = new JMenuItem("Historia");
      menu.add(menuItem3);
      menuItem2.addActionListener(wl);
      
      return mb;          
      
      
   }  
 
}