import java.util.*;
import java.awt.*;
import java.awt.Image;
import javax.swing.ImageIcon;

/**
 *  Piece View
 *  <p>
 *  This class handles the visual aspect of every piece in the game
 */
public class PieceView {
    private GameObject pp;
    private Image img;
    private String dir_img = "src/";

    /**
    * Constructor for PieceView
    * @param p      object to represent visually
    * @param color  color of the player
    */
    public PieceView (GameObject p, int color){
      pp=p;
      String nombre = p.getClass().getName();
      Vector2D pos = p.getPosition();
      if (color==1){
        dir_img = "src/R"+nombre+".png";
      }
      else{
        dir_img = "src/B"+nombre+".png";
      }
      ImageIcon ii = new ImageIcon(dir_img);
      img = ii.getImage();
    }

    /**
    * Updates the image of the given piece
    * @param p Piece to update
    * @param color new color for the piece
    */
    public void update(GameObject p, int color){
      pp=p;
      String nombre = p.getClass().getName();
      Vector2D pos = p.getPosition();
      if (color==1){
        dir_img = "src/R"+nombre+".png";
      }
      else{
        dir_img = "src/B"+nombre+".png";
      }
      ImageIcon ii = new ImageIcon(dir_img);
      img = ii.getImage();
    }

    /**
    * Method to be drawn by the World
    * @param g object 2d
    */
    void paint(Graphics2D g) {
       Vector2D pos = pp.getPosition();
       Pawn ppeon = (Pawn)pp;
       g.drawImage(img, pos.getX(), pos.getY(), null);
       Pawn peon = (Pawn)pp;
    }
 }