-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
43 lines (36 loc) · 1.21 KB
/
Game.java
File metadata and controls
43 lines (36 loc) · 1.21 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
package snake;
import java.lang.reflect.InvocationTargetException;
import snake.view.View;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import snake.controller.GameController;
/**
* @author afeher
*/
public class Game {
private final Map<String, String> settings;
public Game(Map<String, String> settings) {
this.settings = settings;
}
public void run() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
int width = getSetting("width");
int height = getSetting("height");
int scale = getSetting("scale");
View view = new View(width, height, scale);
view.bindController(new GameController());
}
});
} catch (InterruptedException | InvocationTargetException ex) {
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
}
}
private Integer getSetting(String key) throws NumberFormatException {
return Integer.valueOf(settings.get(key));
}
}