import java.util.*;
public class Block extends PhysicsElement  {
    /**
    * Se agrego el atributo <code> fixer </code> para diferenciar entre los objetos 
    * Block y Fixer
    */
   protected boolean fixer;
   private static int id=0;
   private final float mass;
   protected Vector2D pos_t;
   private Vector2D pos_tPlusDelta;
   private Vector2D speed_t;
   private Vector2D speed_tPlusDelta;
   private Vector<Spring> springs;  // This Vector is a growable array of objects
                                    // it has nothing to do with Vector2D.
   private Vector<RubberBand> strings;

   private Block(){ // nobody can create a block without state
      super(id++);
      mass=0;
   }  
   public Block(float mass, Vector2D position, Vector2D speed){
      super(id++);
      this.mass = mass;
      pos_t = position;
      this.speed_t = speed;
      springs = new Vector<Spring>();
      strings = new Vector<RubberBand>();

   }
   public void attachSpring (Spring spring) {
     springs.add(spring);
   }
   public void detachSpring (Spring spring) {
     springs.remove(spring);
   }
   public void attachString (RubberBand string) {
     strings.add(string);
   }
   public void detachString (RubberBand string) {
     strings.remove(string);
   }
   public Vector2D getPosition() {
      return pos_t;
   }
   /**
    * Se modifico el metodo <code> computeNextState </code> para que el calculo
    * de la fuerza considerara el nuevo elemento fisico String y Fixer.
    */
   public void computeNextState(double delta_t) {
   if(!fixer){
     Vector2D force = new Vector2D();
     Spring spring;
     RubberBand string;
     Vector2D a= new Vector2D();
     if(gravity!=0)
         force = force.plus(new  Vector2D(0f,gravity*mass));

     for (int i=0; i<springs.size(); i++) {
        spring = springs.get(i);
        if (spring != null) force = force.plus(spring.getForce(this));
     }
     for (int i=0; i<strings.size(); i++) {   //Esto esta agregado.
         string = strings.get(i);
        if (string != null) force = force.plus(string.getForce(this));
     }
     
     a = force.times(1/mass);
     pos_tPlusDelta = pos_t.plus(speed_t.times(delta_t)).plus(a.times(delta_t*delta_t/2));
     speed_tPlusDelta = speed_t.plus(a.times(delta_t));
    }
   }
   public void updateState(){
     if(!fixer){
     pos_t = pos_tPlusDelta;
     speed_t = speed_tPlusDelta;
     
     }
   }
   public String getDescription() {
      if(!fixer){
      return "Block#" + getId() + ": "+getPosition().getDescription()+",";
      }
      else return "Fixer#" + getId() + ": "+getPosition().getDescription()+",";
   }
   public String getState() {
         return getPosition()+",";
   }
} 
    
    
           
      