|
|
@ -5,7 +5,7 @@ package cancergrowth;
|
|
|
|
* Created: Oct 02, 2017
|
|
|
|
* Created: Oct 02, 2017
|
|
|
|
* Author:
|
|
|
|
* Author:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*; // Import libraries we need
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
@ -15,13 +15,12 @@ import javax.swing.event.ChangeEvent;
|
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
|
|
|
|
|
|
|
import javazoom.jl.decoder.JavaLayerException;
|
|
|
|
import javazoom.jl.decoder.JavaLayerException;
|
|
|
|
import javazoom.jl.player.Player;
|
|
|
|
import javazoom.jl.player.Player;
|
|
|
|
|
|
|
|
|
|
|
|
public class CellPanel extends javax.swing.JPanel implements ActionListener, ChangeListener
|
|
|
|
public class CellPanel extends javax.swing.JPanel implements ActionListener, ChangeListener
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private Timer swingTimer;
|
|
|
|
private Timer swingTimer; // Declare and instantiate variables
|
|
|
|
private int delay;
|
|
|
|
private int delay;
|
|
|
|
private boolean growing = false;
|
|
|
|
private boolean growing = false;
|
|
|
|
private int count = 0;
|
|
|
|
private int count = 0;
|
|
|
@ -30,7 +29,8 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
private int cycle;
|
|
|
|
private int cycle;
|
|
|
|
private boolean cycledir = true;
|
|
|
|
private boolean cycledir = true;
|
|
|
|
Player player;
|
|
|
|
Player player;
|
|
|
|
ArrayList<Cell> cells = new ArrayList<Cell>(100000000);
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Cell> cells = new ArrayList<Cell>(100000000); // Limit us at 10,000,000 cells
|
|
|
|
|
|
|
|
|
|
|
|
public CellPanel()
|
|
|
|
public CellPanel()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -41,16 +41,16 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
//Cell t1 = new Cell(300, 100, Color.RED);
|
|
|
|
//Cell t1 = new Cell(300, 100, Color.RED);
|
|
|
|
//choice1.addItem(t1);
|
|
|
|
//choice1.addItem(t1);
|
|
|
|
//cells.add(t1);
|
|
|
|
//cells.add(t1);
|
|
|
|
Cell t2 = new Cell(475, 475);
|
|
|
|
Cell t2 = new Cell(475, 475); // Create the initial cell (would be inserted into blood stream)
|
|
|
|
//choice1.addItem(t2);
|
|
|
|
//choice1.addItem(t2);
|
|
|
|
cells.add(t2);
|
|
|
|
cells.add(t2); // add our cell to the ArrayList of cells
|
|
|
|
//choice2.addItem(t2);
|
|
|
|
//choice2.addItem(t2);
|
|
|
|
|
|
|
|
|
|
|
|
//choice1.setRenderer(new ComboBoxRenderer());
|
|
|
|
//choice1.setRenderer(new ComboBoxRenderer());
|
|
|
|
//choice2.setRenderer(new ComboBoxRenderer());
|
|
|
|
//choice2.setRenderer(new ComboBoxRenderer());
|
|
|
|
speed.setValue(250);
|
|
|
|
speed.setValue(250);
|
|
|
|
delay = speed.getValue();
|
|
|
|
delay = speed.getValue();
|
|
|
|
swingTimer = new Timer(delay, this);
|
|
|
|
swingTimer = new Timer(delay, this); // Use a timer to time the simulation
|
|
|
|
//swingTimer.start();
|
|
|
|
//swingTimer.start();
|
|
|
|
pacmanx = 1050;
|
|
|
|
pacmanx = 1050;
|
|
|
|
pacmany = -20;
|
|
|
|
pacmany = -20;
|
|
|
@ -59,7 +59,7 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
|
{
|
|
|
|
{ // Runs whenever the timer runs out (and starts over)
|
|
|
|
if (swingTimer.isRunning())
|
|
|
|
if (swingTimer.isRunning())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
speed.setEnabled(true);
|
|
|
|
speed.setEnabled(true);
|
|
|
@ -72,21 +72,17 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
swingTimer.start();
|
|
|
|
swingTimer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//canvas = new BufferedImage(1000, 1000, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
|
|
|
|
//g2 = canvas.getGraphics();
|
|
|
|
|
|
|
|
for (int k = 0; k < cells.size(); k++)
|
|
|
|
for (int k = 0; k < cells.size(); k++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Cell t = cells.get(k);
|
|
|
|
Cell t = cells.get(k);
|
|
|
|
Cell rec = t.performTime(!kill);
|
|
|
|
Cell rec = t.performTime(!kill); // Perform simulation for every cell using a loop
|
|
|
|
if (t != rec) {
|
|
|
|
if (t != rec) {
|
|
|
|
cells.add(rec);
|
|
|
|
cells.add(rec); // If performing the simulation results in a new daughter cell, add it to the list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//g2.drawImage(t.getImage(), t.getX(), t.getY(), this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//growing = true;
|
|
|
|
//growing = true;
|
|
|
|
if(!kill) count ++;
|
|
|
|
if(!kill) count ++; // Count how many hours have passed
|
|
|
|
//System.out.println("ACTION PERFORMED");
|
|
|
|
super.repaint(); // Redraw the screen so we can see the progress
|
|
|
|
super.repaint();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -99,47 +95,44 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
public void paintComponent(Graphics g)
|
|
|
|
public void paintComponent(Graphics g)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
super.paintComponent(g);
|
|
|
|
super.paintComponent(g);
|
|
|
|
//g.setColor(Color.BLACK);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int x = cells.size() - 1;
|
|
|
|
int x = cells.size() - 1;
|
|
|
|
//g.drawImage(canvas, 0, 0, this);
|
|
|
|
for (int k = x; k >= 0; k--) // Use a loop to draw each cell
|
|
|
|
for (int k = x; k >= 0; k--)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Cell t = cells.get(k);
|
|
|
|
Cell t = cells.get(k);
|
|
|
|
/*if(k > cells.size() / 4) {
|
|
|
|
/*if(k > cells.size() / 4) {
|
|
|
|
//g.setColor(t.getColor());
|
|
|
|
//g.setColor(t.getColor());
|
|
|
|
g.fillOval(t.getX(), t.getY(), 50, 50);
|
|
|
|
g.fillOval(t.getX(), t.getY(), 50, 50);
|
|
|
|
} else*/
|
|
|
|
} else*/
|
|
|
|
//if (cells.size() > 10000000) {
|
|
|
|
//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 && (Math.abs(pacmanx + 40 - t.getX()) < 50) && (Math.abs(pacmany + 25 - t.getY()) < 75)) {
|
|
|
|
cells.remove(t);
|
|
|
|
cells.remove(t); // If pacman is here, have him eat the cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else g.drawImage(t.getImage(), t.getX(), t.getY(), this);
|
|
|
|
else g.drawImage(t.getImage(), t.getX(), t.getY(), this); // otherwise, draw the cell
|
|
|
|
|
|
|
|
|
|
|
|
//swingTimer.stop();
|
|
|
|
//swingTimer.stop();
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(kill) {
|
|
|
|
if(kill) { // draw pacman if he needs to be drawn
|
|
|
|
//swingTimer.setDelay(100);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
pacmanx -= 10;
|
|
|
|
pacmanx -= 10; // move pacman
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
pacmanx = 1050;
|
|
|
|
pacmanx = 1050;
|
|
|
|
pacmany += 100;
|
|
|
|
pacmany += 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cycledir) cycle ++;
|
|
|
|
if (cycledir) cycle ++;
|
|
|
|
else cycle --;
|
|
|
|
else cycle --; // Open and close his mouth
|
|
|
|
if (cycle == 21) cycledir = false;
|
|
|
|
if (cycle == 21) cycledir = false;
|
|
|
|
if (cycle == 0) cycledir = true;
|
|
|
|
if (cycle == 0) cycledir = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pacmany > 1050) {
|
|
|
|
if(pacmany > 1050) {
|
|
|
|
while (!cells.isEmpty()) {
|
|
|
|
while (!cells.isEmpty()) {
|
|
|
|
cells.remove(0);
|
|
|
|
cells.remove(0); // make sure we got rid of every cell with pacman
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kill = false;
|
|
|
|
kill = false; // turn off pacman
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jLabel1.setText("Delay: " + delay + "ms. Hours since start: " + count + ". Cell Count: " + cells.size());
|
|
|
|
jLabel1.setText("Delay: " + delay + "ms. Hours since start: " + count + ". Cell Count: " + cells.size());
|
|
|
|
System.out.println("Cell Count: " + cells.size());
|
|
|
|
System.out.println("Cell Count: " + cells.size());
|
|
|
@ -151,7 +144,7 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
/** This method is called from within the constructor to initialize the form.
|
|
|
|
/** This method is called from within the constructor to initialize the form.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* WARNING: Do NOT modify this code by hand. The content of this method is
|
|
|
|
* WARNING: Do NOT modify this code by hand. The content of this method is
|
|
|
|
* always regenerated by the Form Editor.
|
|
|
|
* always regenerated by the Form Editor. Ignore this part! this just creates the buttons and slider
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
|
@ -230,23 +223,20 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
|
|
|
|
|
|
|
|
private void speedMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_speedMouseReleased
|
|
|
|
private void speedMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_speedMouseReleased
|
|
|
|
{//GEN-HEADEREND:event_speedMouseReleased
|
|
|
|
{//GEN-HEADEREND:event_speedMouseReleased
|
|
|
|
// TODO add your handling code here:
|
|
|
|
delay = speed.getValue(); // if the slider bar is moved, update the timing
|
|
|
|
delay = speed.getValue();
|
|
|
|
|
|
|
|
//swingTimer.setDelay(1000);
|
|
|
|
//swingTimer.setDelay(1000);
|
|
|
|
super.repaint();
|
|
|
|
super.repaint();
|
|
|
|
}//GEN-LAST:event_speedMouseReleased
|
|
|
|
}//GEN-LAST:event_speedMouseReleased
|
|
|
|
|
|
|
|
|
|
|
|
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
|
|
|
|
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
|
|
|
|
{//GEN-HEADEREND:event_jButton1ActionPerformed
|
|
|
|
{//GEN-HEADEREND:event_jButton1ActionPerformed
|
|
|
|
// TODO add your handling code here:
|
|
|
|
swingTimer.setDelay(delay); // When we press start, start the simulation
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
|
|
|
|
swingTimer.start();
|
|
|
|
swingTimer.start();
|
|
|
|
}//GEN-LAST:event_jButton1ActionPerformed
|
|
|
|
}//GEN-LAST:event_jButton1ActionPerformed
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
// TODO add your handling code here:
|
|
|
|
if(kill) { // if we press the kill button, then begin the killing
|
|
|
|
if(kill) {
|
|
|
|
|
|
|
|
kill = false;
|
|
|
|
kill = false;
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
swingTimer.setDelay(delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -256,13 +246,11 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
|
|
|
|
swingTimer.setDelay(10);
|
|
|
|
swingTimer.setDelay(10);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
FileInputStream fileInputStream = new FileInputStream("lib/pacman.mp3");
|
|
|
|
FileInputStream fileInputStream = new FileInputStream("lib/pacman.mp3");
|
|
|
|
Player player = new Player(fileInputStream);
|
|
|
|
Player player = new Player(fileInputStream); // play pacman sound effect
|
|
|
|
player.play();
|
|
|
|
player.play();
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace(); // catch any errors with the mp3
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (JavaLayerException e) {
|
|
|
|
} catch (JavaLayerException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|