-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathGameFactory.java
More file actions
29 lines (24 loc) · 932 Bytes
/
GameFactory.java
File metadata and controls
29 lines (24 loc) · 932 Bytes
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
package scorekeep;
import java.util.*;
import java.lang.Exception;
public class GameFactory {
private final HashMap<String, Game> allGames = new HashMap<String, Game>(1);
private final GameModel model = new GameModel();
private final SessionController sessionController = new SessionController();
public GameFactory(){
}
public Game newGame(String sessionId) throws SessionNotFoundException, GameNotFoundException {
String gameId = Identifiers.random();
Game game = new Game(gameId, sessionId);
model.saveGame(game);
// Register game to session
sessionController.setSessionGame(sessionId, gameId);
return game;
}
public Game getGame(String sessionId, String gameId) throws SessionNotFoundException, GameNotFoundException {
return model.loadGame(gameId);
}
public List<Game> getGames(String sessionId) throws SessionNotFoundException {
return model.loadGames(sessionId);
}
}