-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTowerDefenseGame.java
executable file
·118 lines (99 loc) · 2.97 KB
/
TowerDefenseGame.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
/**
* TowerDefenseGame Class. Contains the public static game panel and control
* panel.
*
* @author haolidu
* @version 1.00
*/
public class TowerDefenseGame extends JFrame {
private static final long serialVersionUID = 7802547810493971167L;
public static final int WINDOW_WIDTH = 800 + 150, WINDOW_HEIGHT = 600;
private static GamePanel gamePanel;
private static ControlPanel cPanel;
/**
* Returns the control panel
*
* @return ControlPanel
*/
public static ControlPanel getControlPanel() {
return cPanel;
}
/**
* Returns the game panel
*
* @return the game panel
*/
public static GamePanel getGamePanel() {
return gamePanel;
}
public static void main(String[] args) {
new TowerDefenseGame("Tower Defense Game");
}
/**
* TowerDefenseGame Constructor. Sets up the properties of the frame.
*/
public TowerDefenseGame(String name) {
super(name);
// Adds menu bar.
setJMenuBar(setupMenuBar());
// Set Window properties
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gamePanel = new GamePanel();
add(gamePanel);
cPanel = new ControlPanel();
add(cPanel, BorderLayout.WEST);
pack();
setVisible(true);
}
/**
* Setups the menu bar for the frame.
*
* @return JMenuBar
*/
private JMenuBar setupMenuBar() {
final JMenuBar menuBar = new JMenuBar();
final JMenu system = new JMenu("System");
// item 1:
JMenuItem path = new JMenuItem("New Path");
path.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gamePanel.newPath();
}
});
JMenuItem fastF = new JMenuItem("Fast Forward x2");
fastF.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gamePanel.getTimer().setDelay(40);
}
});
JMenuItem fastF2 = new JMenuItem("Fast Forward x4");
fastF2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gamePanel.getTimer().setDelay(20);
}
});
JMenuItem regularV = new JMenuItem("Regular Speed");
regularV.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gamePanel.getTimer().setDelay(80);
}
});
system.add(path);
system.add(fastF);
system.add(fastF2);
system.add(regularV);
menuBar.add(system);
return menuBar;
}
}