-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaze.java
More file actions
50 lines (46 loc) · 1.09 KB
/
Maze.java
File metadata and controls
50 lines (46 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.util.ArrayList;
public class Maze {
protected ArrayList<MazePosition> arrl=new ArrayList<MazePosition>();
public Maze(File lbr) throws Exception{
if(lbr==null){
throw new Exception("File cannot be null");
}
if(!lbr.canRead()){
throw new Exception("File cannot be read");
}
else{
BufferedReader br = new BufferedReader(new FileReader(lbr));
String str=br.readLine();
int rowCounter=0;
MazePosition exit=new MazePosition();
while (str!=null){
rowCounter++;
for(int i=0;i<str.length();i++){
if(str.charAt(i)=='o'){
MazePosition mp=new MazePosition();
mp.setRow(rowCounter);
mp.setColumn(i+1);
arrl.add(mp);
}
else if(str.charAt(i)=='i'){
MazePosition mp=new MazePosition();
mp.setRow(rowCounter);
mp.setColumn(i+1);
arrl.add(0, mp);
}
else if(str.charAt(i)=='e'){
exit.setRow(rowCounter);
exit.setColumn(i+1);
}
}
str=br.readLine();
}
arrl.add(arrl.size(),exit);
br.close();
}
}
}