-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacmanFrame.java
More file actions
257 lines (212 loc) · 10.5 KB
/
PacmanFrame.java
File metadata and controls
257 lines (212 loc) · 10.5 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author francisco
*/
public class PacmanFrame extends javax.swing.JFrame {
private Cronometro crono;
private Thread t_puntos;
public PacmanFrame() {
initComponents();
crono = new Cronometro(tiempo);
t_puntos = new Thread(new Runnable(){
public void run(){
while(true){
puntos.setText(mapa.getPuntuacion()+" puntos");
if(mapa.isFinished())
crono.parar();
vidas.setText(mapa.getVidasComecocos()+ " vidas");
try {
Thread.sleep(200);
} catch (InterruptedException ex) {
Logger.getLogger(PacmanFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
t_puntos.start();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
acerca_de = new javax.swing.JDialog();
titulo = new javax.swing.JLabel();
logo = new javax.swing.JLabel();
cuerpo = new javax.swing.JLabel();
ayuda_dialogo = new javax.swing.JDialog();
titulo1 = new javax.swing.JLabel();
cuerpo1 = new javax.swing.JLabel();
central = new javax.swing.JPanel();
mapa = new Mapa();
barra_estado = new javax.swing.JPanel();
p_tiempo = new javax.swing.JPanel();
tiempo = new javax.swing.JLabel();
p_puntos = new javax.swing.JPanel();
puntos = new javax.swing.JLabel();
p_vidas = new javax.swing.JPanel();
vidas = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
FileMenu = new javax.swing.JMenu();
NewItem = new javax.swing.JMenuItem();
ExitItem = new javax.swing.JMenuItem();
HelpMenu = new javax.swing.JMenu();
AboutItem = new javax.swing.JMenuItem();
ayuda = new javax.swing.JMenuItem();
acerca_de.setTitle("Acerca de");
acerca_de.setAlwaysOnTop(true);
acerca_de.setMinimumSize(new java.awt.Dimension(550, 400));
acerca_de.setResizable(false);
acerca_de.getContentPane().setLayout(new java.awt.FlowLayout());
titulo.setText("<html><h1>Rones & Gijon's Development</h1>");
acerca_de.getContentPane().add(titulo);
logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/logo.png"))); // NOI18N
logo.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 4, true));
acerca_de.getContentPane().add(logo);
cuerpo.setText("<html><h2>Desarrolladores:</h2><ul><li>Aarón Rosas</li><li>Francisco Javier Gijón</li></ul><p>Estudiantes de Ingeniería Técnica en Informática de Sistemas, en Granada.</p><p>Práctica de la asignatura: Nuevas Tecnologías de la Programación.</p><p>Curso: 2010-2011</p></html>");
acerca_de.getContentPane().add(cuerpo);
ayuda_dialogo.setTitle("Acerca de");
ayuda_dialogo.setAlwaysOnTop(true);
ayuda_dialogo.setMinimumSize(new java.awt.Dimension(750, 400));
ayuda_dialogo.setResizable(false);
ayuda_dialogo.getContentPane().setLayout(new java.awt.FlowLayout());
titulo1.setText("<html><h1>Pacman v1.5 Beta</h1>");
ayuda_dialogo.getContentPane().add(titulo1);
cuerpo1.setText("<html><h2>Elementos</h2><ul><li>Cocos (puntos pequeños)</li><li>SuperCocos (puntos grandes)</li><li>Fantasmas</li><li>Comecocos</li><h2>Objetivo</h2><p>Capturar todos los cocos del mapa</p><h2>Bases</h2><p>Comerse un SuperCoco permitirá al comecocos capturar fantasmas durante un tiempo limitado</p><p>Comer fantasmas incrementará la puntuación</p><p>Cuantos más fantamas se capturen durante un mismo periodo, mejor será la bonificación</p>");
ayuda_dialogo.getContentPane().add(cuerpo1);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Pacman");
getContentPane().setLayout(new java.awt.BorderLayout(0, 5));
mapa.setBorder(new javax.swing.border.MatteBorder(null));
javax.swing.GroupLayout mapaLayout = new javax.swing.GroupLayout(mapa);
mapa.setLayout(mapaLayout);
mapaLayout.setHorizontalGroup(
mapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 558, Short.MAX_VALUE)
);
mapaLayout.setVerticalGroup(
mapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 618, Short.MAX_VALUE)
);
central.add(mapa);
getContentPane().add(central, java.awt.BorderLayout.CENTER);
barra_estado.setPreferredSize(new java.awt.Dimension(560, 20));
barra_estado.setLayout(new java.awt.GridLayout(1, 3));
p_tiempo.setLayout(new java.awt.GridBagLayout());
tiempo.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
tiempo.setText("00:00");
tiempo.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
tiempo.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
tiempo.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
p_tiempo.add(tiempo, new java.awt.GridBagConstraints());
barra_estado.add(p_tiempo);
p_puntos.setLayout(new java.awt.GridBagLayout());
puntos.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
puntos.setText("00:00");
puntos.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
puntos.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
p_puntos.add(puntos, new java.awt.GridBagConstraints());
barra_estado.add(p_puntos);
p_vidas.setLayout(new java.awt.GridBagLayout());
vidas.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
vidas.setText("00:00");
vidas.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
vidas.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
vidas.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
p_vidas.add(vidas, new java.awt.GridBagConstraints());
barra_estado.add(p_vidas);
getContentPane().add(barra_estado, java.awt.BorderLayout.SOUTH);
FileMenu.setText("Archivo");
NewItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
NewItem.setText("Nuevo");
NewItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
NewItemActionPerformed(evt);
}
});
FileMenu.add(NewItem);
ExitItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
ExitItem.setText("Salir");
ExitItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ExitItemActionPerformed(evt);
}
});
FileMenu.add(ExitItem);
jMenuBar1.add(FileMenu);
HelpMenu.setText("Ayuda");
AboutItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
AboutItem.setText("Acerca de");
AboutItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AboutItemActionPerformed(evt);
}
});
HelpMenu.add(AboutItem);
ayuda.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
ayuda.setText("Ayuda");
ayuda.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ayudaActionPerformed(evt);
}
});
HelpMenu.add(ayuda);
jMenuBar1.add(HelpMenu);
setJMenuBar(jMenuBar1);
pack();
}// </editor-fold>//GEN-END:initComponents
private void NewItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NewItemActionPerformed
mapa.iniciarJuego();
crono.parar();
crono = new Cronometro(tiempo);
}//GEN-LAST:event_NewItemActionPerformed
private void ExitItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitItemActionPerformed
System.exit(0);
}//GEN-LAST:event_ExitItemActionPerformed
private void ayudaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ayudaActionPerformed
ayuda_dialogo.setVisible(true);
}//GEN-LAST:event_ayudaActionPerformed
private void AboutItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutItemActionPerformed
acerca_de.setVisible(true);
}//GEN-LAST:event_AboutItemActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PacmanFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem AboutItem;
private javax.swing.JMenuItem ExitItem;
private javax.swing.JMenu FileMenu;
private javax.swing.JMenu HelpMenu;
private javax.swing.JMenuItem NewItem;
private javax.swing.JDialog acerca_de;
private javax.swing.JMenuItem ayuda;
private javax.swing.JDialog ayuda_dialogo;
private javax.swing.JPanel barra_estado;
private javax.swing.JPanel central;
private javax.swing.JLabel cuerpo;
private javax.swing.JLabel cuerpo1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JLabel logo;
private Mapa mapa;
private javax.swing.JPanel p_puntos;
private javax.swing.JPanel p_tiempo;
private javax.swing.JPanel p_vidas;
private javax.swing.JLabel puntos;
private javax.swing.JLabel tiempo;
private javax.swing.JLabel titulo;
private javax.swing.JLabel titulo1;
private javax.swing.JLabel vidas;
// End of variables declaration//GEN-END:variables
}