Browse Source

Merge pull request #6 from cognitivegears/master

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

+ 405
- 163
src/com/droidquest/DQ.java View File

@@ -2,178 +2,420 @@ 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.avatars.Avatar;
import com.droidquest.avatars.LabCursor;
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 JCheckBoxMenuItem menuToggleHot = null;
private JMenuItem menuItemCursor = null;
private JMenuItem menuItemSolderpen = null;
private JMenuItem menuItemPaintbrush = null;
private JCheckBoxMenuItem menuItemRadio = null;
private JMenuItem menuItemToolbox = null;

private JMenuItem menuRotateRight = null;
private JMenuItem menuRotateLeft = null;
private JMenuItem menuLoadChip = null;

private JMenuItem menuFlipDevice = null;

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(this);

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

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

JMenuBar menuBar;
JMenu fileMenu;
JMenu avatarMenu;
JMenu controlMenu;
JMenu helpMenu;
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);

avatarMenu = new JMenu("Avatar");
avatarMenu.setMnemonic(KeyEvent.VK_A);
menuBar.add(avatarMenu);


menuItemCursor = new JRadioButtonMenuItem("Cursor");
avatarMenu.add(menuItemCursor);
menuItemCursor.addActionListener(this);

menuItemSolderpen = new JRadioButtonMenuItem("Solderpen");
avatarMenu.add(menuItemSolderpen);
menuItemSolderpen.setEnabled(false);
menuItemSolderpen.addActionListener(this);

menuItemPaintbrush = new JRadioButtonMenuItem("Paintbrush");
avatarMenu.add(menuItemPaintbrush);
menuItemPaintbrush.setEnabled(false);
menuItemPaintbrush.addActionListener(this);

ButtonGroup menuItemAvatarButtonGroup = new ButtonGroup();
menuItemAvatarButtonGroup.add(menuItemCursor);
menuItemAvatarButtonGroup.add(menuItemSolderpen);
menuItemAvatarButtonGroup.add(menuItemPaintbrush);
menuItemCursor.setSelected(true);

controlMenu = new JMenu("Controls");
controlMenu.setMnemonic(KeyEvent.VK_C);
menuBar.add(controlMenu);


menuItemToolbox = new JMenuItem("Toolbox");
controlMenu.add(menuItemToolbox);
menuItemToolbox.addActionListener(this);

menuItemRadio = new JCheckBoxMenuItem("Radio");
controlMenu.add(menuItemRadio);
menuItemRadio.setSelected(false);
menuItemRadio.setEnabled(false);
menuItemRadio.addActionListener(this);

menuRotateRight = new JMenuItem("Rotate Part Clockwise");
controlMenu.add(menuRotateRight);
menuRotateRight.setEnabled(false);
menuRotateRight.addActionListener(this);

menuRotateLeft = new JMenuItem("Rotate Part Counter-clockwise");
controlMenu.add(menuRotateLeft);
menuRotateLeft.setEnabled(false);
menuRotateLeft.addActionListener(this);

menuToggleHot = new JCheckBoxMenuItem("Hot Cursor", false);
menuToggleHot.setEnabled(false);
controlMenu.add(menuToggleHot);
menuToggleHot.addActionListener(this);


menuLoadChip = new JMenuItem("Load Chip");
controlMenu.add(menuLoadChip);
menuLoadChip.setEnabled(false);
menuLoadChip.addActionListener(this);


JMenuItem menuEnterRobot = new JMenuItem("Enter Robot");
controlMenu.add(menuEnterRobot);
menuEnterRobot.addActionListener(this);

JMenuItem menuExitRobot = new JMenuItem("Exit Robot");
controlMenu.add(menuExitRobot);
menuExitRobot.addActionListener(this);

menuFlipDevice = new JMenuItem("Flip Device/Wire");
controlMenu.add(menuFlipDevice);
menuFlipDevice.setEnabled(false);
menuFlipDevice.addActionListener(this);

menuBar.add(Box.createHorizontalGlue());

helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
menuBar.add(helpMenu);

JMenuItem helpInfo = new JMenuItem("Help");
helpMenu.add(helpInfo);
helpInfo.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 setHotCursorSelected(boolean selected) {
if (null != this.menuToggleHot) {
this.menuToggleHot.setSelected(selected);
}
}

