add pacman support

master
ThirstyShark 5 years ago
parent 2062b15346
commit 84ca2f8b8f

@ -1,4 +1,4 @@
#Mon, 04 Feb 2019 21:13:01 -0600
#Tue, 05 Feb 2019 17:51:51 -0600
C\:\\Users\\cd109\\Desktop\\CancerGrowth=

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -15,7 +15,6 @@ import java.util.Scanner;
* Created: Nov 7, 2018
* Author:
*/
public class Cell extends Object
{
@ -24,6 +23,7 @@ public class Cell extends Object
private ArrayList<Integer> stages = new ArrayList<Integer>();
private int currentStage;
private int currentTime;
private static final BufferedImage p0;
private static BufferedImage[] p1 = new BufferedImage[12];
private static final BufferedImage p2;
private static final BufferedImage p3;
@ -36,8 +36,14 @@ public class Cell extends Object
{
BufferedImage g1 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics gg1 = g1.getGraphics();
if (transparent) gg1.setColor(new Color(255, 0, 0, 127));
else gg1.setColor(new Color(255, 0, 0));
if (transparent)
{
gg1.setColor(new Color(255, 0, 0, 127));
}
else
{
gg1.setColor(new Color(255, 0, 0));
}
int width;
int pos;
width = (int) ((count + 1) * 2 + 22.5);
@ -51,8 +57,14 @@ public class Cell extends Object
BufferedImage s = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics gs = s.getGraphics();
if (transparent) gs.setColor(new Color(255, 255, 0, 127));
else gs.setColor(new Color(255, 255, 0));
if (transparent)
{
gs.setColor(new Color(255, 255, 0, 127));
}
else
{
gs.setColor(new Color(255, 255, 0));
}
gs.fillOval(0, 0, 50, 50);
gs.setColor(Color.BLACK);
gs.drawOval(0, 0, 50, 50);
@ -60,8 +72,14 @@ public class Cell extends Object
p2 = s;
BufferedImage g2 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics gg2 = g2.getGraphics();
if (transparent) gg2.setColor(new Color(0, 255, 0, 127));
else gg2.setColor(new Color(0, 255, 0));
if (transparent)
{
gg2.setColor(new Color(0, 255, 0, 127));
}
else
{
gg2.setColor(new Color(0, 255, 0));
}
gg2.fillOval(0, 0, 50, 50);
gg2.setColor(Color.BLACK);
gg2.drawOval(0, 0, 50, 50);
@ -69,13 +87,34 @@ public class Cell extends Object
p3 = g2;
BufferedImage m = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics gm = m.getGraphics();
if (transparent) gm.setColor(new Color(0, 0, 255, 127));
else gm.setColor(new Color(0, 0, 255));
if (transparent)
{
gm.setColor(new Color(0, 0, 255, 127));
}
else
{
gm.setColor(new Color(0, 0, 255));
}
gm.fillOval(0, 0, 50, 50);
gm.setColor(Color.BLACK);
gm.drawOval(0, 0, 50, 50);
gm.drawString("M", 22, 30);
p4 = m;
BufferedImage g0 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics gg0 = g0.getGraphics();
if (transparent)
{
gg0.setColor(new Color(80, 80, 80, 127));
}
else
{
gm.setColor(new Color(80, 80, 80));
}
gg0.fillOval(0, 0, 50, 50);
gg0.setColor(Color.BLACK);
gg0.drawOval(0, 0, 50, 50);
gg0.drawString("G0", 18, 30);
p0 = g0;
}
public Cell(int x, int y)
@ -104,8 +143,24 @@ public class Cell extends Object
{
return myColor;
}*/
public Cell performTime()
public Cell performTime(boolean run)
{
if (!run || currentStage == 4)
{
if (run)
{
currentStage = 0;
}
else
{
int random = (int) (Math.random() * 10);
if (random == 0)
{
currentStage = 4;
}
return this;
}
}
this.currentTime++;
Cell newcell = this;
//System.out.println("Increased Current Time to:" + this.currentTime);
@ -162,8 +217,11 @@ public class Cell extends Object
{
return p3;
}
return p4;
if (currentStage == 3)
{
return p4;
}
return p0;
}
}

@ -21,7 +21,9 @@
<Component id="speed" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="662" max="32767" attributes="0"/>
<EmptySpace pref="593" max="32767" attributes="0"/>
<Component id="jButton2" min="-2" pref="63" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
</Group>
@ -35,10 +37,11 @@
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
<Component id="jButton1" alignment="3" pref="0" max="32767" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="speed" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace pref="967" max="32767" attributes="0"/>
<EmptySpace pref="959" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -75,5 +78,16 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton2">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="14" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Kill"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

