package com.droidquest.devices; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Vector; import javax.swing.ImageIcon; import com.droidquest.Room; import com.droidquest.Wire; import com.droidquest.chipstuff.ChipCompiler; import com.droidquest.chipstuff.Gate; import com.droidquest.chipstuff.Port; import com.droidquest.chipstuff.PortSignal; import com.droidquest.chipstuff.Signal; import com.droidquest.decorations.TextBox; import com.droidquest.materials.ChipTester; import com.droidquest.materials.ChipTrash; import com.droidquest.materials.SmallChipBurner; public class SmallChip extends GenericChip { public int speed; public transient PortSignal[] portSignals = new PortSignal[8]; public Vector signals = new Vector(); public Vector gates = new Vector(); public SmallChip(int X, int Y, Room r, String l) { x=X; y=Y; room=r; label = l; width=26; height=30; speed=1; GenerateIcons(); for (int a=0; a<8; a++) portSignals[a] = new PortSignal(); } public void GenerateIcons() { if (ports==null) { ports = new Port[8]; ports[0] = new Port(0,3,Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this); ports[1] = new Port(0,11,Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this); ports[2] = new Port(0,19,Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this); ports[3] = new Port(0,27,Port.TYPE_UNDEFINED, 0, Port.ROT_LEFT, this); ports[4] = new Port(25,26,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this); ports[5] = new Port(25,18,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this); ports[6] = new Port(25,10,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this); ports[7] = new Port(25,2,Port.TYPE_UNDEFINED, 0, Port.ROT_RIGHT, this); } ChipText chiptext = new ChipText(this); chiptext.setTitle("Pinout for Chip " + label); if (portSignals == null) { portSignals = new PortSignal[8]; for (int a=0; a<8; a++) portSignals[a] = new PortSignal(); } icons = new ImageIcon[1]; icons[0] = new ImageIcon( new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR)); Graphics g; try { g = icons[0].getImage().getGraphics(); } catch (NullPointerException e) { System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); return; } Graphics2D g2 = (Graphics2D) g; g2.setBackground(transparent); g2.clearRect(0,0,width,height); g.setColor(Color.blue); g.fillRect(4,0,18,30); g.fillRect(0,2,26,2); g.fillRect(0,10,26,2); g.fillRect(0,18,26,2); g.fillRect(0,26,26,2); g.setColor(Color.black); Font font = new Font("Courier",Font.BOLD, 20); g.setFont(font); FontMetrics fm = g.getFontMetrics(); label = String.valueOf(label.charAt(0)); int X = fm.stringWidth(label); g.drawString(label, 13-X/2, 22); currentIcon = icons[0].getImage(); } public void writeRef(ObjectOutputStream s) throws IOException { super.writeRef(s); for (int a=0; a<8; a++) { s.writeInt(signals.indexOf(portSignals[a].internalSignal)); s.writeInt(portSignals[a].type); } for (int a=0; a=0) portSignals[a].internalSignal = (Signal) signals.elementAt(portIndex); portSignals[a].type = s.readInt(); } for (int a=0; a=0) gate.portSignals[b].externalSignal = (Signal) signals.elementAt(sigIndex); gate.portSignals[b].type = s.readInt(); } gate.readRef(s); } } public void Decorate() {} public void IsDropped() { inBurner = false; inTester = false; int bigXl = (x)/28; int bigXr = (x+width-1)/28; int bigYt = (y)/32; int bigYb = (y+height-1)/32; if (bigXr>19) bigXr=19; if (bigYb>11) bigYb=11; for (int a=bigYt; a<=bigYb; a++) for (int b=bigXl; b<=bigXr; b++) { if (room.MaterialArray[a][b] instanceof SmallChipBurner) { a=bigYb; b=bigXr; x = 13*28 - width/2; y = 8*32 - height/2; inBurner=true; ChipCompiler.chipSpeed = speed; TextBox tb = (TextBox) room.textBoxes.elementAt(1); tb.textString= speed + "x"; return; } if (room.MaterialArray[a][b] instanceof ChipTrash) { SetRoom(null); // Cheap way to remove the wires; level.items.removeElement(this); level.PlaySound(room,level.DISCHARGESOUND); return; } if (room.MaterialArray[a][b] instanceof ChipTester) { a=bigYb; b=bigXr; x = 10*28-width/2; y = 5*32-height/2; inTester=true; return; } } } public boolean Function() { int a; for (int s=0; s=0) gate.portSignals[b].externalSignal = (Signal) signals.elementAt(sigIndex); gate.portSignals[b].type = s.readInt(); } if (gate.type.equalsIgnoreCase("Chip")) gate.LoadSubGate(s); } // PortSignals for (int a=0; a<8; a++) { int sigIndex = s.readInt(); if (sigIndex>=0) portSignals[a].internalSignal = (Signal) signals.elementAt(sigIndex); ports[a].type = s.readInt(); portSignals[a].type = ports[a].type; } // Description description = (String) s.readObject(); // Speed speed = s.readInt(); s.close(); in.close(); } catch (ClassNotFoundException e) {} catch (FileNotFoundException e) { System.out.println("File Not Found"); return; } catch (IOException e) { System.out.println("IO Exception"); System.out.println(e.getMessage()); e.printStackTrace(); return; } // Debug report // System.out.println(signals.size() + " Signals"); // System.out.println(gates.size() + " Gates"); // for(int a=0; a