Browse Source

Refactored and cleaned up code. Modernized some constructs.

tags/2.7
cognitivegears 5 years ago
parent
commit
0786afb4d9
100 changed files with 14009 additions and 14704 deletions
  1. 118
    162
      src/com/droidquest/DQ.java
  2. 309
    344
      src/com/droidquest/Room.java
  3. 454
    548
      src/com/droidquest/RoomDisplay.java
  4. 15
    19
      src/com/droidquest/SoundClip.java
  5. 381
    418
      src/com/droidquest/Wire.java
  6. 744
    759
      src/com/droidquest/avatars/GameCursor.java
  7. 33
    37
      src/com/droidquest/avatars/HelpCam.java
  8. 390
    409
      src/com/droidquest/avatars/LabCursor.java
  9. 285
    260
      src/com/droidquest/avatars/PaintBrush.java
  10. 226
    304
      src/com/droidquest/avatars/Remote.java
  11. 476
    516
      src/com/droidquest/avatars/SolderingPen.java
  12. 176
    193
      src/com/droidquest/chipstuff/ChipCompiler.java
  13. 244
    287
      src/com/droidquest/chipstuff/Gate.java
  14. 177
    180
      src/com/droidquest/chipstuff/Port.java
  15. 6
    6
      src/com/droidquest/chipstuff/PortSignal.java
  16. 21
    22
      src/com/droidquest/chipstuff/Signal.java
  17. 44
    46
      src/com/droidquest/decorations/Arrow.java
  18. 114
    112
      src/com/droidquest/decorations/Graphix.java
  19. 38
    34
      src/com/droidquest/decorations/Spark.java
  20. 19
    18
      src/com/droidquest/decorations/TextBox.java
  21. 164
    160
      src/com/droidquest/devices/ANDGate.java
  22. 172
    183
      src/com/droidquest/devices/Antenna.java
  23. 230
    230
      src/com/droidquest/devices/Bumper.java
  24. 64
    78
      src/com/droidquest/devices/ChipText.java
  25. 140
    148
      src/com/droidquest/devices/ContactSensor.java
  26. 175
    196
      src/com/droidquest/devices/Device.java
  27. 115
    138
      src/com/droidquest/devices/DirectionalSensor.java
  28. 187
    174
      src/com/droidquest/devices/FlipFlop.java
  29. 20
    23
      src/com/droidquest/devices/GenericChip.java
  30. 137
    153
      src/com/droidquest/devices/Grabber.java
  31. 147
    148
      src/com/droidquest/devices/NOTGate.java
  32. 139
    139
      src/com/droidquest/devices/Node.java
  33. 180
    170
      src/com/droidquest/devices/ORGate.java
  34. 44
    48
      src/com/droidquest/devices/PortDevice.java
  35. 241
    254
      src/com/droidquest/devices/Prototype16Chip.java
  36. 303
    320
      src/com/droidquest/devices/Prototype32Chip.java
  37. 250
    269
      src/com/droidquest/devices/PrototypeChip.java
  38. 144
    156
      src/com/droidquest/devices/RoomSensor.java
  39. 359
    409
      src/com/droidquest/devices/SmallChip.java
  40. 73
    82
      src/com/droidquest/devices/StormShield.java
  41. 202
    210
      src/com/droidquest/devices/Thruster.java
  42. 179
    171
      src/com/droidquest/devices/XORGate.java
  43. 351
    329
      src/com/droidquest/items/AmpireBot.java
  44. 147
    166
      src/com/droidquest/items/AutoWire.java
  45. 46
    51
      src/com/droidquest/items/BinaryKey.java
  46. 37
    41
      src/com/droidquest/items/BlackCrystal.java
  47. 47
    51
      src/com/droidquest/items/BlueRobot.java
  48. 106
    114
      src/com/droidquest/items/Burner.java
  49. 38
    40
      src/com/droidquest/items/Button.java
  50. 28
    32
      src/com/droidquest/items/CamDisk.java
  51. 404
    440
      src/com/droidquest/items/ChipDecompiler.java
  52. 98
    104
      src/com/droidquest/items/Crystal.java
  53. 67
    76
      src/com/droidquest/items/Disk.java
  54. 48
    51
      src/com/droidquest/items/ElevatorKey.java
  55. 62
    68
      src/com/droidquest/items/ElevatorSwitch.java
  56. 38
    44
      src/com/droidquest/items/EndAnimation.java
  57. 28
    30
      src/com/droidquest/items/EnergyButton.java
  58. 51
    55
      src/com/droidquest/items/F12Form.java
  59. 40
    46
      src/com/droidquest/items/FFButton.java
  60. 55
    56
      src/com/droidquest/items/Factory.java
  61. 92
    101
      src/com/droidquest/items/GateKeeper.java
  62. 454
    457
      src/com/droidquest/items/GenericRobot.java
  63. 170
    171
      src/com/droidquest/items/Ghost.java
  64. 70
    80
      src/com/droidquest/items/Handle.java
  65. 33
    35
      src/com/droidquest/items/Hexagon.java
  66. 11
    11
      src/com/droidquest/items/HiddenCamera.java
  67. 11
    8
      src/com/droidquest/items/Initializer.java
  68. 747
    700
      src/com/droidquest/items/Item.java
  69. 39
    40
      src/com/droidquest/items/Key.java
  70. 35
    37
      src/com/droidquest/items/Magnet.java
  71. 53
    58
      src/com/droidquest/items/MasterRobot.java
  72. 105
    107
      src/com/droidquest/items/MazeControl.java
  73. 85
    92
      src/com/droidquest/items/MazeCreator.java
  74. 19
    29
      src/com/droidquest/items/MazeLock.java
  75. 75
    78
      src/com/droidquest/items/NotAButton.java
  76. 63
    62
      src/com/droidquest/items/OrangeRobot.java
  77. 42
    45
      src/com/droidquest/items/PC16Button.java
  78. 44
    47
      src/com/droidquest/items/PC32Button.java
  79. 42
    45
      src/com/droidquest/items/PCButton.java
  80. 59
    64
      src/com/droidquest/items/Pellet.java
  81. 73
    80
      src/com/droidquest/items/Polarizer.java
  82. 83
    81
      src/com/droidquest/items/PowerSwitch.java
  83. 399
    396
      src/com/droidquest/items/Sentry.java
  84. 137
    104
      src/com/droidquest/items/Sentry3.java
  85. 173
    168
      src/com/droidquest/items/SentryT1.java
  86. 121
    87
      src/com/droidquest/items/SentryT2.java
  87. 48
    54
      src/com/droidquest/items/SkyGuard.java
  88. 55
    52
      src/com/droidquest/items/SkywayFlyer.java
  89. 37
    48
      src/com/droidquest/items/SlipperyToken.java
  90. 140
    146
      src/com/droidquest/items/SonicLock.java
  91. 73
    83
      src/com/droidquest/items/SpeedControl.java
  92. 44
    52
      src/com/droidquest/items/SpyCam.java
  93. 31
    36
      src/com/droidquest/items/Square.java
  94. 261
    241
      src/com/droidquest/items/StormCloud.java
  95. 67
    70
      src/com/droidquest/items/Suitcase.java
  96. 192
    206
      src/com/droidquest/items/Sweeper.java
  97. 158
    154
      src/com/droidquest/items/Switch4A.java
  98. 21
    26
      src/com/droidquest/items/Switch4B.java
  99. 21
    26
      src/com/droidquest/items/Switch4C.java
  100. 0
    0
      src/com/droidquest/items/Switch4D.java

