我正在尝试将一个命令行迷宫求解算法(运行良好)使用2d字符数组将迷宫表示为android,以进行一些实践和乐趣。我在导航文件结构并使Java查找R.raw中的.txt文件时遇到麻烦。有什么想法吗?
//int[] size contains the size X,Y of the maze.
public void constructArray(int[] size,String filename) throws FileNotFoundException {
Scanner sc = new Scanner(new File(filename));
for (int y = 0; y < this.size[1]; y++) {
String line = sc.nextLine().replaceAll(" ", "");
for (int x = 0; x < this.size[0]; x++) {
this.maze[x][y] = line.charAt(x);
}
}
}
}
这基本上是每个.txt文件的内部外观。
# # # # # # # # # # # #
# . . . # . . . . . . #
. . # . # . # # # # . #
# # # . # . . . . # . #
# . . . . # # # . # . #
# # # # . # F # . # . #
# . . # . # . # . # . #
# # . # . # . # . # . #
# . . . . . . . . # . #
# # # # # # . # # # . #
# . . . . . . # . . . #
# # # # # # # # # # # #