public void changeDirection() 
    {
        int x= 0, y= 0, d= 0, posX, posY;
        boolean wall = true;
        
        //Get current position on the board
        posX = this.getHLocation();
        posY = this.getVLocation();
        
        while(wall) //Are you going to hit a wall?
        {
            d = randDirection();
        
            if(d == 0) //North
            {
                x = 0;
                y = -1;
            }

            if(d == 1) //East
            {
                x = 1;
                y = 0;
            }

            if(d == 2) //South
            {
                x = 0;
                y = 1;
            }

            if(d == 3) //West
            {
                x = -1;
                y = 0;
            }
            
            wall = Collision.hitWall(posX+x, posY+y);
        }

        if(Collision.hitHero(posX+x, posY+y)) //Are you going to hit the hero?
            Window.gameLost();
        
        
        //If the position BadGuy is on has energy, then set the number to 1
        if(Window.getEnergy(posX, posY) == 1)
            Window.setMapPosition(posX, posY, 2);
        else
            Window.setMapPosition(posX, posY, 3);
        
        
        Window.setMapPosition((posX+x), (posY+y), 4);
        this.setLocation((posX+x), (posY+y));
    }