+ 118
- 162
src/com/droidquest/DQ.java View File

@@ -2,178 +2,134 @@ package com.droidquest;

//This is the source code for DroidQuest 2.7. Copyright 2003 by Thomas Foote.

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

import javax.swing.*;

import com.droidquest.avatars.GameCursor;
import com.droidquest.chipstuff.Port;
import com.droidquest.decorations.Arrow;
import com.droidquest.decorations.Graphix;
import com.droidquest.decorations.Spark;
import com.droidquest.decorations.TextBox;
import com.droidquest.devices.ANDGate;
import com.droidquest.devices.Device;
import com.droidquest.devices.FlipFlop;
import com.droidquest.devices.NOTGate;
import com.droidquest.devices.Node;
import com.droidquest.devices.ORGate;
import com.droidquest.devices.PortDevice;
import com.droidquest.devices.XORGate;
import com.droidquest.items.Item;
import com.droidquest.items.ToolBox;
import com.droidquest.levels.Level;
import com.droidquest.levels.MainMenu;
import com.droidquest.materials.Material;

import java.util.Iterator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Set;
import java.util.Vector;
import java.util.Date;
import java.lang.Integer;
import java.util.Random;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;

public class DQ extends JFrame implements ActionListener
{
RoomDisplay myRoom;

public DQ ()
{
// Constructor
super("DroidQuest");
setSize(560+8,384+27+24);
addWindowListener( new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ setVisible(false); dispose(); System.exit(0); }
});
setIconImage(new ImageIcon("images/helper0.gif").getImage());

Container contentPane = getContentPane();
myRoom = new RoomDisplay();
myRoom.dq=this;

addFocusListener(new FocusAdapter()
{
public void focusGained(FocusEvent e)
{
myRoom.requestFocus();
}
});

contentPane.add(myRoom);
myRoom.setLocation(0,0);

JMenuBar menuBar;
JMenu fileMenu;
JMenuItem menuItemSave;
JMenuItem menuItemMain;
JCheckBoxMenuItem menuItemSound;
JMenuItem menuItemExit;

menuBar = new JMenuBar();
setJMenuBar(menuBar);
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);

menuItemSave = new JMenuItem("Save Level",KeyEvent.VK_S);
menuItemMain = new JMenuItem("Main Menu", KeyEvent.VK_M);
menuItemSound = new JCheckBoxMenuItem("Sound", true);
menuItemExit = new JMenuItem("Exit", KeyEvent.VK_X);
fileMenu.add(menuItemSave);
fileMenu.add(menuItemMain);
fileMenu.add(menuItemSound);
fileMenu.add(menuItemExit);

menuItemSave.addActionListener(this);
menuItemMain.addActionListener(this);
menuItemSound.addActionListener(this);
menuItemExit.addActionListener(this);

try
{
System.setErr(System.out);
}
catch (SecurityException e) {}
}

public static void main(String[] args)
{
DQ dq = new DQ();
GraphicsConfiguration gc = dq.getGraphicsConfiguration();
Rectangle bounds = gc.getBounds();
dq.setLocation(bounds.x + (bounds.width - 568)/2,
bounds.y + (bounds.height - 435)/2 );
dq.setVisible(true);

}

public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand() == "Save Level")
{
FileDialog fd = new FileDialog(this,"Save Level", FileDialog.SAVE);
fd.setDirectory("ROlevels");
fd.show();
System.out.println("Dialog returned with "
+ fd.getDirectory()
+ fd.getFile());
if (fd.getFile() != null)
myRoom.SaveLevel(fd.getDirectory()+fd.getFile());
}

if (e.getActionCommand() == "Main Menu")
{
int n = JOptionPane.showConfirmDialog(this,"Do you want to quit this level?",
"return to Main Menu", JOptionPane.YES_NO_OPTION);
if (n==0)
{
myRoom.level.Empty();
myRoom.level = new MainMenu(myRoom);
myRoom.level.Init();
}
}

if (e.getActionCommand() == "Sound")
{
myRoom.useSounds = ((JCheckBoxMenuItem)e.getSource()).getState();
if (myRoom.useSounds==false)
{
Set<String> keys = myRoom.level.sounds.keySet();
Iterator<String> iterator = keys.iterator();
while (iterator.hasNext()) {
String soundFile = iterator.next();
SoundClip soundClip = myRoom.level.sounds.get(soundFile);
soundClip.audioClip.stop();
}
// for (int a=0; a<myRoom.level.sounds.size(); a++)
// {
// SoundClip sc = (SoundClip) myRoom.level.sounds.elementAt(a);
// sc.audioClip.stop();
// }
}
}

if (e.getActionCommand() == "Exit")
{ setVisible(false); dispose(); System.exit(0); }

}
public class DQ extends JFrame implements ActionListener {
private RoomDisplay myRoom;

private DQ() {
// Constructor
super("DroidQuest");
setSize(560 + 8, 384 + 27 + 24);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
dispose();
System.exit(0);
}
});

setIconImage(new ImageIcon("images/helper0.gif").getImage());

