-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterSystem.java
More file actions
137 lines (119 loc) · 5.16 KB
/
CharacterSystem.java
File metadata and controls
137 lines (119 loc) · 5.16 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import java.util.ArrayList;
public class CharacterSystem {
public Arraylist<Character> charactermap; // *5 Error where Arraylist cannot resolve to a type; will go over on Monday [Hugh]
public CharacterSystem() {
this.charactermap = new ArrayList<Character>(); // *5
}
//add method STILL NEEDS CHECKING
public boolean add(String name, String element, int attack, String weapontype, Weapon weapon) {
if (name == null) {
return false;
}
if (attack <= 0) {
return false;
}
// null weapon means character has no weapon equipped
if (element != "Cryo" || element != "Anemo" || element != "Hydro" || element != "Geo" || element != "Pyro" || element != "Dendro" || element != "Electro") {
return false;
}
if (weapontype != "Sword" || weapontype != "Polearm" || weapontype != "Bow" || weapontype != "Claymore" || weapontype != "Catalyst") {
return false;
}
if (this.search(name)) {
return false;
}
Character toAdd = new Character(name, element, attack, weapontype, weapon);
this.charactermap.add(toAdd);
return true;
}
//search (contains) by name only (filter by name only) . True means it is in the list, false means it is not in the list
public boolean search(String name) {
for (Character c: this.charactermap) { // *5
if (c.name == name) {
return true;
}
}
return false;
}
public boolean remove(String name) {
if (this.search(name)) { //if true, character is in the list so remove them
int idx = 0;
for (Character c: this.charactermap) {
if (c.name == name) { //if the name equals, break out of the for loop and do the remove
break;
}
idx += 1; //if name not found yet, just move on to the next index
}
this.charactermap.remove(idx);
System.out.println("Your character has been removed");
return true;
}
System.out.println("Your character is not in the list");
return false; //if false, then return false because character is not in the list
}
public boolean elementRemove(String element) {
Arraylist<Character> c1 = this.charactermap;
int initialcount = c1.size();
for (int i = 0; i < c1.size(); i++) { //goes through each index of the list, checks if the element of the character at that index matches, if it does then remove
if (c1.get(i).element == element) {
System.out.println("removed" + c1.get(i).name); // < does not have to be gramatically correct
c1.remove(i);
}
}
if (c1.size() == initialcount) {
System.out.println("No characters have been removed");
return false;
}
return true;
}
public boolean weaponRemove(String weaponType) {
Arraylist<Character> c2 = this.charactermap;
int initialcount = c2.size();
for (int i = 0; i < c2.size(); i++) { //goes through each index of the list, checks if the weapontype of the character at that index matches, if it does then remove
if (c2.get(i).weapontype == weaponType) {
System.out.println("removed" + c2.get(i).name); // < does not have to be gramatically correct
c2.remove(i);
}
}
if (c1.size() == initialcount) {
System.out.println("No characters have been removed");
return false;
}
return true;
}
//How to deal with multiple elements (should be inputted in the form "element element element") like 'anemo cryo electro'
public Arraylist<Character> elementFilter(String element) {
Arraylist<Character> toReturn = new Arraylist<>();
String[] splitted = element.split(" "); //split the argument into the individual elements
for (String s: splitted) { //for each element, search the list for characters of that element
for (Character c: this.charactermap) {
if (c.element == s) {
toReturn.add(c);
}
}
}
return toReturn;
}
//Deal with multiple weapontypes same way as elements, type them out in this format: "Sword Polearm Bow"
public Arraylist<Character> weaponFilter(String weaponType) {
Arraylist<Character> toReturn = new Arraylist<>();
String[] splitted = weaponType.split(" "); //split the argument into the individual elements
for (String s: splitted) { //for each weapontype, search the list for characters of that element
for (Character c: this.charactermap) {
if (c.weapontype == s) {
toReturn.add(c);
}
}
}
return toReturn;
}
}
/*
remove method
//later, should i add like remove by element or remove by weapon? < address this later
//add to this method to work with multiple elements
find by element
find by weapon
order by attack (return ordered list)
find by certain attack
*/