-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArtifact.java
101 lines (83 loc) · 2.47 KB
/
Artifact.java
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
import java.util.Scanner;
public class Artifact {
private int id, value, mobility, keyPattern;
private String name, description;
public Artifact(Scanner scanner, double version) {
String line = Game.getCleanLine(scanner);
//line 1 will be a D
int idTrue = 0;
Scanner temp = new Scanner(line);
idTrue= temp.nextInt();
//reads in new line
line = Game.getCleanLine(scanner);
readInfo(line);
line = Game.getCleanLine(scanner);
readDescription(line, scanner);
//check version
if (version >= 4) {
if (idTrue < 0) {//character ID given
Character character = Character.getCharacterByID(Math.abs(idTrue));
character.addArtifact(this);
} else if (idTrue > 0) {//place ID given
Place p = Place.getPlaceByID(idTrue);
p.addArtifact(this);
} else {
Place.getRandomPlace().addArtifact(this);
}
}else{
Place place = Place.getPlaceByID(idTrue);
place.addArtifact(this);
}
}
private void readInfo(String line) {
Scanner temp = new Scanner(line);
id = temp.nextInt();
value = temp.nextInt();
mobility = temp.nextInt();
keyPattern = temp.nextInt();
name = temp.nextLine().trim();
temp.close();
}
private void readDescription(String line, Scanner scanner) {
Scanner temp = new Scanner(line);
int numLines = temp.nextInt();
for (int i = 0; i < numLines; i++) {
String d = Game.getCleanLine(scanner);
if (description == null)
description = d + "\n";
else
description += d + "\n";
}
}
public int getMobility() {
return mobility;
}
public String getName() {
return name;
}
public int getID() {
return id;
}
public int getValue() {
return value;
}
public int getKeyPattern() {
return keyPattern;
}
public boolean match(String str) {
return name.equalsIgnoreCase(str);
}
public int size() {
return mobility;
}
public String getDescription() {
return description;
}
public void use(Character character, Place place) {
place.useArtifact(this);
}
public void print() {
}
public void display() {
}
}