Container contentPane = getContentPane();
myRoom = new RoomDisplay();
myRoom.dq = this;

addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
myRoom.requestFocus();
}
});

contentPane.add(myRoom);
myRoom.setLocation(0, 0);

JMenuBar menuBar;
JMenu fileMenu;
JMenuItem menuItemSave;
JMenuItem menuItemMain;
JCheckBoxMenuItem menuItemSound;
JMenuItem menuItemExit;

menuBar = new JMenuBar();
setJMenuBar(menuBar);
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);

menuItemSave = new JMenuItem("Save Level", KeyEvent.VK_S);
menuItemMain = new JMenuItem("Main Menu", KeyEvent.VK_M);
menuItemSound = new JCheckBoxMenuItem("Sound", true);
menuItemExit = new JMenuItem("Exit", KeyEvent.VK_X);
fileMenu.add(menuItemSave);
fileMenu.add(menuItemMain);
fileMenu.add(menuItemSound);
fileMenu.add(menuItemExit);

menuItemSave.addActionListener(this);
menuItemMain.addActionListener(this);
menuItemSound.addActionListener(this);
menuItemExit.addActionListener(this);

try {
System.setErr(System.out);
}
catch (SecurityException e) {
}
}

public static void main(String[] args) {
DQ dq = new DQ();
GraphicsConfiguration gc = dq.getGraphicsConfiguration();
Rectangle bounds = gc.getBounds();
dq.setLocation(bounds.x + (bounds.width - 568) / 2,
bounds.y + (bounds.height - 435) / 2);
dq.setVisible(true);

}

public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Save Level")) {
FileDialog fd = new FileDialog(this, "Save Level", FileDialog.SAVE);
fd.setDirectory("ROlevels");
fd.show();
System.out.println("Dialog returned with "
+ fd.getDirectory()
+ fd.getFile());
if (fd.getFile() != null) {
myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
}
}

if (e.getActionCommand().equals("Main Menu")) {
int n = JOptionPane.showConfirmDialog(this, "Do you want to quit this level?",
"return to Main Menu", JOptionPane.YES_NO_OPTION);
if (n == 0) {
myRoom.level.Empty();
myRoom.level = new MainMenu(myRoom);
myRoom.level.Init();
}
}

if (e.getActionCommand().equals("Sound")) {
myRoom.useSounds = ((JCheckBoxMenuItem) e.getSource()).getState();
if (!myRoom.useSounds) {
Set<String> keys = myRoom.level.sounds.keySet();
for (String soundFile : keys) {
SoundClip soundClip = myRoom.level.sounds.get(soundFile);
soundClip.audioClip.stop();
}
}
}

if (e.getActionCommand().equals("Exit")) {
setVisible(false);
dispose();
System.exit(0);
}

}

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//Updating Tutorial levels to 2.0
//
//ROTUT1 : Robot Anatomy

+ 309
- 344
src/com/droidquest/Room.java View File

@@ -1,14 +1,5 @@
package com.droidquest;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Vector;

import com.droidquest.decorations.Arrow;
import com.droidquest.decorations.Graphix;
import com.droidquest.decorations.TextBox;
@@ -16,340 +7,314 @@ import com.droidquest.items.Item;
import com.droidquest.levels.Level;
import com.droidquest.materials.Material;

