/*
 * MyObject.java
 *
 * Created on 12 October 2006, 22:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ants;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseListener;

/**
 *
 * @author James Hamilton
 */
public abstract class MyObject extends Rectangle implements MyObjectInterface {
    
    private GridSquare gridSquare;
    
    /** Creates a new instance of MyObject */
    public MyObject() {
        setSize(GridSquare.SIZE, GridSquare.SIZE);
    }
    
    public MyObject(GridSquare s) {
        setGridSquare(s);
        setSize(s.getSize());
        setLocation(s.getLocation());
    }

    public void draw(Graphics g) {
        
        Graphics2D g2d = (Graphics2D)g;

        g2d.setColor( getColor());
  
        g2d.fill(this);
       
        g2d.draw(this);
    }

    public GridSquare getGridSquare() {
        return gridSquare;
    }

    public void setGridSquare(GridSquare gridSquare) {
        if(this.gridSquare != null) this.gridSquare.setObject(null);
        this.gridSquare = gridSquare;
        
        if(gridSquare == null) {
            setLocation(-99, -99);
            
        }else{
            setLocation(gridSquare.getLocation());
//            if(this instanceof Ant) 
//               gridSquare.setAnt((Ant)this);
//            else
               gridSquare.setObject(this);
        }
    }
}

