import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.*;
import java.awt.Image;
import java.util.*;
import java.awt.event.*;

public class MyWorldView extends JPanel { 
   private MyWorld world;
   //private static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   public static int WIDTH =(int) GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth();
   public static int HEIGHT =(int) GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight();
   private Image background = Toolkit.getDefaultToolkit().createImage("src/background.png");
   private Image borde = Toolkit.getDefaultToolkit().createImage("src/borde.png");
   //private Image WinPlayer1 = Toolkit.getDefaultToolkit().createImage("src/WinPlayer1.png");
   //private Image WinPlayer2 = Toolkit.getDefaultToolkit().createImage("src/WinPlayer2.png");
   //public static int droping = 0;
   //public static int win = -1;
   
   
   public MyWorldView(MyWorld w){
      world = w;
      mListener = new MouseListener(w);
      addMouseMotionListener(mListener);
      addMouseListener(mListener);      
   }

   public void paintComponent(Graphics g){
      Graphics2D g2 = (Graphics2D)g;
      super.paintComponent(g);
      g.drawImage(background, 0, 0, WIDTH, HEIGHT, null);   //Dibuja el fondo
      g.drawImage(borde, (WIDTH-1039)/2 , (HEIGHT-635)/2, null);  //Dibuja el borde del tablero que hice en paint

      ArrayList<PlayableElement> pieces = world.getPlayableElements();
      ArrayList<Board> boards = world.getBoards();
      //Collections.sort(pe);
      for (Board b:boards){   //Dibuja una lista de casillas
         b.paintView(g2);
      }
      for (PlayableElement p:pieces){   //Dibuja una lista de casillas
         p.paintView(g2);
      
      }
      BotonPass bo = world.getBoton();
      bo.paintView(g2);
      world.info.paintView(g2);
      /*if(MyWorld.game_phase==0){
         g.setColor(Color.RED);
         g.drawLine((WIDTH-630)/2, (HEIGHT-630)/2 +70*3, (WIDTH-630)/2 +630, (HEIGHT-630)/2 +70*3);
         g.setColor(Color.BLUE);
         g.drawLine((WIDTH-630)/2, (HEIGHT-630)/2 +70*6, (WIDTH-630)/2 +630, (HEIGHT-630)/2 +70*6);
      }
      for (int i=0;i<pe.size() ;i++ ) {
         PlayableElement go = pe.get(i);
         go.paintView(g2);
      }
      world.info.paintView(g2);*/
      /*if (MyWorld.game_phase==3){
         if (win==0){
            g.drawImage(winImage0, WIDTH/2 - 160,HEIGHT/2 -160 ,null);
         }
         else if (win==1){
            g.drawImage(winImage1, WIDTH/2 - 160,HEIGHT/2 -160 ,null);
         }
      }*/
   }

   private MouseListener mListener;

}