-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameConfig.java
More file actions
78 lines (55 loc) · 2 KB
/
GameConfig.java
File metadata and controls
78 lines (55 loc) · 2 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
75
76
77
78
import java.util.ArrayList;
import java.util.Scanner;
public class GameConfig {
private FileFormatStrategy fileFormatStrategy;
private QuestionList questions;
private PlayerList players;
public QuestionList getQuestions() {
return questions;
}
public PlayerList getPlayers() {
return players;
}
public GameConfig(){
this.players = new PlayerList();
this.questions = new QuestionList();
}
public void getFile(String fileFormat, String filePath) {
switch (fileFormat.toLowerCase()) {
case "csv":
fileFormatStrategy = new CsvFormatStrategy();
break;
case "json":
fileFormatStrategy = new JsonFormatStrategy();
break;
case "xml":
fileFormatStrategy = new XmlFormatStrategy();
break;
default:
System.out.println("Unsupported file format!");
return;
}
loadQuestions(filePath);
}
public void loadQuestions(String filePath){
if(fileFormatStrategy == null){
System.out.println("File format strategy not set.");
return;
}
ArrayList<Question> loadedQuestions = fileFormatStrategy.loadQuestions(filePath);
for(Question q : loadedQuestions){
questions.addQuestion(q);
}
System.out.println("Loaded " + loadedQuestions.size() + " questions from " + filePath);
}
public void addPlayers(int numPlayers, GameEventLogPublisher publisher){
Scanner scanner = new Scanner(System.in);
for(int i = 1; i <= numPlayers; i++){
System.out.println("Enter name for Player " + i + ":");
String playerName = scanner.nextLine();
Player player = new Player(playerName, publisher);
players.addPlayer(player);
}
System.out.println("Added " + numPlayers + " players to the game.");
}
}