forked from CCSU-DesignPatterns-F20/final-project-team-2-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameGui.java
160 lines (137 loc) · 5.96 KB
/
GameGui.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import src.board.Board;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GameGui {
//Create Frames of the UI
JFrame gameWindow = new JFrame("Stage 1");
JFrame uiWindow = new JFrame("Tower Defense Game");
//initializing Panels
JPanel uiPanel = new JPanel();
JPanel gamePanel1 = new JPanel();
JPanel gameControl = new JPanel();
JPanel infoPanel = new JPanel();
JPanel buttonPanel = new JPanel();
JPanel statPanel = new JPanel();
JPanel functionPanel = new JPanel();
//initializing Button + Labels
JButton startButton = new JButton("Start Game");
JButton quitButton = new JButton("Exit Game");
JButton pauseButton = new JButton("Pause Game");
JButton resumeButton = new JButton("Resume Game");
JButton buyButton = new JButton("Buy");
JButton upgradeButton = new JButton("Upgrade");
JButton sellButton = new JButton("Sell");
JLabel text = new JLabel("Welcome to the tower defense game");
JLabel goldLabel = new JLabel("GOLD: " );
JLabel healthLabel = new JLabel("Lives: ");
JLabel WaveNumLabel = new JLabel("Current Wave: ");
JLabel EnemyHealth = new JLabel("Enemy's Health: ");
JLabel TowerDamage = new JLabel();
//Variables
private int xCanvas = 600;
private int yCanvas = 600;
private Board board;
GameGui(Board board) {
// Button that starts a new frame
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JLabel label = new JLabel();
label.setFont(new Font("Tahoma", Font.BOLD, 15));
// Displays the Game
gamePanel1.setBackground(Color.WHITE);
gamePanel1.setPreferredSize(new Dimension(1000, 200));
//Creates the information Panel
createInfoPanel();
// Buttons for buy, upgrade towers
buttonPanel.setLayout(new GridLayout(0, 1, 2, 2));
buttonPanel.setBackground(Color.white);
buttonPanel.setPreferredSize(new Dimension(100, 100));
buttonPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
buttonPanel.add(buyButton);
buttonPanel.add(upgradeButton);
buttonPanel.add(sellButton);
// Game functionality buttons
functionPanel.setLayout(new GridLayout(0, 1, 2, 2));
functionPanel.setPreferredSize(new Dimension(100, 100));
functionPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
functionPanel.add(pauseButton);
functionPanel.add(resumeButton);
functionPanel.add(quitButton);
// Panel that holds all other Panels
gameControl.setLayout(new BoxLayout(gameControl, BoxLayout.X_AXIS));
gameControl.add(infoPanel);
//gameControl.add(statPanel);
gameControl.add(functionPanel);
gameControl.setPreferredSize(new Dimension(1000, 200));
// Game Window
gameWindow.getContentPane().add(gamePanel1, "Center");
gameWindow.add(gameControl, BorderLayout.PAGE_END);
gameWindow.setSize(xCanvas, yCanvas + 200);
gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gameWindow.setVisible(true);
gameWindow.setResizable(false);
xCanvas = gamePanel1.getWidth();
yCanvas = gamePanel1.getHeight();
uiWindow.dispose();
}
});
// Button that exit the current frame
quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
uiWindow.dispose();
gameWindow.dispose();
System.exit(0);
}
});
uiPanel.setBorder(BorderFactory.createEmptyBorder(300, 300, 100, 300));
uiPanel.setLayout(new GridLayout(0, 1));
uiPanel.add(text);
uiPanel.add(startButton);
uiPanel.add(quitButton);
// set up the frame and display it
uiWindow.add(uiPanel, BorderLayout.CENTER);
uiWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
uiWindow.setTitle("Tower Defense Game");
uiWindow.pack();
uiWindow.setVisible(true);
}
public void createInfoPanel(){
// Display the game Infomation
infoPanel.removeAll();
goldLabel = new JLabel("GOLD: " + board.getBoardInstance().getGold());
healthLabel = new JLabel("Lives: " + board.getBoardInstance().getHealth());
WaveNumLabel = new JLabel("Current Wave: " + board.getBoardInstance().getWaveNum());
EnemyHealth = new JLabel("Enemy's Health: " + board.getBoardInstance().getEnemy().getHealth());
if(board.getBoardInstance().getTowerDamage() != null){
TowerDamage = new JLabel(board.getBoardInstance().getTowerDamage().toString());
}
infoPanel.setBackground(Color.white);
infoPanel.setPreferredSize(new Dimension(100, 100));
infoPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
infoPanel.add(goldLabel);
infoPanel.add(healthLabel);
infoPanel.add(WaveNumLabel);
infoPanel.add(EnemyHealth);
infoPanel.add(TowerDamage);
gameControl.revalidate();
gameControl.repaint();
gameControl.setVisible(true);
}
public void drawBoard(JPanel board) {
gameWindow.remove(gamePanel1);
gamePanel1 = board;
gameWindow.add(gamePanel1);
gameWindow.revalidate();
gameWindow.repaint();
gameWindow.setVisible(true);
}
public void drawInfoPage(JPanel infoPage) {
gameControl.remove(infoPanel);
infoPanel = infoPage;
gameControl.add(infoPanel);
gameControl.revalidate();
gameControl.repaint();
gameControl.setVisible(true);
}
}