|
|
@ -25,6 +25,7 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
private boolean growing = false;
|
|
|
|
private boolean growing = false;
|
|
|
|
private int count = 0;
|
|
|
|
private int count = 0;
|
|
|
|
private boolean kill = false;
|
|
|
|
private boolean kill = false;
|
|
|
|
|
|
|
|
private boolean dontkill = false;
|
|
|
|
private int pacmanx, pacmany;
|
|
|
|
private int pacmanx, pacmany;
|
|
|
|
private int cycle;
|
|
|
|
private int cycle;
|
|
|
|
private boolean cycledir = true;
|
|
|
|
private boolean cycledir = true;
|
|
|
@ -106,7 +107,7 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
g.fillOval(t.getX(), t.getY(), 50, 50);
|
|
|
|
g.fillOval(t.getX(), t.getY(), 50, 50);
|
|
|
|
} else*/
|
|
|
|
} else*/
|
|
|
|
//if (cells.size() > 10000000) { // we can simulate until 10000000 first to see what happens isntead of waiting
|
|
|
|
//if (cells.size() > 10000000) { // we can simulate until 10000000 first to see what happens isntead of waiting
|
|
|
|
if(kill && (Math.abs(pacmanx + 40 - t.getX()) < 50) && (Math.abs(pacmany + 25 - t.getY()) < 75)) {
|
|
|
|
if(kill && !dontkill && (Math.abs(pacmanx + 40 - t.getX()) < 50) && (Math.abs(pacmany + 25 - t.getY()) < 75)) {
|
|
|
|
cells.remove(t); // If pacman is here, have him eat the cell
|
|
|
|
cells.remove(t); // If pacman is here, have him eat the cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else g.drawImage(t.getImage(), t.getX(), t.getY(), this); // otherwise, draw the cell
|
|
|
|
else g.drawImage(t.getImage(), t.getX(), t.getY(), this); // otherwise, draw the cell
|
|
|
@ -114,7 +115,7 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
//swingTimer.stop();
|
|
|
|
//swingTimer.stop();
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(kill) { // draw pacman if he needs to be drawn
|
|
|
|
if(kill && !dontkill) { // draw pacman if he needs to be drawn
|
|
|
|
g.setColor(Color.YELLOW);
|
|
|
|
g.setColor(Color.YELLOW);
|
|
|
|
g.fillArc(pacmanx, pacmany, 100, 100, 220 - cycle * 2, 280 + cycle * 4);
|
|
|
|
g.fillArc(pacmanx, pacmany, 100, 100, 220 - cycle * 2, 280 + cycle * 4);
|
|
|
|
if (pacmanx > -100) {
|
|
|
|
if (pacmanx > -100) {
|
|
|
@ -155,6 +156,7 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
jLabel1 = new javax.swing.JLabel();
|
|
|
|
jLabel1 = new javax.swing.JLabel();
|
|
|
|
jButton1 = new javax.swing.JButton();
|
|
|
|
jButton1 = new javax.swing.JButton();
|
|
|
|
jButton2 = new javax.swing.JButton();
|
|
|
|
jButton2 = new javax.swing.JButton();
|
|
|
|
|
|
|
|
jButton3 = new javax.swing.JButton();
|
|
|
|
|
|
|
|
|
|
|
|
speed.setMaximum(1000);
|
|
|
|
speed.setMaximum(1000);
|
|
|
|
speed.setMinimum(1);
|
|
|
|
speed.setMinimum(1);
|
|
|
@ -192,6 +194,16 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jButton3.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
|
|
|
|
|
|
|
|
jButton3.setText("Stable");
|
|
|
|
|
|
|
|
jButton3.addActionListener(new java.awt.event.ActionListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
jButton3ActionPerformed(evt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
|
|
|
|
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
|
|
|
|
this.setLayout(layout);
|
|
|
|
this.setLayout(layout);
|
|
|
|
layout.setHorizontalGroup(
|
|
|
|
layout.setHorizontalGroup(
|
|
|
@ -201,7 +213,9 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
.add(speed, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
|
|
|
.add(speed, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.add(jLabel1)
|
|
|
|
.add(jLabel1)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 593, Short.MAX_VALUE)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 513, Short.MAX_VALUE)
|
|
|
|
|
|
|
|
.add(jButton3)
|
|
|
|
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
|
|
|
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
|
|
|
|
.add(jButton1)
|
|
|
|
.add(jButton1)
|
|
|
@ -215,7 +229,8 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
|
|
|
|
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
|
|
|
|
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
|
|
|
|
.add(jLabel1)
|
|
|
|
.add(jLabel1)
|
|
|
|
.add(jButton2))
|
|
|
|
.add(jButton2)
|
|
|
|
|
|
|
|
.add(jButton3))
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, speed, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
|
|
.add(org.jdesktop.layout.GroupLayout.LEADING, speed, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
|
|
.addContainerGap(959, Short.MAX_VALUE))
|
|
|
|
.addContainerGap(959, Short.MAX_VALUE))
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -236,13 +251,26 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
|
|
|
|
|
|
|
|
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
|
|
|
|
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
|
|
|
|
{//GEN-HEADEREND:event_jButton2ActionPerformed
|
|
|
|
{//GEN-HEADEREND:event_jButton2ActionPerformed
|
|
|
|
if(kill) { // if we press the kill button, then begin the killing
|
|
|
|
if(dontkill) {
|
|
|
|
|
|
|
|
dontkill = false;
|
|
|
|
|
|
|
|
kill = true;
|
|
|
|
|
|
|
|
swingTimer.setDelay(10);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
FileInputStream fileInputStream = new FileInputStream("lib/pacman.mp3");
|
|
|
|
|
|
|
|
Player player = new Player(fileInputStream); // play pacman sound effect
|
|
|
|
|
|
|
|
player.play();
|
|
|
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
|
|
|
e.printStackTrace(); // catch any errors with the mp3
|
|
|
|
|
|
|
|
} catch (JavaLayerException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(kill) { // if we press the kill button, then begin the killing
|
|
|
|
kill = false;
|
|
|
|
kill = false;
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
kill = true;
|
|
|
|
kill = true;
|
|
|
|
|
|
|
|
|
|
|
|
swingTimer.setDelay(10);
|
|
|
|
swingTimer.setDelay(10);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
FileInputStream fileInputStream = new FileInputStream("lib/pacman.mp3");
|
|
|
|
FileInputStream fileInputStream = new FileInputStream("lib/pacman.mp3");
|
|
|
@ -256,10 +284,18 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}//GEN-LAST:event_jButton2ActionPerformed
|
|
|
|
}//GEN-LAST:event_jButton2ActionPerformed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton3ActionPerformed
|
|
|
|
|
|
|
|
{//GEN-HEADEREND:event_jButton3ActionPerformed
|
|
|
|
|
|
|
|
// TODO add your handling code here:
|
|
|
|
|
|
|
|
kill = true;
|
|
|
|
|
|
|
|
dontkill = true;
|
|
|
|
|
|
|
|
}//GEN-LAST:event_jButton3ActionPerformed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
|
|
private javax.swing.JButton jButton1;
|
|
|
|
private javax.swing.JButton jButton1;
|
|
|
|
private javax.swing.JButton jButton2;
|
|
|
|
private javax.swing.JButton jButton2;
|
|
|
|
|
|
|
|
private javax.swing.JButton jButton3;
|
|
|
|
private javax.swing.JLabel jLabel1;
|
|
|
|
private javax.swing.JLabel jLabel1;
|
|
|
|
private javax.swing.JSlider speed;
|
|
|
|
private javax.swing.JSlider speed;
|
|
|
|
// End of variables declaration//GEN-END:variables
|
|
|
|
// End of variables declaration//GEN-END:variables
|
|
|
|