public void setHotCursorEnabled(boolean enabled) {
if (null != this.menuToggleHot) {
this.menuToggleHot.setEnabled(enabled);
}
}

public void setRotateEnabled(boolean enabled) {
if (null != this.menuRotateRight && null != this.menuRotateLeft) {
this.menuRotateRight.setEnabled(enabled);
this.menuRotateLeft.setEnabled(enabled);
}
}

public void setLoadChipEnabled(boolean enabled) {
if (null != this.menuLoadChip) {
this.menuLoadChip.setEnabled(enabled);
}
}

public void setFlipDeviceEnabled(boolean enabled) {
if(null != this.menuFlipDevice) {
this.menuFlipDevice.setEnabled(enabled);
}
}

public void setToolboxEnabled(boolean enabled) {
if (null != this.menuItemToolbox) {
this.menuItemToolbox.setEnabled(enabled);
}
}


public void selectCursor() {
if (null != this.menuItemCursor) {
this.menuItemCursor.setSelected(true);
if (null != myRoom && null != myRoom.level && myRoom.level.gameCursor instanceof LabCursor) {
setHotCursorEnabled(true);
}
setToolboxEnabled(true);
}
}

public void setSolderPenEnabled(boolean enabled) {
if (null != this.menuItemSolderpen) {
this.menuItemSolderpen.setEnabled(enabled);
}
}

public void selectSolderpen() {
if (null != this.menuItemSolderpen) {
this.menuItemSolderpen.setSelected(true);
this.setHotCursorEnabled(false);
setToolboxEnabled(false);
setFlipDeviceEnabled(true);
}
}

public void setPaintbrushEnabled(boolean enabled) {
if (null != this.menuItemPaintbrush) {
this.menuItemPaintbrush.setEnabled(enabled);
setFlipDeviceEnabled(false);
}
}

public void selectPaintBrush() {
if (null != this.menuItemPaintbrush) {
this.menuItemPaintbrush.setSelected(true);
this.setHotCursorEnabled(false);
this.setToolboxEnabled(false);
}
}


public void setRadioEnabled(boolean enabled) {
if (null != this.menuItemRadio) {
this.menuItemRadio.setEnabled(enabled);
}
}

public void setRadioSelected(boolean selected) {
if (null != this.menuItemRadio) {
this.menuItemRadio.setSelected(selected);
}
}


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());
}
}
else if (e.getActionCommand().equals("Cursor")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleGameCursor();
}
}
else if (e.getActionCommand().equals("Solderpen")) {
// Handle Solderpen
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleSolderPen();
}
}
else if (e.getActionCommand().equals("Paintbrush")) {
// Handle Paintbrush
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handlePaintbrush();
}
}
else if (e.getActionCommand().equals("Toolbox")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleToolbox();
}
}
else if (e.getActionCommand().equals("Radio")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleRadio();
}
}
else if (e.getActionCommand().equals("Rotate Part Clockwise")) {
// Rotate a part clockwise
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleRotateDevice(1);
}
}
else if (e.getActionCommand().equals("Rotate Part Counter-clockwise")) {
// Rotate counter clockwise
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleRotateDevice(-1);
}
}
else if (e.getActionCommand().equals("Hot Cursor")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleHotCursor();
}
}
else if (e.getActionCommand().equals("Load Chip")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleLoadSmallChip();
}
}
else if (e.getActionCommand().equals("Help")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleHelp();
}
}
else if (e.getActionCommand().equals("Enter Robot")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleEnterRoom();
}
}
else if (e.getActionCommand().equals("Exit Robot")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleExitRoom();
}
}
else if (e.getActionCommand().equals("Flip Device/Wire")) {
if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
Avatar playerAvatar = (Avatar) myRoom.level.player;
playerAvatar.handleFlipDevice();
}
}
else 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();
setHotCursorEnabled(false);
setHotCursorSelected(false);
setRotateEnabled(false);
setLoadChipEnabled(false);
setPaintbrushEnabled(false);
setFlipDeviceEnabled(false);
setToolboxEnabled(false);
setSolderPenEnabled(false);
setRadioSelected(false);
setRadioEnabled(false);
selectCursor();
}
}

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();
}

}

+ 494
- 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;