package candyfactory;

import java.awt.Graphics;

public class Truck extends Thread {

    int x, y, dx, dy, step;

    CandyPanel panel;
    
    boolean full;
    
    int capacity = 50;

    public Truck(int x, int y, int dx, int dy, int step, CandyPanel panel, boolean full) {
	this.x = x;
	this.y = y;
	this.dx = dx;
	this.dy = dy;
	this.step = step;
	this.panel = panel;
	this.full=full;
	start();
    }

    void move() {
	CandyObject obj = panel.getCandyObject(this);
	if(obj!=null){
	    obj.loadUnload(this);
	    dx*=-1;
	    dy*=-1;
	}
	x += dx * step;
	y += dy * step;
    }

    void drawSelf(Graphics g) {
	if(!full)
	    g.drawRect(x, y, 5, 5);
	else
	    g.fillRect(x, y, 5, 5);
    }

    @Override
    public void run() {
	// TODO Auto-generated method stub
	super.run();
	while (true) {
	    move();
	    try {
		sleep(10);
	    } catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	    }
	    panel.repaint();
	}
    }
}
