package com.droidquest.materials; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.util.Date; import javax.swing.ImageIcon; import com.droidquest.Room; import com.droidquest.items.Item; public class MultiSwitch extends Material { public int number; //0=starter, 1,2,3,4=pistons transient ImageIcon images[]; static int[] states = {0,0,0,0,0}; //0=Blue, 1=White, 2=Orange public Date timeout; transient Room room=null; public MultiSwitch(int n, int s) { super(true, false); number = n; states[number] = s; } public void GenerateIcons() { images = new ImageIcon[3]; for (int a=0; a<3; a++) { images[a] = new ImageIcon(new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR)); Graphics g; try { g = images[a].getImage().getGraphics(); } catch (NullPointerException e) { System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); return; } Graphics2D g2 = (Graphics2D) g; g2.setBackground(Color.black); g2.clearRect(0,0,28,32); if (a==0) g2.setColor(Color.blue); else if (a==1) g2.setColor(Color.white); else if (a==2) g2.setColor(new Color(255,128,0)); g2.fillRect(12,4,6,24); g2.fillRect(18,12,10,8); } icon = images[0]; } public void TouchedByItem(Item item) { if (room==null) room = item.room; if (number==0) { if (states[0]!=2) { states[0]=2; states[1]=1; states[2]=1; states[3]=1; states[4]=1; timeout = new Date(new Date().getTime() + 5000); } } else { boolean okay = true; if (states[0]<2) okay=false; for (int a=1; a timeout.getTime()) { states[0]=0; states[1]=0; states[2]=0; states[3]=0; states[4]=0; } } } public boolean equals(Material mat) { if (super.equals(mat)) if (number == ((MultiSwitch)mat).number) return true; return false; } }