-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
74 lines (61 loc) · 1.73 KB
/
Copy pathPlayer.java
File metadata and controls
74 lines (61 loc) · 1.73 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
package udemy;
import java.util.ArrayList;
import java.util.List;
public class Player implements ISaveable{
private String name;
private String weapon;
private int hitPoints;
private int strength;
public Player(String name, int hitPoints, int strength) {
this.name = name;
this.hitPoints = hitPoints;
this.strength = strength;
this.weapon = "Sword";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWeapon() {
return weapon;
}
public void setWeapon(String weapon) {
this.weapon = weapon;
}
public int getHitPoints() {
return hitPoints;
}
public void setHitPoints(int hitPoints) {
this.hitPoints = hitPoints;
}
public int getStrength() {
return strength;
}
public void setStrength(int strength) {
this.strength = strength;
}
@Override
public List<String> write(){
List<String> values = new ArrayList<String>();
values.add(0,this.name);
values.add(1,""+this.hitPoints);
values.add(2,""+this.strength);
values.add(3,this.weapon);
return values;
}
@Override
public void read(List<String> values){
if(values != null && values.size()>0){
this.name = values.get(0);
this.hitPoints = Integer.parseInt(values.get(1));
this.strength = Integer.parseInt(values.get(2));
this.weapon = values.get(3);
}
}
@Override
public String toString(){
return ("Player{name='"+this.name+"', hitPoints="+this.hitPoints+", strength="+this.strength+", weapon='"+this.weapon+"'}");
}
}