import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Write a description of class BoxautoRot here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

 

public abstract class Auto extends Actor
{
    private int mDrehrichtung = 0;
    private int mDrehung = 0;

    public Auto()
    {
        setRotation(Greenfoot.getRandomNumber(360));
    }
    
    public void act() 
    {
    }  
 
    public void fahren()
    {
       if(amArenaRand())
       {
            move(-15);
            mDrehrichtung = Greenfoot.getRandomNumber(2);
            mDrehung = Greenfoot.getRandomNumber(90)+ 90;
            if(mDrehrichtung==0)
            {
                turn(-mDrehung);
            }
            else
            {
                turn(+mDrehung);
            }
       }
       Actor kollidierendesFahrzeug = getOneIntersectingObject(Auto.class);
       if (kollidierendesFahrzeug != null)
       {
            kollidierendesFahrzeug.move(-15);
            kollidierendesFahrzeug.turn(30);
       }
       move(5);
    }
    
    public boolean amArenaRand()
    {
        boolean mWenden = false;
        if(getX()- 18 < 21) 
        {
            mWenden = true;
        }
        if (getX() + 18 > getWorld().getWidth() - 21)
        {
            mWenden = true;
        }
        if(getY()-18 < 21)
        {
           mWenden = true;
        }
        if( getY()+ 18 > getWorld().getHeight() - 2)
        {
            mWenden = true;
        }
        return mWenden;
    }
}
