import sum.kern.*;

public class Kugel
{
    private Buntstift hatStift;
    private Bildschirm kenntBildschirm;
    // Attribute
    private int zGroesse;
    private double zGeschwindigkeit;

    // Konstruktor
    public Kugel(int pH, int pV, int pGroesse, double pGeschwindigkeit,
                 int pFarbe, int pRichtung, Bildschirm pBildschirm)
    {
        hatStift = new Buntstift();
        hatStift.bewegeBis(pH, pV);
        hatStift.setzeFarbe(pFarbe);
        hatStift.setzeFuellmuster(Muster.GEFUELLT);
        zGroesse = pGroesse;
        zGeschwindigkeit = pGeschwindigkeit;
        this.setzeRichtung(pRichtung);
        kenntBildschirm = pBildschirm;
    }

    // Dienste
    public void gibFrei()
    { hatStift.gibFrei(); }

    public void zeichne()
    {
        hatStift.zeichneKreis(zGroesse);
    }

    public void loesche()
    {
        hatStift.radiere();
        this.zeichne();
        hatStift.normal();
    }

    public void bewege()
    {
        this.loesche();
        hatStift.bewegeUm(zGeschwindigkeit);
        this.zeichne();
        if(this.amLinkenRand() || this.amRechtenRand())
            this.setzeRichtung(180 - hatStift.winkel());
        if(this.amOberenRand() || this.amUnterenRand())
            this.setzeRichtung(360 - hatStift.winkel());
    }

    public double hPosition()
    {
        return hatStift.hPosition();
    }

    public double vPosition()
    {
        return hatStift.vPosition();
    }

    public void setzeRichtung(double pRichtung)
    {
        hatStift.dreheBis(pRichtung);
    }

    private boolean amLinkenRand()
    {
        return this.hPosition() < zGroesse;
    }

    private boolean amRechtenRand()
    {
        return this.hPosition() >(kenntBildschirm.breite() - zGroesse);
    }

    private boolean amOberenRand()
    {
        return this.vPosition() < zGroesse;
    }

    private boolean amUnterenRand()
    {
        return this.vPosition() >(kenntBildschirm.hoehe() - zGroesse);
    }

    public void setzeGroesse(int pGroesse)
    {
        zGroesse = pGroesse;
    }

    public int groesse()
    {
        return zGroesse;
    }

    public void setzeGeschwindigkeit(double pGeschwindigkeit)
    {
        zGeschwindigkeit = pGeschwindigkeit;
    }

    public double geschwindigkeit()
    {
        return zGeschwindigkeit;
    }
}
