-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
88 lines (74 loc) · 2.16 KB
/
Main.java
File metadata and controls
88 lines (74 loc) · 2.16 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
79
80
81
82
83
84
85
86
87
88
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Controller.EditorKeyboard;
import Controller.EditorMouse;
import Controller.GameKeyboard;
import Controller.GameMouse;
import Controller.ImagesFactory;
import Model.Editor;
import Model.Game;
import Resources.ResourceLoader;
import View.LoadingFrame;
import View.Window;
public class Main {
private static final String DEFAULT_LOAD_PATH = "Data/sample2.map";
public static void main(String[] args) {
/*
* Try to load all resources in a temporary file (if we are running in a JAR)
*/
LoadingFrame splash = new LoadingFrame();
splash.showFrame();
try {
ResourceLoader.loadAll("Data");
} catch (Exception e1) {
e1.printStackTrace();
}
/* Build and run the game */
Window window = new Window("Game");
// Initialise game
Game game = new Game(window);
GameKeyboard gameKeyboard = new GameKeyboard(game);
GameMouse gameMouse = new GameMouse(game);
window.addMapKeyListener(gameKeyboard);
window.addMapMouseListener(gameMouse);
// Initialise editor
Editor editor = new Editor(window);
EditorKeyboard editorKeyboard = new EditorKeyboard(editor);
EditorMouse editorMouse = new EditorMouse(editor);
window.addMapKeyListener(editorKeyboard);
window.addMapMouseListener(editorMouse);
game.setCreatorAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
game.stopGame();
game.closeGameMenu();
editor.start();
}
});
editor.setStartGameAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editor.stop();
editor.closeEditorMenu();
game.loadGameMapPacket(editor.getGameMapPacket());
game.startGame();
}
});
/*
* Load all images at starting of the program
*/
try {
ImagesFactory.loadAllImages();
} catch (Exception e) {
e.printStackTrace();
return;
}
/*
* Load a sample map file
*/
game.restoreFromFile(ResourceLoader.getResourcePath(DEFAULT_LOAD_PATH));
splash.hideFrame();
window.setVisible(true);
game.openGameMenu();
}
}