@ -8,12 +8,8 @@ package cancergrowth;
import java.util.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@ -24,12 +20,12 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
private int delay;
private boolean growing = false;
private int count = 0;
private boolean draw = false;
private boolean kill = false;
private int pacmanx, pacmany;
private int cycle;
private boolean cycledir = true;
ArrayList<Cell> cells = new ArrayList<Cell>(10000000);
Graphics g2;
Image canvas;
ArrayList<Cell> cells = new ArrayList<Cell>(100000000);
public CellPanel()
{
@ -51,6 +47,8 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
delay = speed.getValue();
swingTimer = new Timer(delay, this);
//swingTimer.start();
pacmanx = 1050;
pacmany = -20;
}
@Override
@ -73,14 +71,14 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
for (int k = 0; k < cells.size(); k++)
{
Cell t = cells.get(k);
Cell rec = t.performTime();
Cell rec = t.performTime(!kill);
if (t != rec) {
cells.add(rec);
}
//g2.drawImage(t.getImage(), t.getX(), t.getY(), this);
}
growing = true;
count ++;
//growing = true;
if(!kill) count ++;
//System.out.println("ACTION PERFORMED");
super.repaint();
@ -107,15 +105,39 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
//g.setColor(t.getColor());
g.fillOval(t.getX(), t.getY(), 50, 50);
} else*/
//if (draw || cells.size() > 10000000) {
g.drawImage(t.getImage(), t.getX(), t.getY(), this);
//if (cells.size() > 10000000) {
if(kill && (Math.abs(pacmanx + 40 - t.getX()) < 50) && (Math.abs(pacmany + 25 - t.getY()) < 75)) {
cells.remove(t);
}
else g.drawImage(t.getImage(), t.getX(), t.getY(), this);
//swingTimer.stop();
//}
}
if(kill) {
//swingTimer.setDelay(100);
g.setColor(Color.YELLOW);
g.fillArc(pacmanx, pacmany, 100, 100, 220 - cycle * 2, 280 + cycle * 4);
if (pacmanx > -100) {
pacmanx -= 10;
} else {
pacmanx = 1050;
pacmany += 100;
}
if (cycledir) cycle ++;
else cycle --;
if (cycle == 21) cycledir = false;
if (cycle == 0) cycledir = true;
}
if(pacmany > 1050) {
while (!cells.isEmpty()) {
cells.remove(0);
}
kill = false;
}
jLabel1.setText("Delay: " + delay + "ms. Hours since start: " + count + ". Cell Count: " + cells.size());
System.out.println("Cell Count: " + cells.size());
growing = false;
//growing = false;
}
@ -126,13 +148,14 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents()
{
speed = new javax.swing.JSlider();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
speed.setMaximum(1000);
speed.setMinimum(1);
@ -160,6 +183,16 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
}
});
jButton2.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
jButton2.setText("Kill");
jButton2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton2ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@ -169,7 +202,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)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 662, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 593, Short.MAX_VALUE)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton1)
.add(18, 18, 18))
);
@ -180,33 +215,47 @@ public class CellPanel extends javax.swing.JPanel implements ActionListener, Cha
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.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(jLabel1))
.add(jLabel1)
.add(jButton2))
.add(org.jdesktop.layout.GroupLayout.LEADING, speed, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(967, Short.MAX_VALUE))
.addContainerGap(959, Short.MAX_VALUE))
);
}// </editor-fold>
}// </editor-fold>//GEN-END:initComponents
private void speedMouseReleased(java.awt.event.MouseEvent evt)
{
private void speedMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_speedMouseReleased
{//GEN-HEADEREND:event_speedMouseReleased
// TODO add your handling code here:
delay = speed.getValue();
//swingTimer.setDelay(1000);
super.repaint();
}
}//GEN-LAST:event_speedMouseReleased
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
{//GEN-HEADEREND:event_jButton1ActionPerformed
// TODO add your handling code here:
swingTimer.setDelay(delay);
swingTimer.start();
}
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
{//GEN-HEADEREND:event_jButton2ActionPerformed
// TODO add your handling code here:
if(kill) {
kill = false;
swingTimer.setDelay(delay);
}
else {
kill = true;
swingTimer.setDelay(25);
}
}//GEN-LAST:event_jButton2ActionPerformed
// Variables declaration - do not modify
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JSlider speed;
// End of variables declaration
// End of variables declaration//GEN-END:variables
}

Binary file not shown.
Loading…
Cancel
Save