-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmoryList.java
More file actions
50 lines (43 loc) · 1.77 KB
/
ArmoryList.java
File metadata and controls
50 lines (43 loc) · 1.77 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.*;
import java.util.ArrayList;
//initiate all the Armory from file and store them into ArrayList
public class ArmoryList {
private ArrayList<Armory> armoryList;
private String filepath;
public ArmoryList(){
armoryList = new ArrayList<Armory>();
generateList();
}
public ArrayList<Armory> getArmoryList(){
return this.armoryList;
}
//read through the file and generate the Arraylist from the file and store in arraylist
public void generateList(){
filepath = "Armory.txt";
try (InputStream inputStream = ArmoryList.class.getClassLoader().getResourceAsStream(filepath);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(inputStreamReader)) {
String line;
while ((line = br.readLine()) != null) {
if (!line.startsWith("Name")) {
String[] tokens = line.split("\\s+");
String name = tokens[0];
int cost = Integer.parseInt(tokens[1]);
int level = Integer.parseInt(tokens[2]);
int damage_reduce = Integer.parseInt(tokens[3]);
armoryList.add(new Armory(name, cost, level, damage_reduce));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
//print out the list of armory
public void print(){
for (Armory armory : armoryList) {
System.out.print("Name: " + armory.getName() + "\nCost: " + armory.getCost() + "\nRequired Level: " +
armory.getRequiredLevel() + "\ndamage_reduce: " + armory.getDamage_reduce());
System.out.println("\n");
}
}
}