-
Notifications
You must be signed in to change notification settings - Fork 1
/
Data.java
74 lines (64 loc) · 2.05 KB
/
Data.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package src;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Data {
private ArrayList<String[]> MAP = new ArrayList<>();
private Point ROBOT;
private ArrayList<Point> BUTTER = new ArrayList<>();
private ArrayList<Point> PURCHASER = new ArrayList<>();
public Data(String path) throws FileNotFoundException {
File myObj = new File(path);
Scanner myReader = new Scanner(myObj);
String data = myReader.nextLine();
String[] strings = data.split("\t");
while (myReader.hasNextLine()) {
data = myReader.nextLine();
strings = data.split("\t");
MAP.add(strings);
}
myReader.close();
for(int i =0; i < this.MAP.size(); i++){
for(int j = 0; j < this.MAP.get(i).length; j++){
String c = this.MAP.get(i)[j];
if (c.contains("r")){
ROBOT = new Point(i, j);
MAP.get(i)[j] = MAP.get(i)[j].replace("r", "");
}
if (c.contains("b")){
BUTTER.add(new Point(i, j));
MAP.get(i)[j] = MAP.get(i)[j].replace("b", "");
}
if (c.contains("p")){
PURCHASER.add(new Point(i, j));
}
}
}
}
public ArrayList<Point> getBUTTER() {
return BUTTER;
}
public Point getROBOT() {
return ROBOT;
}
public ArrayList<String[]> getMAP() {
return MAP;
}
public ArrayList<Point> getPURCHASER() {
return PURCHASER;
}
public void output(Result result) {
System.out.println("Saved data to file: (" + result.getPath() + ")");
System.out.println(result.output());
try {
FileWriter myWriter = new FileWriter(result.getPath());
myWriter.write(result.output());
myWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}