package com.droidquest.materials; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import com.droidquest.Room; import com.droidquest.items.BinaryKey; import com.droidquest.items.Item; public class BinaryLock extends Material { // Binary shaped Generic Lock; Used to redefine materials in the local room. int doorState=0; transient BinaryKey latchKey = null; transient Room room; transient Room currentRoom; static public int NARROW = -1; static public int WIDE = -2; static public int REMOVE = -3; static public int RESET = -4; static public int LEFT = -5; static public int RIGHT = -6; static public int UP = -7; static public int DOWN = -8; int[][] program; // program[][] is an array of arrays. Each array holds the behavior of a // single value of doorState. // // A single array can hold one of the following: // A single value of Lock.NARROW, Lock.WIDE, or Lock.REMOVE to define a pause // A single value of RESET, LEFT, RIGHT, UP, or DOWN to change rooms // A series of triplets (X,Y,M) with the XY position and the Materials // Index. // // Pause value can be one of the following: // Lock.NARROW = Pause until the key is placed once more precisely into the lock. // Lock.WIDE = Pause until the key is placed ANYWHERE into the lock // Lock.REMOVE = Pause until the key is removed. // // Pause values automatically reset the current Room to the original value. // // Lock.RESET = Set current room to the original room value // Lock.LEFT = Change the current room to the room's left room // Lock.RIGHT = Same, but right // Lock.UP = Same, but up // Lock.DOWN = Same, but down // // The room is normally the key's rom when the key touches the lock, and // the triplets change the materials within the current room. With these // commands the current room can be changed so other rooms can be // manipulated. // // Here's a sample program[][] // // int[][] = { // {Lock.NARROW}, // Wait for precise placement // {10,5,0, 11,5,0}, // Converts two spots to holes // {10,6,0, 11,6,0}, // Same, but lower // {Lock.NARROW}, // Wait again // {10,6,1, 11,6,1}, // Converts two spots to wall // {10,5,1, 11,5,1} // same, in reverse, go to pause. // }; // public BinaryLock(Color lc, int[][] prg) { super(true, false); color = lc; program = prg; GenerateIcons(); } public void GenerateIcons() { BufferedImage bi = new BufferedImage(28,32,BufferedImage.TYPE_4BYTE_ABGR); Graphics g; try { g = bi.getGraphics(); } catch (NullPointerException e) { System.out.println("Could not get Graphics pointer to " + getClass() + "Image"); return; } g.setColor(color); g.fillRect(0,0,28,32); g.setColor(Color.black); g.fillRect(16,2,4,8); g.fillRect(16,12,4,2); g.fillRect(12,14,4,4); g.fillRect(20,14,4,4); g.fillRect(16,18,4,2); g.fillRect(16,22,4,8); g.fillRect(24,4,4,4); g.fillRect(24,24,4,4); icon = new ImageIcon(bi); } public boolean equals(Material mat) { if (super.equals(mat)) if (program == ((BinaryLock)mat).program) return true; return false; } public void Animate() { if (doorState == program.length) doorState = 0; if (latchKey==null) return; if (program[doorState].length > 1) { for (int a=0; a=10 && X <=14 && Y<=4) doorState++; } else if (program[doorState][0]==WIDE) { currentRoom = room; doorState++; } } if (doorState == program.length) doorState = 0; } }