-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
67 lines (48 loc) · 1.38 KB
/
Copy pathItem.java
File metadata and controls
67 lines (48 loc) · 1.38 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
// abstract class for all the Items in the game
// implements the Entity interface
abstract class Item implements Entity, Sellable {
// private data members
private String name;
private int level;
private int price;
// constructor
public Item(String name, int price, int level) {
this.name = name;
this.level = level;
this.price = price;
}
// all the getter methods
public String getName() {
return name;
}
public int getLevel() {
return level;
}
public int getPrice() {
return price;
}
// attribute mutator methods
public void setName(String newName) {
name = newName;
}
public void setLevel(int k) {
level = k;
}
public void setPrice(int k) {
price = k;
}
// additional methods
public String toString() {
String s = "";
s += name + "\n";
s += " Level: " + Colors.ANSI_CYAN + Integer.toString(level) + Colors.ANSI_RESET + "\n";
s += " Price: " + Colors.ANSI_YELLOW + Integer.toString(price) + Colors.ANSI_RESET + "\n";
return s;
}
// equals methods for the item
public boolean equals(Item other) {
return this.getName() == other.getName();
}
// abstract method that has to be implemented by any Item object
abstract boolean canBeUsed(HeroEntity other);
}