public class Room implements Serializable, Cloneable
{
public transient static Level level;
public transient Room upRoom;
public transient Room downRoom;
public transient Room rightRoom;
public transient Room leftRoom;
public transient Item portalItem = null;

public int[][] RoomArray = { // Array of image references
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
public transient Material[][] MaterialArray = new Material[12][20];
public Vector textBoxes = new Vector();
public Vector wires = new Vector();
public Vector graphix = new Vector();
public Vector arrows = new Vector();
public boolean editable;

public Room()
{
upRoom=this;
downRoom=this;
rightRoom=this;
leftRoom=this;
editable=false;
}

public void writeRef(ObjectOutputStream s) throws IOException
{
s.writeInt(level.rooms.indexOf(upRoom));
s.writeInt(level.rooms.indexOf(downRoom));
s.writeInt(level.rooms.indexOf(rightRoom));
s.writeInt(level.rooms.indexOf(leftRoom));
s.writeInt(level.items.indexOf(portalItem));
s.writeInt(wires.size());
for (int a=0; a<wires.size(); a++)
((Wire)wires.elementAt(a)).writeRef(s);
}

public void readRef(ObjectInputStream s) throws IOException
{
upRoom = level.FindRoom(s.readInt());
downRoom = level.FindRoom(s.readInt());
rightRoom = level.FindRoom(s.readInt());
leftRoom = level.FindRoom(s.readInt());
portalItem = level.FindItem(s.readInt());

int numWires = s.readInt();
wires = new Vector();
for (int a=0; a<numWires; a++)
{
Wire wire = new Wire();
wires.addElement(wire);
wire.readRef(s,level);
}
for (int a=0; a<graphix.size(); a++)
{
((Graphix)graphix.elementAt(a)).GenerateIcons();
}
GenerateArray();
}

public void GenerateArray()
{
MaterialArray = new Material[12][20];
for (int y=0; y<12; y++)
for (int x=0; x<20; x++)
MaterialArray[y][x] = (Material) level.materials.elementAt(RoomArray[y][x]);
}

public void SetMaterial(int X, int Y, int index)
{
Material mat = (Material) level.materials.elementAt(index);
if (mat != null)
{
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}

public void SetMaterial(int X, int Y, Material mat)
{
int index = level.materials.indexOf(mat);
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}

public void SetMaterialFill(int X1, int Y1, int X2, int Y2, int index)
{
Material mat = (Material) level.materials.elementAt(index);
if (mat != null)
{
for (int Y=Y1; Y<=Y2; Y++)
for(int X=X1; X<=X2; X++)
{
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}
}

public void SetMaterialOutline(int X1, int Y1, int X2, int Y2, int index)
{
Material mat = (Material) level.materials.elementAt(index);
if (mat != null)
{
for (int Y=Y1; Y<=Y2; Y++)
{
RoomArray[Y][X1] = index;
MaterialArray[Y][X1] = mat;
RoomArray[Y][X2] = index;
MaterialArray[Y][X2] = mat;
}
for(int X=X1; X<=X2; X++)
{
RoomArray[Y1][X] = index;
MaterialArray[Y1][X] = mat;
RoomArray[Y2][X] = index;
MaterialArray[Y2][X] = mat;
}
}
}

public void SetMaterialFromRoom(int roomIndex)
{
Room r = (Room) level.rooms.elementAt(roomIndex);
for (int Y=0; Y<12; Y++)
for (int X=0; X<20; X++)
{
RoomArray[Y][X] = r.RoomArray[Y][X];
MaterialArray[Y][X] = r.MaterialArray[Y][X];
}
}

public void AddTextBox(String t, int X, int Y, int W)
{
TextBox newText = new TextBox(t,X,Y,W);
textBoxes.addElement(newText);
}

public void AddArrow(int X, int Y, int dir, int len, Color col)
{
Arrow newArrow = new Arrow( X, Y, dir, len, col);
arrows.addElement(newArrow);
}

public void AddGraphix(String t, int X, int Y)
{
Graphix newGraphix = new Graphix(t,X,Y);
graphix.addElement(newGraphix);
}

public void AddGraphix(String[] t, int X, int Y)
{
Graphix newGraphix = new Graphix(t,X,Y);
graphix.addElement(newGraphix);
}

public void DrawTextBoxes(Graphics g, RoomDisplay rd)
{
for (int a=0; a<textBoxes.size(); a++)
{
TextBox textBox = (TextBox) textBoxes.elementAt(a);
g.setColor(Color.white);
g.setFont(rd.smallFont);
int cursX = textBox.x;
int cursY = textBox.y;
int advY=0;
int advX;
String nextWord;
int indexFrom=0;
int indexTo;
do
{
// Get the next word in the string
if (indexFrom >= textBox.textString.lastIndexOf(" "))
{indexTo = textBox.textString.length();}
else
{indexTo = textBox.textString.indexOf(" ",indexFrom+1);}
nextWord = textBox.textString.substring(indexFrom, indexTo);
if (nextWord.startsWith(" "))
{
nextWord = nextWord.substring(1,nextWord.length());
}
if (!nextWord.endsWith(" "))
{
nextWord = nextWord + " ";
}
if (nextWord.startsWith("{BIG}"))
{
g.setFont(rd.bigFont);
}
else if (nextWord.startsWith("{SML}"))
{
g.setFont(rd.smallFont);
}
else if (nextWord.startsWith("{BSP}"))
{
FontMetrics fm = g.getFontMetrics();
advX = fm.stringWidth(" ");
cursX-=advX;
}
// if (nextWord fits "{rrr,ggg,bbb} "
else if (nextWord.startsWith("{")
&& nextWord.endsWith("} ")
&& nextWord.length()==14)
{
// extract rrr,ggg,bbb
Integer rr = new Integer(nextWord.substring(1,4));
Integer gg = new Integer(nextWord.substring(5,8));
Integer bb = new Integer(nextWord.substring(9,12));
g.setColor(new Color(rr.intValue(),
gg.intValue(),
bb.intValue()));
}
else
{
FontMetrics fm = g.getFontMetrics();
if (fm.getAscent() > advY)
{advY = fm.getAscent() ;}
advX = fm.stringWidth(nextWord);
if (cursX+advX > textBox.width + textBox.x)
{
cursX=textBox.x;
cursY+=advY;
advY=fm.getAscent();
}
g.drawString(nextWord, cursX, cursY);
cursX+=advX;
if (cursX+advX > textBox.width + textBox.x)
{
cursX=textBox.x;
cursY+=advY;
advY=fm.getAscent();
}
}
indexFrom = indexTo;
}
while (indexFrom < textBox.textString.length());
}
}

public void DrawGraphix(Graphics g, RoomDisplay rd)
{
for (int a = 0; a< graphix.size(); a++)
{
Graphix grx = (Graphix) graphix.elementAt(a);
grx.Draw(g,rd);
}
}

public void DrawArrows(Graphics g)
{
for (int a = 0; a< arrows.size(); a++)
((Arrow) arrows.elementAt(a)).Draw(g);
}

public Room getUpRoom(Item item)
{
return upRoom;
}

public Room getDownRoom(Item item)
{
return downRoom;
}

public Room getLeftRoom(Item item)
{
return leftRoom;
}

public Room getRightRoom(Item item)
{
return rightRoom;
}

public Wire FindWire(int wireIndex)
{
if (wireIndex==-1) return null;
if (wireIndex>=wires.size()) return null;
return (Wire) wires.elementAt(wireIndex);
}

public Object clone()
{
Object newObject = null;
try
{
newObject = super.clone();
}
catch (CloneNotSupportedException e) {}
return newObject;
}

public void Erase()
{
upRoom = null;
downRoom = null;
rightRoom = null;
leftRoom = null;
portalItem = null;
arrows.clear();
graphix.clear();
for (int a=0; a< wires.size(); a++)
{
Wire wire = (Wire) wires.elementAt(a);
wire.fromPort = null;
wire.toPort = null;
wire.inPort = null;
wire.outPort = null;
}
wires.clear();
}
import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Vector;

public class Room implements Serializable, Cloneable {
public transient static Level level;
public transient Room upRoom;
public transient Room downRoom;
public transient Room rightRoom;
public transient Room leftRoom;
public transient Item portalItem = null;

public int[][] RoomArray = { // Array of image references
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
public transient Material[][] MaterialArray = new Material[12][20];
public Vector<TextBox> textBoxes = new Vector<TextBox>();
public Vector<Wire> wires = new Vector<Wire>();
public Vector<Graphix> graphix = new Vector<Graphix>();
public Vector<Arrow> arrows = new Vector<Arrow>();
public boolean editable;

public Room() {
upRoom = this;
downRoom = this;
rightRoom = this;
leftRoom = this;
editable = false;
}

public void writeRef(ObjectOutputStream s) throws IOException {
s.writeInt(level.rooms.indexOf(upRoom));
s.writeInt(level.rooms.indexOf(downRoom));
s.writeInt(level.rooms.indexOf(rightRoom));
s.writeInt(level.rooms.indexOf(leftRoom));
s.writeInt(level.items.indexOf(portalItem));
s.writeInt(wires.size());
for (int a = 0; a < wires.size(); a++) {
wires.elementAt(a).writeRef(s);
}
}

public void readRef(ObjectInputStream s) throws IOException {
upRoom = level.FindRoom(s.readInt());
downRoom = level.FindRoom(s.readInt());
rightRoom = level.FindRoom(s.readInt());
leftRoom = level.FindRoom(s.readInt());
portalItem = level.FindItem(s.readInt());

int numWires = s.readInt();
wires = new Vector<Wire>();
for (int a = 0; a < numWires; a++) {
Wire wire = new Wire();
wires.addElement(wire);
wire.readRef(s, level);
}

for (int a = 0; a < graphix.size(); a++) {
graphix.elementAt(a).GenerateIcons();
}

GenerateArray();
}

public void GenerateArray() {
MaterialArray = new Material[12][20];
for (int y = 0; y < 12; y++) {
for (int x = 0; x < 20; x++) {
MaterialArray[y][x] = level.materials.elementAt(RoomArray[y][x]);
}
}
}

public void SetMaterial(int X, int Y, int index) {
Material mat = level.materials.elementAt(index);
if (mat != null) {
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}

public void SetMaterial(int X, int Y, Material mat) {
int index = level.materials.indexOf(mat);
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}

public void SetMaterialFill(int X1, int Y1, int X2, int Y2, int index) {
Material mat = level.materials.elementAt(index);
if (mat != null) {
for (int Y = Y1; Y <= Y2; Y++) {
for (int X = X1; X <= X2; X++) {
RoomArray[Y][X] = index;
MaterialArray[Y][X] = mat;
}
}
}
}

public void SetMaterialOutline(int X1, int Y1, int X2, int Y2, int index) {
Material mat = level.materials.elementAt(index);
if (mat != null) {
for (int Y = Y1; Y <= Y2; Y++) {
RoomArray[Y][X1] = index;
MaterialArray[Y][X1] = mat;
RoomArray[Y][X2] = index;
MaterialArray[Y][X2] = mat;
}

for (int X = X1; X <= X2; X++) {
RoomArray[Y1][X] = index;
MaterialArray[Y1][X] = mat;
RoomArray[Y2][X] = index;
MaterialArray[Y2][X] = mat;
}
}
}

public void SetMaterialFromRoom(int roomIndex) {
Room r = level.rooms.elementAt(roomIndex);
for (int Y = 0; Y < 12; Y++) {
for (int X = 0; X < 20; X++) {
RoomArray[Y][X] = r.RoomArray[Y][X];
MaterialArray[Y][X] = r.MaterialArray[Y][X];
}
}
}

public void AddTextBox(String t, int X, int Y, int W) {
TextBox newText = new TextBox(t, X, Y, W);
textBoxes.addElement(newText);
}

public void AddArrow(int X, int Y, int dir, int len, Color col) {
Arrow newArrow = new Arrow(X, Y, dir, len, col);
arrows.addElement(newArrow);
}

public void AddGraphix(String t, int X, int Y) {
Graphix newGraphix = new Graphix(t, X, Y);
graphix.addElement(newGraphix);
}

public void AddGraphix(String[] t, int X, int Y) {
Graphix newGraphix = new Graphix(t, X, Y);
graphix.addElement(newGraphix);
}

public void DrawTextBoxes(Graphics g, RoomDisplay rd) {
for (int a = 0; a < textBoxes.size(); a++) {
TextBox textBox = textBoxes.elementAt(a);
g.setColor(Color.white);
g.setFont(rd.smallFont);

int cursX = textBox.x;
int cursY = textBox.y;
int advY = 0;
int advX;
String nextWord;
int indexFrom = 0;
int indexTo;

do {
// Get the next word in the string
if (indexFrom >= textBox.textString.lastIndexOf(" ")) {
indexTo = textBox.textString.length();
}
else {
indexTo = textBox.textString.indexOf(" ", indexFrom + 1);
}
nextWord = textBox.textString.substring(indexFrom, indexTo);
if (nextWord.startsWith(" ")) {
nextWord = nextWord.substring(1, nextWord.length());
}
if (!nextWord.endsWith(" ")) {
nextWord = nextWord + " ";
}

if (nextWord.startsWith("{BIG}")) {
g.setFont(rd.bigFont);
}

else if (nextWord.startsWith("{SML}")) {
g.setFont(rd.smallFont);
}

else if (nextWord.startsWith("{BSP}")) {
FontMetrics fm = g.getFontMetrics();
advX = fm.stringWidth(" ");
cursX -= advX;
}

// if (nextWord fits "{rrr,ggg,bbb} "
else if (nextWord.startsWith("{")
&& nextWord.endsWith("} ")
&& nextWord.length() == 14) {
// extract rrr,ggg,bbb
Integer rr = new Integer(nextWord.substring(1, 4));
Integer gg = new Integer(nextWord.substring(5, 8));
Integer bb = new Integer(nextWord.substring(9, 12));
g.setColor(new Color(rr.intValue(),
gg.intValue(),
bb.intValue()));
}
else {
FontMetrics fm = g.getFontMetrics();
if (fm.getAscent() > advY) {
advY = fm.getAscent();
}
advX = fm.stringWidth(nextWord);
if (cursX + advX > textBox.width + textBox.x) {
cursX = textBox.x;
cursY += advY;
advY = fm.getAscent();
}
g.drawString(nextWord, cursX, cursY);
cursX += advX;
if (cursX + advX > textBox.width + textBox.x) {
cursX = textBox.x;
cursY += advY;
advY = fm.getAscent();
}
}
indexFrom = indexTo;
}
while (indexFrom < textBox.textString.length());
}
}

public void DrawGraphix(Graphics g, RoomDisplay rd) {
for (int a = 0; a < graphix.size(); a++) {
Graphix grx = graphix.elementAt(a);
grx.Draw(g, rd);
}
}

public void DrawArrows(Graphics g) {
for (int a = 0; a < arrows.size(); a++) {
arrows.elementAt(a).Draw(g);
}
}

public Room getUpRoom(Item item) {
return upRoom;
}

public Room getDownRoom(Item item) {
return downRoom;
}

public Room getLeftRoom(Item item) {
return leftRoom;
}

public Room getRightRoom(Item item) {
return rightRoom;
}

public Wire FindWire(int wireIndex) {
if (wireIndex == -1) {
return null;
}
if (wireIndex >= wires.size()) {
return null;
}
return wires.elementAt(wireIndex);
}

public Object clone() {
Object newObject = null;
try {
newObject = super.clone();
}
catch (CloneNotSupportedException e) {
}
return newObject;
}

public void Erase() {
upRoom = null;
downRoom = null;
rightRoom = null;
leftRoom = null;
portalItem = null;
arrows.clear();
graphix.clear();
for (int a = 0; a < wires.size(); a++) {
Wire wire = wires.elementAt(a);
wire.fromPort = null;
wire.toPort = null;
wire.inPort = null;
wire.outPort = null;
}
wires.clear();
}

}

+ 454
- 548
src/com/droidquest/RoomDisplay.java
File diff suppressed because it is too large
View File


+ 15
- 19
src/com/droidquest/SoundClip.java View File

@@ -5,24 +5,20 @@ import java.applet.AudioClip;
import java.net.MalformedURLException;
import java.net.URL;

public class SoundClip
{
public AudioClip audioClip;
public String filename;
public class SoundClip {
public AudioClip audioClip;
private String filename;

public SoundClip(String f)
{
filename = f;
try
{
URL baseURL = new URL("file:" + System.getProperty("user.dir") + "/sounds/");
URL soundURL;
soundURL = new URL(baseURL, filename);
audioClip = Applet.newAudioClip(soundURL);
}
catch (MalformedURLException e)
{
System.err.println(e.getMessage());
}
}
public SoundClip(String f) {
filename = f;
try {
URL baseURL = new URL("file:" + System.getProperty("user.dir") + "/sounds/");
URL soundURL;
soundURL = new URL(baseURL, filename);
audioClip = Applet.newAudioClip(soundURL);
}
catch (MalformedURLException e) {
System.err.println(e.getMessage());
}
}
}

+ 381
- 418
src/com/droidquest/Wire.java View File

@@ -1,439 +1,402 @@
package com.droidquest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import com.droidquest.chipstuff.Port;
import com.droidquest.devices.Device;
import com.droidquest.levels.Level;

import java.awt.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import com.droidquest.chipstuff.Port;
import com.droidquest.devices.Device;
import com.droidquest.levels.Level;
public class Wire implements Serializable {
public transient Port fromPort; // Connected First
public transient Port toPort; // Connected 2nd
public transient Port inPort; // Connected to Input
public transient Port outPort; // Connected to Output (Source of Value)
public boolean value;

public Wire() {
}

public Wire(Port f, Port t) {
if (f.myDevice != null) {
if (f.myDevice.room != null) {
if (f.myDevice.room.wires == null) {
System.out.println("f.myDevice.room.wires is null");
}
}
else {
System.out.println("f.myDevice.room is null");
}
}
else {
System.out.println("f.myDevice is null");
}

f.myDevice.room.wires.addElement(this);
f.myDevice.level.PlaySound(f.myDevice.room, Level.ATTACHSOUND);

if (f.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (f.type == Port.TYPE_OUTPUT) {
if (t.type == Port.TYPE_INPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (f.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
f.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
f.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = f;
toPort = t;
f.myWire = this;
t.myWire = this;
}
}
}

void writeRef(ObjectOutputStream s) throws IOException {
Level level = fromPort.myDevice.level;
int a;

s.writeInt(level.items.indexOf(fromPort.myDevice)); // Index of fromport device
a = 0;
while (((Device) fromPort.myDevice).ports[a] != fromPort) {
a++;
}
s.writeInt(a); // Index of fromport (as device.ports[?]

s.writeInt(level.items.indexOf(toPort.myDevice)); // Index of toPort device
a = 0;
while (((Device) toPort.myDevice).ports[a] != toPort) {
a++;
}
s.writeInt(a); // Index of toPort (as device.ports[?]

s.writeInt(level.items.indexOf(inPort.myDevice)); // Index of inPort device
a = 0;
while (((Device) inPort.myDevice).ports[a] != inPort) {
a++;
}
s.writeInt(a); // Index of inPort (as device.ports[?]

s.writeInt(level.items.indexOf(outPort.myDevice)); // Index of outPort device
a = 0;
while (((Device) outPort.myDevice).ports[a] != outPort) {
a++;
}
s.writeInt(a); // Index of outPort (as device.ports[?]
}

void readRef(ObjectInputStream s, Level level) throws IOException {
Device tempDevice;
tempDevice = (Device) level.FindItem(s.readInt());
fromPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
toPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
inPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
outPort = tempDevice.ports[s.readInt()];
}

public void ConnectTo(Port t) {
fromPort.myDevice.level.PlaySound(fromPort.myDevice.room, Level.DETATCHSOUND);

if (toPort.myDevice == toPort.myDevice.level.solderingPen) {
toPort.value = false;
toPort.type = Port.TYPE_UNDEFINED;
toPort.myWire = null;

public class Wire implements Serializable
{
public transient Port fromPort; // Connected First
public transient Port toPort; // Connected 2nd
public transient Port inPort; // Connected to Input
public transient Port outPort; // Connected to Output (Source of Value)
public boolean value;
if (fromPort.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT) {
toPort = t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (fromPort.type == Port.TYPE_OUTPUT) {
if (t.type == Port.TYPE_INPUT) {
toPort = t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (fromPort.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
toPort = t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
fromPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
toPort = t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
fromPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
toPort = t;
t.myWire = this;
}
}
}
else {
fromPort.value = false;
fromPort.type = Port.TYPE_UNDEFINED;
fromPort.myWire = null;

public Wire() {}
if (toPort.type == Port.TYPE_INPUT) {
if (t.type == Port.TYPE_INPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (toPort.type == Port.TYPE_OUTPUT) {
if (t.type == Port.TYPE_INPUT) {
fromPort = t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (toPort.type == Port.TYPE_UNDEFINED) {
if (t.type == Port.TYPE_INPUT) {
fromPort = t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
toPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT) {
fromPort = t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
toPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED) {
fromPort = t;
t.myWire = this;
}
}
}

public Wire(Port f, Port t)
{
if (f.myDevice!=null)
{
if (f.myDevice.room!=null)
{
if (f.myDevice.room.wires==null)
System.out.println("f.myDevice.room.wires is null");
}
else
System.out.println("f.myDevice.room is null");
}
else
System.out.println("f.myDevice is null");
f.myDevice.room.wires.addElement(this);
f.myDevice.level.PlaySound(f.myDevice.room, Level.ATTACHSOUND);
if (f.type == Port.TYPE_INPUT)
{
if (t.type == Port.TYPE_INPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (f.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_INPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (f.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
f.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
f.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort = f;
toPort=t;
f.myWire = this;
t.myWire = this;
return;
}
}
}
}

protected void writeRef(ObjectOutputStream s) throws IOException
{
Level level = fromPort.myDevice.level;
int a;
s.writeInt(level.items.indexOf(fromPort.myDevice)); // Index of fromport device
a=0; while (((Device)fromPort.myDevice).ports[a] != fromPort) a++;
s.writeInt(a); // Index of fromport (as device.ports[?]
public void Remove() {
Room room = fromPort.myDevice.room;

s.writeInt(level.items.indexOf(toPort.myDevice)); // Index of toPort device
a=0; while (((Device)toPort.myDevice).ports[a] != toPort) a++;
s.writeInt(a); // Index of toPort (as device.ports[?]
s.writeInt(level.items.indexOf(inPort.myDevice)); // Index of inPort device
a=0; while (((Device)inPort.myDevice).ports[a] != inPort) a++;
s.writeInt(a); // Index of inPort (as device.ports[?]
s.writeInt(level.items.indexOf(outPort.myDevice)); // Index of outPort device
a=0; while (((Device)outPort.myDevice).ports[a] != outPort) a++;
s.writeInt(a); // Index of outPort (as device.ports[?]
}
room.level.PlaySound(room, Level.DETATCHSOUND);

protected void readRef(ObjectInputStream s, Level level) throws IOException
{
Device tempDevice;
tempDevice = (Device) level.FindItem(s.readInt());
fromPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
toPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
inPort = tempDevice.ports[s.readInt()];
tempDevice = (Device) level.FindItem(s.readInt());
outPort = tempDevice.ports[s.readInt()];
}
fromPort.myWire = null;
toPort.myWire = null;
fromPort = null;
toPort = null;
inPort = null;
outPort = null;
room.wires.removeElement(this);

public void ConnectTo(Port t)
{
fromPort.myDevice.level.PlaySound(fromPort.myDevice.room, Level.DETATCHSOUND);
}

if (toPort.myDevice == toPort.myDevice.level.solderingPen)
{
toPort.value = false;
toPort.type = Port.TYPE_UNDEFINED;
toPort.myWire = null;
if (fromPort.type == Port.TYPE_INPUT)
{
if (t.type == Port.TYPE_INPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
toPort=t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
toPort=t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (fromPort.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_INPUT)
{
toPort=t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
toPort=t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (fromPort.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
toPort=t;
t.myWire = this;
outPort = fromPort;
inPort = toPort;
fromPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
toPort=t;
t.myWire = this;
inPort = fromPort;
outPort = toPort;
fromPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
toPort=t;
t.myWire = this;
return;
}
}
}
else
{
fromPort.value = false;
fromPort.type = Port.TYPE_UNDEFINED;
fromPort.myWire = null;
if (toPort.type == Port.TYPE_INPUT)
{
if (t.type == Port.TYPE_INPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort=t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort=t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
t.type = Port.TYPE_OUTPUT;
return;
}
}
if (toPort.type == Port.TYPE_OUTPUT)
{
if (t.type == Port.TYPE_INPUT)
{
fromPort=t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
Remove();
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort=t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
t.type = Port.TYPE_INPUT;
return;
}
}
if (toPort.type == Port.TYPE_UNDEFINED)
{
if (t.type == Port.TYPE_INPUT)
{
fromPort=t;
t.myWire = this;
outPort = toPort;
inPort = fromPort;
toPort.type = Port.TYPE_OUTPUT;
return;
}
if (t.type == Port.TYPE_OUTPUT)
{
fromPort=t;
t.myWire = this;
inPort = toPort;
outPort = fromPort;
toPort.type = Port.TYPE_INPUT;
return;
}
if (t.type == Port.TYPE_UNDEFINED)
{
fromPort=t;
t.myWire = this;
return;
}
}
}
public void Draw(Graphics g) {
g.setColor(Color.white);
value = false;
if (fromPort.type == Port.TYPE_OUTPUT && fromPort.value) {
g.setColor(new Color(255, 128, 0));
value = true;
}
if (toPort.type == Port.TYPE_OUTPUT && toPort.value) {
g.setColor(new Color(255, 128, 0));
value = true;
}

}
Dimension d1, d2;
int x1, y1, x2, y2;
d1 = fromPort.myDevice.GetXY();
d2 = toPort.myDevice.GetXY();
x1 = d1.width + fromPort.x;
y1 = d1.height + fromPort.y;
x2 = d2.width + toPort.x;
y2 = d2.height + toPort.y;
switch ((((Device) fromPort.myDevice).rotation + fromPort.rotation) % 4) {
case 0: // Up
x1 += 1;
y1 += 1;
break;
case 1: // Right
x1 -= 2;
y1 += 1;
break;
case 2: // Down
x1 -= 2;
y1 -= 2;
break;
case 3: // Left
x1 += 1;
y1 -= 2;
break;
}
switch ((((Device) toPort.myDevice).rotation + toPort.rotation) % 4) {
case 0: // Up
x2 += 1;
y2 += 1;
break;
case 1: // Right
x2 -= 2;
y2 += 1;
break;
case 2: // Down
x2 -= 2;
y2 -= 2;
break;
case 3: // Left
x2 += 1;
y2 -= 2;
break;
}

public void Remove()
{
Room room = fromPort.myDevice.room;
room.level.PlaySound(room, Level.DETATCHSOUND);
fromPort.myWire = null;
toPort.myWire = null;
fromPort = null;
toPort = null;
inPort = null;
outPort = null;
room.wires.removeElement(this);
}
g.fillRect(Math.min(x1, x2), y1, Math.abs(x1 - x2), 2);
g.fillRect(x2, Math.min(y1, y2), 2, Math.abs(y1 - y2));
g.fillRect(x1, y1, 2, 2);
g.fillRect(x2, y2, 2, 2);
g.fillRect(x2, y1, 2, 2);

public void Draw(Graphics g)
{
g.setColor(Color.white);
value = false;
if (fromPort.type == Port.TYPE_OUTPUT && fromPort.value)
{
g.setColor(new Color(255,128,0));
value = true;
}
if (toPort.type == Port.TYPE_OUTPUT && toPort.value)
{
g.setColor(new Color(255,128,0));
value = true;
}
Dimension d1, d2;
int x1, y1, x2, y2;
d1 = fromPort.myDevice.GetXY();
d2 = toPort.myDevice.GetXY();
x1 = d1.width + fromPort.x;
y1 = d1.height + fromPort.y;
x2 = d2.width + toPort.x;
y2 = d2.height + toPort.y;
switch((((Device)fromPort.myDevice).rotation + fromPort.rotation)%4)
{
case 0: // Up
x1 += 1;
y1 += 1;
break;
case 1: // Right
x1 -= 2;
y1 += 1;
break;
case 2: // Down
x1 -= 2;
y1 -= 2;
break;
case 3: // Left
x1 += 1;
y1 -= 2;
break;
}
switch((((Device)toPort.myDevice).rotation + toPort.rotation)%4)
{
case 0: // Up
x2 += 1;
y2 += 1;
break;
case 1: // Right
x2 -= 2;
y2 += 1;
break;
case 2: // Down
x2 -= 2;
y2 -= 2;
break;
case 3: // Left
x2 += 1;
y2 -= 2;
break;
}
g.fillRect(Math.min(x1,x2),y1,Math.abs(x1-x2),2);
g.fillRect(x2,Math.min(y1,y2),2,Math.abs(y1-y2));
g.fillRect(x1,y1,2,2);
g.fillRect(x2,y2,2,2);
g.fillRect(x2,y1,2,2);
}
}

public Port otherPort(Port p)
{
if (fromPort == p) return toPort;
if (toPort == p) return fromPort;
return null;
}
public Port otherPort(Port p) {
if (fromPort == p) {
return toPort;
}
if (toPort == p) {
return fromPort;
}
return null;
}

}

+ 744
- 759
src/com/droidquest/avatars/GameCursor.java
File diff suppressed because it is too large
View File


+ 33
- 37
src/com/droidquest/avatars/HelpCam.java View File

@@ -1,45 +1,41 @@
package com.droidquest.avatars;

import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import com.droidquest.Room;
import com.droidquest.items.Item;

public class HelpCam extends Item
{
public HelpCam(Room r)
{
charge=0;
x=28; y=32; width=0; height=0; room =r;
GenerateIcons();
currentIcon = icons[0].getImage();
}

public void GenerateIcons()
{
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(8,8,BufferedImage.TYPE_4BYTE_ABGR));
}

public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_ENTER)
{
level.player = level.gameCursor;
level.currentViewer = level.gameCursor;
}
return false;
}

public void Draw(Graphics g, JPanel jp)
{
// Draws nothing
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

public class HelpCam extends Item {
public HelpCam(Room r) {
charge = 0;
x = 28;
y = 32;
width = 0;
height = 0;
room = r;
GenerateIcons();
currentIcon = icons[0].getImage();
}

public void GenerateIcons() {
icons = new ImageIcon[1];
icons[0] = new ImageIcon(new BufferedImage(8, 8, BufferedImage.TYPE_4BYTE_ABGR));
}

public boolean KeyUp(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
level.player = level.gameCursor;
level.currentViewer = level.gameCursor;
}
return false;
}

public void Draw(Graphics g, JPanel jp) {
// Draws nothing
}


}

+ 390
- 409
src/com/droidquest/avatars/LabCursor.java View File

@@ -1,157 +1,146 @@
package com.droidquest.avatars;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

import com.droidquest.Room;
import com.droidquest.devices.Device;
import com.droidquest.devices.GenericChip;
import com.droidquest.devices.SmallChip;
import com.droidquest.items.GenericRobot;
import com.droidquest.items.Item;
import com.droidquest.items.ToolBox;

public class LabCursor extends Item
{
public boolean hot;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

public class LabCursor extends Item {
public boolean hot;


public LabCursor(){}

public LabCursor(int X, int Y, Room r)
{
x=X; y=Y;
hot=false;
room=r;
width=28; height=32;
GenerateIcons();
}
public LabCursor(int X, int Y, Room r) {
x = X;
y = Y;
hot = false;
room = r;
width = 28;
height = 32;
GenerateIcons();
}

public void GenerateIcons()
{
icons = new ImageIcon[2];
icons[0]= new ImageIcon(new BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR));
icons[1]= 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 LabCursor Image");
return;
}
Graphics2D g2 = (Graphics2D) g;
g.setColor(Color.white);
g.fillRect(0,0,width,height);
try
{
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e)
{
System.out.println("Could not get Graphics pointer to LabCursor Image");
return;
}
g2 = (Graphics2D) g;
g.setColor(new Color(255,128,0));
g.fillRect(0,0,width,height);
if (hot)
currentIcon = icons[1].getImage();
else
currentIcon = icons[0].getImage();
}
public void GenerateIcons() {
icons = new ImageIcon[2];
icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
icons[1] = 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 LabCursor Image");
return;
}
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
try {
g = icons[1].getImage().getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to LabCursor Image");
return;
}
g.setColor(new Color(255, 128, 0));
g.fillRect(0, 0, width, height);
if (hot) {
currentIcon = icons[1].getImage();
}
else {
currentIcon = icons[0].getImage();
}
}

public boolean CanBePickedUp(Item i)
{
if (i.getClass().toString().endsWith("Robot"))
return false;
return true;
}
public boolean CanBePickedUp(Item i) {
return !(i instanceof GenericRobot);
}

public boolean KeyUp(KeyEvent e)
{
if (e.getKeyCode() == e.VK_L)
{
if (carrying != null)
if (carrying.getClass().toString().endsWith("SmallChip"))
{
FileDialog fd = new FileDialog(level.roomdisplay.dq,"Load Chip", FileDialog.LOAD);
fd.setDirectory("chips");
fd.show();
System.out.println("Dialog returned with "
+ fd.getDirectory()
+ fd.getFile());
if (fd.getFile() != null)
{
((SmallChip)carrying).Empty();
((SmallChip)carrying).LoadChip(fd.getDirectory()+fd.getFile());
}
}
}
if (e.getKeyCode() == e.VK_H)
{
hot = !hot;
if (hot)
currentIcon = icons[1].getImage();