public class Labyrintti {
    static char[][] laby = {{'#','#','#','#','#','#','#'},
                            {'#','.','.','.','.','#','#'},
                            {'#','.','#','.','#','#','#'},
                            {'#','.','#','.','#','.','#'},
                            {'#','.','.','.','.','.','#'},
                            {'#','#','#','#','#','#','#'}};
    static void tulosta(int y, int x) {
        try {Thread.sleep(500);} catch (Exception e) {};
        for (int i = 0; i < 50; i++) {
            System.out.println();
        }
        for (int i = 0; i < laby.length; i++) {
            for (int j = 0; j < laby[0].length; j++) {
                if (i == y && j == x) {
                    System.out.print('@');
                } else {
                    System.out.print(laby[i][j]);
                }
            }
            System.out.println();
        }
    }

    static void syvyyshaku(int y, int x) {
        if (laby[y][x] == '#') return;
        if (laby[y][x] == 'x') return;
        laby[y][x] = 'x';
        tulosta(y,x);
        syvyyshaku(y-1,x);
        syvyyshaku(y+1,x);
        syvyyshaku(y,x-1);
        syvyyshaku(y,x+1);
    }

    public static void main(String[] args) {
        syvyyshaku(1,1);
    }
}
