-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPotionsList.java
More file actions
59 lines (52 loc) · 2.06 KB
/
PotionsList.java
File metadata and controls
59 lines (52 loc) · 2.06 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
51
52
53
54
55
56
57
58
59
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
//define all the potion from files
public class PotionsList {
private String filePath;
private ArrayList<item> potionsList;
public PotionsList(){
potionsList = new ArrayList<item>();
generateList();
}
//read potion txt file and store information to Arraylist
public ArrayList<item> getPotionsList(){
return this.potionsList;
}
public void generateList(){
filePath = "Potions.txt";
InputStream inputStream = ArmoryList.class.getClassLoader().getResourceAsStream(filePath);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
Scanner scanner = new Scanner(inputStreamReader);
scanner.nextLine(); // skip first line
while (scanner.hasNextLine()) {
String[] data;
data = scanner.nextLine().split("\\s+");
String name = data[0];
int cost = Integer.parseInt(data[1]);
int requiredLevel = Integer.parseInt(data[2]);
int attributeIncrease = Integer.parseInt(data[3]);
ArrayList<String> attributeAffected = new ArrayList<String>(Arrays.asList(data[4].split("/")));
Potions potion = new Potions(name, cost, requiredLevel, attributeIncrease, attributeAffected);
potionsList.add(potion);
}
scanner.close();
}
//print all the potion information
public void print(){
int i = 1;
for (item potion : potionsList) {
System.out.println(i);
Potions p = (Potions) potion;
System.out.print("Name: " + p.getName() + "\nCost: " + p.getCost() + "\nRequired Level: " +
p.getRequiredLevel() + "\nAttribute Increase: " + p.getAttributeIncrease() +
"\nAttribute Affected: ");
for (String attribute : p.getAttributeAffect()) {
System.out.print(attribute + " ");
}
System.out.println("\n");
i++;
}
}
}