package candyfactory;

import java.awt.Graphics;

public class CandyShop extends CandyObject {

    public CandyShop(int x, int y, int w, int h, int capacity, int quantity) {
	super(x, y, w, h, capacity, quantity);
	// TODO Auto-generated constructor stub
    }

    @Override
    void drawSelf(Graphics g) {
	super.drawSelf(g);
	g.drawRect(x, y, w, h);
	// TODO Auto-generated method stub
    }
    
    void sell() {
  	lock.lock();
  	while (quantity==0)
  	    try {
  		hasCandies.await();
  	    } catch (InterruptedException e) {
  		// TODO Auto-generated catch block
  		e.printStackTrace();
  	    }
  	quantity --;
  	hasRoom.signalAll();
  	lock.unlock();
      }
    
    @Override
    public void run() {
        // TODO Auto-generated method stub
        super.run();
        while(true){
            try {
		sleep(100);
	    } catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	    }
            sell();
        }
    }

}
