-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
50 lines (41 loc) · 1.28 KB
/
Item.java
File metadata and controls
50 lines (41 loc) · 1.28 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
package APCSA.APCSA_Code_Your_Own;
import java.io.Serializable;
public class Item implements Serializable{
private String description;
private String[] abilities;
public Item(String description) {
this(description, new String[] { "none" });
}
public Item(String description, String[] abilities) {
this.description = description;
this.abilities = abilities;
}
public String[] getAbilities() {
return abilities;
}
public boolean hasAbility(String selectedAbility) {
for (String ability : abilities) {
if (selectedAbility.equals(ability)) {
return true;
}
}
return false;
}
public boolean useAbility(String selectedAbility, Player player) {
return hasAbility(selectedAbility);
}
public String toString() {
String returnString = "It is " + description + "Its abilities are as follows:";
for (int i = 0; i < abilities.length; i++) {
{
returnString += " " + abilities[i];
if (i == abilities.length - 1) {
returnString += ".";
} else {
returnString += ";";
}
}
}
return returnString;
}
}