-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFLoadGameConfig.java
60 lines (50 loc) · 1.52 KB
/
FLoadGameConfig.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class FLoadGameConfig implements GameConfig {
private int id;
private String name;
private int version;
/**
* Constructor for objects of class LoadGameConfig
*/
public FLoadGameConfig() {
try (BufferedReader reader = new BufferedReader(
new FileReader(System.getProperty("user.dir") + "/config/GameConfig.txt"))) {
String line;
if ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
id = Integer.parseInt(parts[0]);
name = parts[1];
version = Integer.parseInt(parts[2]);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public Object getGameConfig() {
return new GameConfigImpl(id, name, version);
}
private class GameConfigImpl implements GameConfig {
private int id;
private String name;
private int version;
public GameConfigImpl(int id, String name, int version) {
this.id = id;
this.name = name;
this.version = version;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getVersion() {
return version;
}
public Object getGameConfig() {
return new GameConfigImpl(id, name, version);
}
}
}