-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDriver3
57 lines (50 loc) · 2.23 KB
/
Driver3
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
51
52
53
54
55
56
57
import java.util.*;//for scanner
import java.io.*;//for writer
import javax.swing.*;//for file chooser
public class Driver3{
Node start, room = null;
private File txtFile;
private String fileName, line;
boolean kFound = false;
int k = 1;
int roomNum, scaryRoomNum = 0;
public void readFile(){
int arrayPos = 0;
String []stringsOfInt;
Node []nodeArray;
try{//choose a file
JFileChooser aChooser = new JFileChooser();
System.out.println("Please choose a .txt file");
aChooser.showOpenDialog(null);//opens pop-up window to choose file
txtFile = aChooser.getSelectedFile();
fileName = txtFile.getName();
BufferedReader readFile = new BufferedReader(new FileReader(fileName));
while ((line = readFile.readLine()) != null){
stringsOfInt = line.split(" ");//needed to read diff rooms on same line
if (roomNum < (k*k)){//initially one, but we get the real k later
if (kFound == false){//only gets the k val
k = Integer.parseInt(stringsOfInt[1]);//get real k
nodeArray = new nodeArray(k*k);
kFound = true;}
else{
//creates node and puts it into array
nodeArray[roomNum] = new Node (Integer.parseInt(stringsOfInt[1]),roomNum);
roomNum++;
}
}
}
for (roomNum = 0; roomNum < (k*k); roomNum++){//gets shared walls
nodeArray[roomNum].sharesWallWith(roomNum + 1);
nodeArray[roomNum].sharesWallWtih(roomNum - 1);
nodeArray[roomNum].sharesWallWith(roomNum + k);
nodeArray[roomNum].sharesWallWith(roomNum + k - 1);
nodeArray[roomNum].sharesWallWith(roomNum - k);
nodeArray[roomNum].sharesWallWith(roomNum - k + 1);}
}
catch (Exception e){System.err.println("Error " + e);}
}
public static void main (String[] args) throws Exception {
Driver3 d3 = new Driver3();
d3.readFile();
}
}