import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class RoverCuriosity here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class RoverCuriosity extends Actor
{

    private int richtung = 1;
    private int direction = 1;
    private boolean stoesstAnWandAn = false;
    private static final int EAST = 0;
    private static final int WEST = 1;
    private static final int NORTH = 2;
    private static final int SOUTH = 3;

    /**
     * Act - do whatever the RoverCuriosity wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {

        
    }   

    public void debugStatusAusgeben()
    {
        System.out.println("x: " + getX() + ", y: " + getY() + "; rotation: " + getRotation()

            + ", Richtung: " + richtung + ", stoesstAnWand: " + stoesstAnWandAn  + ", canMove: " + canMove());

    }

    public boolean canMove()
    {
        World myWorld = getWorld();

        int x = getX();
        int y = getY();
        stoesstAnWandAn = false;
        if((getRotation() > 315 && getRotation() <= 359) || (getRotation() >= 0 && getRotation() <= 45))
        {richtung = EAST;
            if(x+20 >= myWorld.getWidth())
            { stoesstAnWandAn = true;
            }
        }
        else if(getRotation() > 45 && getRotation() <= 135)
        { richtung = SOUTH;
            if(y+20 >= myWorld.getHeight())
            { stoesstAnWandAn = true;
            }
        }
        else if(getRotation() > 135 && getRotation() <= 225)
        { richtung = WEST;
            if(x-20 < 0)
            { stoesstAnWandAn = true;
            }
        }
        else if(getRotation() > 225 && getRotation() <= 315)
        { richtung = NORTH;
            if(y-20 < 0 )
            { stoesstAnWandAn = true;
            }
        }
        else {System.out.println("da geht etwas schief!!!");
            System.out.println(getRotation())    ;
        }
 
        return !stoesstAnWandAn;

    }
}
