import java.io.IOException;

public class Mouse extends Player{

    public static int counter = 0;

    public Mouse(Position p, GamingArea g, Game ga) throws IOException {
        super(p, g, ga);
        p.displayChar = DisplayChars.JERRY.getCharacter();
    }
    @Override
    public void movePlayer() throws IOException {
        MouseMove mm = MouseMove.getMove();
        int posX = this.positionPlayer.posX + mm.deltaX;
        int posY = this.positionPlayer.posY + mm.deltaY;

        if (!gArea.validatePosition(new Position(posX, posY))) {
            if(posX < 0 || posX > 9)
            {
                posX = posX-mm.deltaX;
            }
            if(posY < 0 || posY > 9)
            {
                posY = posY-mm.deltaY;
            }
        }

        Position p = gArea.playingField[posX][posY];

        if((counter%3) == 0)
        {
            p.displayChar = DisplayChars.JERRY.getCharacter();
        }
        else
        {
            p.displayChar = DisplayChars.DEFAULT.getCharacter();
        }


        System.out.println("Jerry moves to " + posX + "-" + posY);
        game.writer.write("Jerry moves from " + positionPlayer.posX+ "-" + positionPlayer.posY + " to " + posX + "-" + posY);
        game.writer.newLine();

        movePlayer(p);

        counter++;
    }
}
