import sum.kern.*;
import sum.werkzeuge.*;

public class Rotkaeppchen
{
    // Bezugsobjekte
    Rechner hatRechner;
    Buntstift hatStift;
    Bildschirm kenntBildschirm;
    
    // Attribute
    double zAbstand;
    double zGeschwindigkeit;

    // Konstruktor
    public Rotkaeppchen(double pGeschw, Bildschirm pBildschirm)
    {
        kenntBildschirm = pBildschirm;
        hatRechner = new Rechner();
        hatStift = new Buntstift();
        hatStift.bewegeBis(hatRechner.ganzeZufallszahl(10, kenntBildschirm.breite() - 10),
                           hatRechner.ganzeZufallszahl(10, kenntBildschirm.hoehe() - 10));
        hatStift.runter();
        hatStift.setzeFarbe(Farbe.ROT);
        zGeschwindigkeit = pGeschw;
   }

    public void gibFrei()
    {
        hatStift.gibFrei();
        hatRechner.gibFrei();
    }
    
    public void bewege()
    {
        hatStift.bewegeUm(zGeschwindigkeit);
        if (this.amLinkenRand())
            hatStift.dreheBis(0);
        else if (this.amRechtenRand())
            hatStift.dreheBis(180);
        else if (this.amOberenRand())
            hatStift.dreheBis(-90);
        else if (this.amUnterenRand())
            hatStift.dreheBis(90);            
        else 
            hatStift.dreheUm(hatRechner.ganzeZufallszahl(-90, 90));
    }
    
    private boolean amLinkenRand()
    {
        return hatStift.hPosition() < 10;
    }    
    
    private boolean amRechtenRand()
    {
        return hatStift.hPosition() > kenntBildschirm.breite() - 10;
    }    
    
    private boolean amOberenRand()
    {
        return hatStift.vPosition() < 10;
    }    
    
    private boolean amUnterenRand()
    {
        return hatStift.vPosition() > kenntBildschirm.hoehe() - 10;
    }
    
    public double hPosition()
    {
      return hatStift.hPosition();
    }

    public double vPosition()
    {
      return hatStift.vPosition();
    }

}

