-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpellList.java
More file actions
54 lines (51 loc) · 1.99 KB
/
SpellList.java
File metadata and controls
54 lines (51 loc) · 1.99 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
import java.io.*;
import java.util.ArrayList;
//initiate spell information
public class SpellList {
ArrayList<item> spellList;
private static String filePath;
public SpellList(){
spellList = new ArrayList<item>();
String filePath1 = "FireSpells.txt";
generateList(filePath1);
String filepath3 = "LightningSpells.txt";
String filePath2 = "IceSpells.txt";
generateList(filePath2);
generateList(filepath3);
}
public ArrayList<item> getSpellList(){
return this.spellList;
}
public void generateList(String filePath) {
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 = Integer.parseInt(tokens[3]);
int mana_cost = Integer.parseInt(tokens[4]);
spellList.add(new Spells(name, cost, level, damage, mana_cost));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void print(){
int i = 1;
for (item a : spellList) {
Spells armory = (Spells) a;
System.out.println(i);
System.out.print("Name: " + armory.getName() + "\nCost: " + armory.getCost() + "\nRequired Level: " +
armory.getRequiredLevel() + "\nDamage: " + armory.getDamage() +
"\nMana cost: "+armory.getMana_cost());
i++;
System.out.println("\n");
}
}
}