Browse Source

Implemented additional menu items for avatars and available controls, refactored player avatars to accommodate as well as reduce redundant code.

cognitivegears 5 years ago
parent
commit
a660adb81c
34 changed files with 1813 additions and 1098 deletions
  1. 290
    4
      src/com/droidquest/DQ.java
  2. 44
    4
      src/com/droidquest/RoomDisplay.java
  3. 83
    0
      src/com/droidquest/avatars/Avatar.java
  4. 37
    364
      src/com/droidquest/avatars/GameCursor.java
  5. 60
    1
      src/com/droidquest/avatars/HelpCam.java
  6. 70
    336
      src/com/droidquest/avatars/LabCursor.java
  7. 93
    107
      src/com/droidquest/avatars/PaintBrush.java
  8. 562
    0
      src/com/droidquest/avatars/Player.java
  9. 76
    17
      src/com/droidquest/avatars/Remote.java
  10. 217
    97
      src/com/droidquest/avatars/SolderingPen.java
  11. 3
    0
      src/com/droidquest/devices/Device.java
  12. 19
    19
      src/com/droidquest/items/AmpireBot.java
  13. 2
    2
      src/com/droidquest/items/ChipDecompiler.java
  14. 2
    2
      src/com/droidquest/items/GateKeeper.java
  15. 5
    13
      src/com/droidquest/items/GenericRobot.java
  16. 4
    4
      src/com/droidquest/items/Ghost.java
  17. 2
    2
      src/com/droidquest/items/Handle.java
  18. 24
    24
      src/com/droidquest/items/Item.java
  19. 10
    10
      src/com/droidquest/items/Sentry.java
  20. 14
    14
      src/com/droidquest/items/Sentry3.java
  21. 2
    2
      src/com/droidquest/items/SentryT1.java
  22. 13
    13
      src/com/droidquest/items/SentryT2.java
  23. 2
    2
      src/com/droidquest/items/SkyGuard.java
  24. 4
    4
      src/com/droidquest/items/SkywayFlyer.java
  25. 66
    6
      src/com/droidquest/items/SpyCam.java
  26. 8
    8
      src/com/droidquest/items/StormCloud.java
  27. 2
    2
      src/com/droidquest/items/Sweeper.java
  28. 62
    2
      src/com/droidquest/items/Train.java
  29. 30
    30
      src/com/droidquest/items/TrashCollector.java
  30. 1
    1
      src/com/droidquest/items/Turbine.java
  31. 3
    3
      src/com/droidquest/items/VendingHandle.java
  32. 3
    3
      src/com/droidquest/items/WallHandle.java
  33. 0
    1
      src/com/droidquest/materials/AntiPlayer.java
  34. 0
    1
      src/com/droidquest/materials/ElevatorDoor.java

+ 290
- 4
src/com/droidquest/DQ.java View File

@@ -2,6 +2,8 @@ package com.droidquest;
2 2
 
3 3
 //This is the source code for DroidQuest 2.7. Copyright 2003 by Thomas Foote.
4 4
 
5
+import com.droidquest.avatars.Avatar;
6
+import com.droidquest.avatars.LabCursor;
5 7
 import com.droidquest.levels.MainMenu;
6 8
 
7 9
 import javax.swing.*;
@@ -12,6 +14,19 @@ import java.util.Set;
12 14
 public class DQ extends JFrame implements ActionListener {
13 15
     private RoomDisplay myRoom;
14 16
 
17
+    private JCheckBoxMenuItem menuToggleHot = null;
18
+    private JMenuItem menuItemCursor = null;
19
+    private JMenuItem menuItemSolderpen = null;
20
+    private JMenuItem menuItemPaintbrush = null;
21
+    private JCheckBoxMenuItem menuItemRadio = null;
22
+    private JMenuItem menuItemToolbox = null;
23
+
24
+    private JMenuItem menuRotateRight = null;
25
+    private JMenuItem menuRotateLeft = null;
26
+    private JMenuItem menuLoadChip = null;
27
+
28
+    private JMenuItem menuFlipDevice = null;
29
+
15 30
     private DQ() {
16 31
         // Constructor
17 32
         super("DroidQuest");
@@ -27,8 +42,7 @@ public class DQ extends JFrame implements ActionListener {
27 42
         setIconImage(new ImageIcon("images/helper0.gif").getImage());
28 43
 
29 44
         Container contentPane = getContentPane();
30
-        myRoom = new RoomDisplay();
31
-        myRoom.dq = this;
45
+        myRoom = new RoomDisplay(this);
32 46
 
33 47
         addFocusListener(new FocusAdapter() {
34 48
             public void focusGained(FocusEvent e) {
@@ -41,6 +55,9 @@ public class DQ extends JFrame implements ActionListener {
41 55
 
42 56
         JMenuBar menuBar;
43 57
         JMenu fileMenu;
58
+        JMenu avatarMenu;
59
+        JMenu controlMenu;
60
+        JMenu helpMenu;
44 61
         JMenuItem menuItemSave;
45 62
         JMenuItem menuItemMain;
46 63
         JCheckBoxMenuItem menuItemSound;
@@ -66,6 +83,91 @@ public class DQ extends JFrame implements ActionListener {
66 83
         menuItemSound.addActionListener(this);
67 84
         menuItemExit.addActionListener(this);
68 85
 
86
+        avatarMenu = new JMenu("Avatar");
87
+        avatarMenu.setMnemonic(KeyEvent.VK_A);
88
+        menuBar.add(avatarMenu);
89
+
90
+
91
+        menuItemCursor = new JRadioButtonMenuItem("Cursor");
92
+        avatarMenu.add(menuItemCursor);
93
+        menuItemCursor.addActionListener(this);
94
+
95
+        menuItemSolderpen = new JRadioButtonMenuItem("Solderpen");
96
+        avatarMenu.add(menuItemSolderpen);
97
+        menuItemSolderpen.setEnabled(false);
98
+        menuItemSolderpen.addActionListener(this);
99
+
100
+        menuItemPaintbrush = new JRadioButtonMenuItem("Paintbrush");
101
+        avatarMenu.add(menuItemPaintbrush);
102
+        menuItemPaintbrush.setEnabled(false);
103
+        menuItemPaintbrush.addActionListener(this);
104
+
105
+        ButtonGroup menuItemAvatarButtonGroup = new ButtonGroup();
106
+        menuItemAvatarButtonGroup.add(menuItemCursor);
107
+        menuItemAvatarButtonGroup.add(menuItemSolderpen);
108
+        menuItemAvatarButtonGroup.add(menuItemPaintbrush);
109
+        menuItemCursor.setSelected(true);
110
+
111
+        controlMenu = new JMenu("Controls");
112
+        controlMenu.setMnemonic(KeyEvent.VK_C);
113
+        menuBar.add(controlMenu);
114
+
115
+
116
+        menuItemToolbox = new JMenuItem("Toolbox");
117
+        controlMenu.add(menuItemToolbox);
118
+        menuItemToolbox.addActionListener(this);
119
+
120
+        menuItemRadio = new JCheckBoxMenuItem("Radio");
121
+        controlMenu.add(menuItemRadio);
122
+        menuItemRadio.setSelected(false);
123
+        menuItemRadio.setEnabled(false);
124
+        menuItemRadio.addActionListener(this);
125
+
126
+        menuRotateRight = new JMenuItem("Rotate Part Clockwise");
127
+        controlMenu.add(menuRotateRight);
128
+        menuRotateRight.setEnabled(false);
129
+        menuRotateRight.addActionListener(this);
130
+
131
+        menuRotateLeft = new JMenuItem("Rotate Part Counter-clockwise");
132
+        controlMenu.add(menuRotateLeft);
133
+        menuRotateLeft.setEnabled(false);
134
+        menuRotateLeft.addActionListener(this);
135
+
136
+        menuToggleHot = new JCheckBoxMenuItem("Hot Cursor", false);
137
+        menuToggleHot.setEnabled(false);
138
+        controlMenu.add(menuToggleHot);
139
+        menuToggleHot.addActionListener(this);
140
+
141
+
142
+        menuLoadChip = new JMenuItem("Load Chip");
143
+        controlMenu.add(menuLoadChip);
144
+        menuLoadChip.setEnabled(false);
145
+        menuLoadChip.addActionListener(this);
146
+
147
+
148
+        JMenuItem menuEnterRobot = new JMenuItem("Enter Robot");
149
+        controlMenu.add(menuEnterRobot);
150
+        menuEnterRobot.addActionListener(this);
151
+
152
+        JMenuItem menuExitRobot = new JMenuItem("Exit Robot");
153
+        controlMenu.add(menuExitRobot);
154
+        menuExitRobot.addActionListener(this);
155
+
156
+        menuFlipDevice = new JMenuItem("Flip Device/Wire");
157
+        controlMenu.add(menuFlipDevice);
158
+        menuFlipDevice.setEnabled(false);
159
+        menuFlipDevice.addActionListener(this);
160
+
161
+        menuBar.add(Box.createHorizontalGlue());
162
+
163
+        helpMenu = new JMenu("Help");
164
+        helpMenu.setMnemonic(KeyEvent.VK_H);
165
+        menuBar.add(helpMenu);
166
+
167
+        JMenuItem helpInfo = new JMenuItem("Help");
168
+        helpMenu.add(helpInfo);
169
+        helpInfo.addActionListener(this);
170
+
69 171
         try {
70 172
             System.setErr(System.out);
71 173
         }
@@ -83,6 +185,98 @@ public class DQ extends JFrame implements ActionListener {
83 185
 
84 186
     }
85 187
 
188
+    public void setHotCursorSelected(boolean selected) {
189
+        if (null != this.menuToggleHot) {
190
+            this.menuToggleHot.setSelected(selected);
191
+        }
192
+    }
193
+
194
+    public void setHotCursorEnabled(boolean enabled) {
195
+        if (null != this.menuToggleHot) {
196
+            this.menuToggleHot.setEnabled(enabled);
197
+        }
198
+    }
199
+
200
+    public void setRotateEnabled(boolean enabled) {
201
+        if (null != this.menuRotateRight && null != this.menuRotateLeft) {
202
+            this.menuRotateRight.setEnabled(enabled);
203
+            this.menuRotateLeft.setEnabled(enabled);
204
+        }
205
+    }
206
+
207
+    public void setLoadChipEnabled(boolean enabled) {
208
+        if (null != this.menuLoadChip) {
209
+            this.menuLoadChip.setEnabled(enabled);
210
+        }
211
+    }
212
+
213
+    public void setFlipDeviceEnabled(boolean enabled) {
214
+        if(null != this.menuFlipDevice) {
215
+            this.menuFlipDevice.setEnabled(enabled);
216
+        }
217
+    }
218
+
219
+    public void setToolboxEnabled(boolean enabled) {
220
+        if (null != this.menuItemToolbox) {
221
+            this.menuItemToolbox.setEnabled(enabled);
222
+        }
223
+    }
224
+
225
+
226
+    public void selectCursor() {
227
+        if (null != this.menuItemCursor) {
228
+            this.menuItemCursor.setSelected(true);
229
+            if (null != myRoom && null != myRoom.level && myRoom.level.gameCursor instanceof LabCursor) {
230
+                setHotCursorEnabled(true);
231
+            }
232
+            setToolboxEnabled(true);
233
+        }
234
+    }
235
+
236
+    public void setSolderPenEnabled(boolean enabled) {
237
+        if (null != this.menuItemSolderpen) {
238
+            this.menuItemSolderpen.setEnabled(enabled);
239
+        }
240
+    }
241
+
242
+    public void selectSolderpen() {
243
+        if (null != this.menuItemSolderpen) {
244
+            this.menuItemSolderpen.setSelected(true);
245
+            this.setHotCursorEnabled(false);
246
+            setToolboxEnabled(false);
247
+            setFlipDeviceEnabled(true);
248
+        }
249
+    }
250
+
251
+    public void setPaintbrushEnabled(boolean enabled) {
252
+        if (null != this.menuItemPaintbrush) {
253
+            this.menuItemPaintbrush.setEnabled(enabled);
254
+            setFlipDeviceEnabled(false);
255
+        }
256
+    }
257
+
258
+    public void selectPaintBrush() {
259
+        if (null != this.menuItemPaintbrush) {
260
+            this.menuItemPaintbrush.setSelected(true);
261
+            this.setHotCursorEnabled(false);
262
+            this.setToolboxEnabled(false);
263
+        }
264
+    }
265
+
266
+
267
+    public void setRadioEnabled(boolean enabled) {
268
+        if (null != this.menuItemRadio) {
269
+            this.menuItemRadio.setEnabled(enabled);
270
+        }
271
+    }
272
+
273
+    public void setRadioSelected(boolean selected) {
274
+        if (null != this.menuItemRadio) {
275
+            this.menuItemRadio.setSelected(selected);
276
+        }
277
+    }
278
+
279
+
86 280
     public void actionPerformed(ActionEvent e) {
87 281
         if (e.getActionCommand().equals("Save Level")) {
88 282
             FileDialog fd = new FileDialog(this, "Save Level", FileDialog.SAVE);
@@ -95,14 +289,106 @@ public class DQ extends JFrame implements ActionListener {
95 289
                 myRoom.SaveLevel(fd.getDirectory() + fd.getFile());
96 290
             }
97 291
         }
98
-
99
-        if (e.getActionCommand().equals("Main Menu")) {
292
+        else if (e.getActionCommand().equals("Cursor")) {
293
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
294
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
295
+                playerAvatar.handleGameCursor();
296
+            }
297
+        }
298
+        else if (e.getActionCommand().equals("Solderpen")) {
299
+            // Handle Solderpen
300
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
301
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
302
+                playerAvatar.handleSolderPen();
303
+            }
304
+        }
305
+        else if (e.getActionCommand().equals("Paintbrush")) {
306
+            // Handle Paintbrush
307
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
308
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
309
+                playerAvatar.handlePaintbrush();
310
+            }
311
+        }
312
+        else if (e.getActionCommand().equals("Toolbox")) {
313
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
314
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
315
+                playerAvatar.handleToolbox();
316
+            }
317
+        }
318
+        else if (e.getActionCommand().equals("Radio")) {
319
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
320
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
321
+                playerAvatar.handleRadio();
322
+            }
323
+        }
324
+        else if (e.getActionCommand().equals("Rotate Part Clockwise")) {
325
+            // Rotate a part clockwise
326
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
327
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
328
+                playerAvatar.handleRotateDevice(1);
329
+            }
330
+        }
331
+        else if (e.getActionCommand().equals("Rotate Part Counter-clockwise")) {
332
+            // Rotate counter clockwise
333
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
334
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
335
+                playerAvatar.handleRotateDevice(-1);
336
+            }
337
+        }
338
+        else if (e.getActionCommand().equals("Hot Cursor")) {
339
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
340
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
341
+                playerAvatar.handleHotCursor();
342
+            }
343
+        }
344
+        else if (e.getActionCommand().equals("Load Chip")) {
345
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
346
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
347
+                playerAvatar.handleLoadSmallChip();
348
+            }
349
+        }
350
+        else if (e.getActionCommand().equals("Help")) {
351
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
352
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
353
+                playerAvatar.handleHelp();
354
+            }
355
+        }
356
+        else if (e.getActionCommand().equals("Enter Robot")) {
357
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
358
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
359
+                playerAvatar.handleEnterRoom();
360
+            }
361
+        }
362
+        else if (e.getActionCommand().equals("Exit Robot")) {
363
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
364
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
365
+                playerAvatar.handleExitRoom();
366
+            }
367
+        }
368
+        else if (e.getActionCommand().equals("Flip Device/Wire")) {
369
+            if (null != myRoom.level && null != myRoom.level.player && myRoom.level.player instanceof Avatar) {
370
+                Avatar playerAvatar = (Avatar) myRoom.level.player;
371
+                playerAvatar.handleFlipDevice();
372
+            }
373
+        }
374
+        else if (e.getActionCommand().equals("Main Menu")) {
100 375
             int n = JOptionPane.showConfirmDialog(this, "Do you want to quit this level?",
101 376
                     "return to Main Menu", JOptionPane.YES_NO_OPTION);
102 377
             if (n == 0) {
103 378
                 myRoom.level.Empty();
104 379
                 myRoom.level = new MainMenu(myRoom);
105 380
                 myRoom.level.Init();
381
+                setHotCursorEnabled(false);
382
+                setHotCursorSelected(false);
383
+                setRotateEnabled(false);
384
+                setLoadChipEnabled(false);
385
+                setPaintbrushEnabled(false);
386
+                setFlipDeviceEnabled(false);
387
+                setToolboxEnabled(false);
388
+                setSolderPenEnabled(false);
389
+                setRadioSelected(false);
390
+                setRadioEnabled(false);
391
+                selectCursor();
106 392
             }
107 393
         }
108 394
 

+ 44
- 4
src/com/droidquest/RoomDisplay.java View File

@@ -20,7 +20,7 @@ import java.lang.reflect.Constructor;
20 20
 import java.lang.reflect.InvocationTargetException;
21 21
 
22 22
 public class RoomDisplay extends JPanel {
23
-    public DQ dq;
23
+    public final DQ dq;
24 24
     Level level;
25 25
     public Timer timer;
26 26
     private int timerspeed = 128;
@@ -36,7 +36,8 @@ public class RoomDisplay extends JPanel {
36 36
         return (true);
37 37
     }
38 38
 
39
-    public RoomDisplay() {
39
+    public RoomDisplay(final DQ dq) {
40
+        this.dq = dq;
40 41
         setSize(new Dimension(560, 384));
41 42
         level = new MainMenu(this);
42 43
         level.Init();
@@ -188,6 +189,45 @@ public class RoomDisplay extends JPanel {
188 189
 
189 190
                     level.roomdisplay.useSounds = tempsound;
190 191
                     level.PlaySound(level.currentViewer.room, Level.TRANSPORTSOUND);
192
+
193
+
194
+                    // Handle menu item initialization
195
+                    if (level.gameCursor instanceof LabCursor) {
196
+                        dq.setHotCursorSelected(false);
197
+                        dq.setHotCursorEnabled(true);
198
+                    }
199
+                    else {
200
+                        dq.setHotCursorSelected(false);
201
+                        dq.setHotCursorEnabled(false);
202
+                    }
203
+
204
+                    if(null == level.solderingPen) {
205
+                        dq.setSolderPenEnabled(false);
206
+                    }
207
+                    else {
208
+                        dq.setSolderPenEnabled(true);
209
+                    }
210
+
211
+                    if(null == level.paintbrush) {
212
+                        dq.setPaintbrushEnabled(false);
213
+                    }
214
+                    else {
215
+                        dq.setPaintbrushEnabled(true);
216
+                    }
217
+
218
+                    if(null == level.remote) {
219
+                        dq.setRadioEnabled(false);
220
+                        dq.setRadioSelected(false);
221
+                    }
222
+                    else {
223
+                        dq.setRadioEnabled(true);
224
+                        dq.setRadioSelected(true);
225
+                    }
226
+
227
+                    // Always start with cursor
228
+                    dq.selectCursor();
229
+
230
+
191 231
                 }
192 232
                 Electricity();
193 233
                 for (int a = 0; a < level.items.size(); a++) {
@@ -210,7 +250,7 @@ public class RoomDisplay extends JPanel {
210 250
 
211 251
                 repaint();
212 252
                 for (int a = 0; a < level.sparks.size(); a++) {
213
-                    Spark spark = (Spark) level.sparks.elementAt(a);
253
+                    Spark spark = level.sparks.elementAt(a);
214 254
                     spark.Age();
215 255
                     if (spark.age > 6) {
216 256
                         level.sparks.removeElement(spark);
@@ -284,7 +324,7 @@ public class RoomDisplay extends JPanel {
284 324
 
285 325
         // Paint Sparks
286 326
         for (int a = 0; a < level.sparks.size(); a++) {
287
-            Spark spark = (Spark) level.sparks.elementAt(a);
327
+            Spark spark = level.sparks.elementAt(a);
288 328
             if (spark.room == level.currentViewer.room) {
289 329
                 spark.Draw(g2);
290 330
             }

+ 83
- 0
src/com/droidquest/avatars/Avatar.java View File

@@ -0,0 +1,83 @@
1
+package com.droidquest.avatars;
2
+
3
+/**
4
+ * Interface to support handling a common interface for player types.
5
+ * Particularly, since SolderingPen needs to be a Device, this can
6
+ * be used to provide a player avatar contract.
7
+ */
8
+public interface Avatar {
9
+
10
+    /**
11
+     * Handle change to game cursor.
12
+     * @return boolean whether the change was handled.
13
+     */
14
+    public boolean handleGameCursor();
15
+
16
+    /**
17
+     * Handle change to solder pen.
18
+     * @return boolean whether the change was handled.
19
+     */
20
+    public boolean handleSolderPen();
21
+
22
+    /**
23
+     * Handle opening / summoning the toolbox
24
+     * @return boolean whether the change was handled.
25
+     */
26
+    public boolean handleToolbox();
27
+
28
+    /**
29
+     * Handle starting / stopping the remote.
30
+     * @return boolean whether the change was handled.
31
+     */
32
+    public boolean handleRadio();
33
+
34
+    /**
35
+     * Handle rotating a Device object
36
+     * @param direction -1 for counter clockwise, 1 for clockwise
37
+     * @return boolean whether the change was handled.
38
+     */
39
+    public boolean handleRotateDevice(int direction);
40
+
41
+    /**
42
+     * Handle setting the cursor to hot.
43
+     * @return boolean whether the change was handled.
44
+     */
45
+    public boolean handleHotCursor();
46
+
47
+    /**
48
+     * Handle transforming player to the paintbrush
49
+     * @return boolean whether the change was handled.
50
+     */
51
+    public boolean handlePaintbrush();
52
+
53
+    /**
54
+     * Handle loading a small chip from a saved program.
55
+     * @return boolean whether the change was handled.
56
+     */
57
+    public boolean handleLoadSmallChip();
58
+
59
+    /**
60
+     * Handle context specific help (including chip help)
61
+     * @return boolean whether the change was handled.
62
+     */
63
+    public boolean handleHelp();
64
+
65
+    /**
66
+     * Handle entering an inner room (robot)
67
+     * @return boolean whether the change was handled.
68
+     */
69
+    public boolean handleEnterRoom();
70
+
71
+    /**
72
+     * Handle exiting an inner room (robot)
73
+     * @return boolean whether the change was handled.
74
+     */
75
+    public boolean handleExitRoom();
76
+
77
+    /**
78
+     * Handle flipping a device - either state or direction.
79
+     * @return boolean whether the change was handled.
80
+     */
81
+    public boolean handleFlipDevice();
82
+
83
+}

+ 37
- 364
src/com/droidquest/avatars/GameCursor.java View File

@@ -2,20 +2,13 @@ package com.droidquest.avatars;
2 2
 
3 3
 import com.droidquest.Room;
4 4
 import com.droidquest.RoomDisplay;
5
-import com.droidquest.devices.Device;
6
-import com.droidquest.devices.GenericChip;
7
-import com.droidquest.devices.SmallChip;
8
-import com.droidquest.items.GenericRobot;
9
-import com.droidquest.items.Item;
10
-import com.droidquest.items.ToolBox;
11
-import com.droidquest.items.Train;
5
+import com.droidquest.items.*;
12 6
 
13 7
 import javax.swing.*;
14 8
 import java.awt.*;
15
-import java.awt.event.KeyEvent;
16 9
 import java.awt.image.BufferedImage;
17 10
 
18
-public class GameCursor extends Item {
11
+public class GameCursor extends Player {
19 12
     private int walk = 0; // 0 or 1, used in animation
20 13
     private boolean outline; // Draw outline around GameCursor?
21 14
 
@@ -268,74 +261,30 @@ public class GameCursor extends Item {
268 261
 
269 262
     }
270 263
 
271
-    public void MoveUp(boolean nudge) {
272
-        Item item = level.FindNearestItem(this);
273
-        if (item != null) {
274
-            if (item.InternalRoom != null) {
275
-                if (item.UpEnterOverlap(this)) {
276
-                    int newX = 280; // 10 * 28
277
-                    int newY = 320; // 10 * 32
278
-                    x = newX;
279
-                    y = newY;
280
-                    SetRoom(item.InternalRoom);
281
-                }
282
-            }
283
-        }
284
-        super.MoveUp(nudge);
264
+    @Override
265
+    public void moveUp(boolean nudge) {
266
+        super.moveUp(nudge);
285 267
         walk = 1 - walk;
286 268
         currentIcon = icons[0 + walk].getImage();
287 269
     }
288 270
 
289
-    public void MoveDown(boolean nudge) {
290
-        Item item = level.FindNearestItem(this);
291
-        if (item != null) {
292
-            if (item.InternalRoom != null) {
293
-                if (item.DownEnterOverlap(this)) {
294
-                    int newX = 280; // 10 * 28
295
-                    int newY = 0; //  0 * 32
296
-                    x = newX;
297
-                    y = newY;
298
-                    SetRoom(item.InternalRoom);
299
-                }
300
-            }
301
-        }
302
-        super.MoveDown(nudge);
271
+    @Override
272
+    public void moveDown(boolean nudge) {
273
+        super.moveDown(nudge);
303 274
         walk = 1 - walk;
304 275
         currentIcon = icons[2 + walk].getImage();
305 276
     }
306 277
 
307
-    public void MoveLeft(boolean nudge) {
308
-        Item item = level.FindNearestItem(this);
309
-        if (item != null) {
310
-            if (item.InternalRoom != null) {
311
-                if (item.LeftEnterOverlap(this)) {
312
-                    int newX = 532; // 19 * 28
313
-                    int newY = 176; // 5.5 * 32
314
-                    x = newX;
315
-                    y = newY;
316
-                    SetRoom(item.InternalRoom);
317
-                }
318
-            }
319
-        }
320
-        super.MoveLeft(nudge);
278
+    @Override
279
+    public void moveLeft(boolean nudge) {
280
+        super.moveLeft(nudge);
321 281
         walk = 1 - walk;
322 282
         currentIcon = icons[4 + walk].getImage();
323 283
     }
324 284
 
325
-    public void MoveRight(boolean nudge) {
326
-        Item item = level.FindNearestItem(this);
327
-        if (item != null) {
328
-            if (item.InternalRoom != null) {
329
-                if (item.RightEnterOverlap(this)) {
330
-                    int newX = 0; // 0 * 28
331
-                    int newY = 176; // 5.5 * 32
332
-                    x = newX;
333
-                    y = newY;
334
-                    SetRoom(item.InternalRoom);
335
-                }
336
-            }
337
-        }
338
-        super.MoveRight(nudge);
285
+    @Override
286
+    public void moveRight(boolean nudge) {
287
+        super.moveRight(nudge);
339 288
         walk = 1 - walk;
340 289
         currentIcon = icons[6 + walk].getImage();
341 290
     }
@@ -352,303 +301,27 @@ public class GameCursor extends Item {
352 301
         return !i.getClass().toString().endsWith("Robot");
353 302
     }
354 303
 
355
-    public boolean KeyUp(KeyEvent e) {
356
-        if (e.getKeyCode() == KeyEvent.VK_L) {
357
-            if (carrying != null) {
358
-                if (carrying instanceof SmallChip) {
359
-                    FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
360
-                    fd.setDirectory("chips");
361
-                    fd.show();
362
-                    System.out.println("Dialog returned with "
363
-                            + fd.getDirectory()
364
-                            + fd.getFile());
365
-                    if (fd.getFile() != null) {
366
-                        ((SmallChip) carrying).Empty();
367
-                        ((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
368
-                    }
369
-                }
370
-            }
371
-        }
372
-        if (e.getKeyCode() == KeyEvent.VK_S) {
373
-            if (level.solderingPen == null) {
374
-                return false;
375
-            }
376
-            if (carrying != null) {
377
-                Drops();
378
-            }
379
-            level.solderingPen.x = x;
380
-            level.solderingPen.y = y;
381
-            level.solderingPen.room = room;
382
-            room = null;
383
-            if (level.currentViewer == level.player) {
384
-                level.currentViewer = level.solderingPen;
385
-            }
386
-            level.player = level.solderingPen;
387
-            if (level.remote != null) {
388
-                if (level.remote.carriedBy != null) {
389
-                    level.remote.carriedBy = level.player;
390
-                }
391
-            }
392
-        }
393
-        if (e.getKeyCode() == KeyEvent.VK_R) {
394
-            if (level.remote == null) {
395
-                return false;
396
-            }
397
-            if (level.remote.carriedBy == null) { // Summon Remote
398
-                level.remote.x = 28;
399
-                level.remote.y = -20;
400
-                level.remote.carriedBy = level.player;
401
-                level.remote.room = level.player.room;
402
-                level.electricity = true;
403
-            }
404
-            else { // Hide Remote
405
-                level.remote.carriedBy = null;
406
-                level.remote.room = null;
407
-                level.electricity = false;
408
-            }
409
-            //	     if (carrying != null)
410
-            //	       Drops();
411
-            //	     level.remote.x = x;
412
-            //	     level.remote.y = y;
413
-            //	     level.remote.room = room;
414
-            //	     room = null;
415
-            //	     if (level.currentViewer == level.player)
416
-            //	       level.currentViewer=level.remote;
417
-            //	     level.player = level.remote;
418
-        }
419
-        if (e.getKeyCode() == KeyEvent.VK_T) {
420
-            if (level.toolbox == null) {
421
-                if (carrying != null) {
422
-                    Drops();
423
-                }
424
-                level.toolbox = new ToolBox(x, y + 8, room);
425
-                level.items.addElement(level.toolbox);
426
-                ((ToolBox) level.toolbox).Toggle();
427
-                PicksUp(level.toolbox);
428
-            }
429
-            if (level.toolbox.room != room) {
430
-                // Summon Toolbox
431
-                if (carrying != null) {
432
-                    return false;
433
-                }
434
-                if (((ToolBox) level.toolbox).open) {
435
-                    ((ToolBox) level.toolbox).Toggle();
436
-                }
437
-                level.toolbox.room = room;
438
-                level.toolbox.x = x + 28;
439
-                level.toolbox.y = y + 6;
440
-                PicksUp(level.toolbox);
441
-            }
442
-            else {
443
-                ((ToolBox) level.toolbox).Toggle();
444
-            }
445
-        }
446
-        if (e.getKeyCode() == KeyEvent.VK_SLASH) {
447
-            if (carrying != null) {
448
-                if (carrying instanceof GenericChip) {
449
-                    ((GenericChip) carrying).ShowText(true);
450
-                    return false;
451
-                }
452
-            }
453
-            if (level.helpCam == null) {
454
-                return false;
455
-            }
456
-            level.player = level.helpCam;
457
-            level.currentViewer = level.helpCam;
458
-        }
459
-        if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
460
-            if (level.cheatmode) {
461
-                if (e.isShiftDown() && room != null) {
462
-                    SetRoom(room.rightRoom);
463
-                }
464
-            }
465
-            if (carriedBy == null) {
466
-                MoveRight(e.isControlDown());
467
-            }
468
-            repeating = 0;
469
-            return true;
470
-        }
471
-        if (e.getKeyCode() == KeyEvent.VK_LEFT) {
472
-            if (level.cheatmode) {
473
-                if (e.isShiftDown() && room != null) {
474
-                    SetRoom(room.leftRoom);
475
-                }
476
-            }
477
-            if (carriedBy == null) {
478
-                MoveLeft(e.isControlDown());
479
-            }
480
-            repeating = 0;
481
-            return true;
482
-        }
483
-        if (e.getKeyCode() == KeyEvent.VK_UP) {
484
-            if (level.cheatmode) {
485
-                if (e.isShiftDown() && room != null) {
486
-                    SetRoom(room.upRoom);
487
-                }
488
-            }
489
-            if (carriedBy == null) {
490
-                MoveUp(e.isControlDown());
491
-            }
492
-            repeating = 0;
493
-            return true;
494
-        }
495
-        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
496
-            if (level.cheatmode) {
497
-                if (e.isShiftDown() && room != null) {
498
-                    SetRoom(room.downRoom);
499
-                }
500
-            }
501
-            if (carriedBy == null) {
502
-                MoveDown(e.isControlDown());
503
-            }
504
-            repeating = 0;
505
-            return true;
506
-        }
507
-        if (e.getKeyCode() == KeyEvent.VK_SPACE) {
508
-            {
509
-                Item item = level.FindNearestItem(level.gameCursor);
510
-                if (item != null) {
511
-                    if (item instanceof Train) {
512
-                        item.CanBePickedUp(this);
513
-                        return false;
514
-                    }
515
-                }
516
-            }
517 304
 
518
-            if (carrying != null) {
519
-                Drops();
520
-            }
521
-            else {
522
-                Item item = level.FindNearestItem(level.gameCursor);
523
-                if (item != null) {
524
-                    if (item.CanBePickedUp(level.gameCursor)) {
525
-                        PicksUp(item);
526
-                    }
527
-                }
528
-            }
529
-            outline = false;
530
-            return false;
531
-        }
532
-        if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET) {
533
-            if (carrying != null) {
534
-                if (carrying.isDevice()) {
535
-                    ((Device) carrying).rotate(1);
536
-                }
537
-            }
538
-            return false;
539
-        }
540
-        if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) {
541
-            if (carrying != null) {
542
-                if (carrying.isDevice()) {
543
-                    ((Device) carrying).rotate(-1);
544
-                }
545
-            }
546
-            return false;
547
-        }
548
-        if (e.getKeyCode() == KeyEvent.VK_E) {
549
-            Item item = level.FindNearestItem(this);
550
-            if (item != null) {
551
-                if (item.InternalRoom != null) {
552
-                    if (Overlaps(item))
553
-                    //		 if (x>=item.x && y>=item.y
554
-                    //		     && x+width <= item.x + item.width
555
-                    //		     && y+height <= item.y + item.height)
556
-                    {
557
-                        if (!item.OverWall()) {
558
-                            int newX = 280; // 10 * 28
559
-                            int newY = 176; // 5.5 * 32
560
-                            x = newX;
561
-                            y = newY;
562
-                            SetRoom(item.InternalRoom);
563
-                        }
564
-                    }
565
-                }
566
-            }
567
-        }
568
-        if (e.getKeyCode() == KeyEvent.VK_X) {
569
-            if (room != null && room.portalItem != null) {
570
-                Dimension d = room.portalItem.GetXY();
571
-                int newX = d.width
572
-                        + room.portalItem.getWidth() / 2
573
-                        - width / 2;
574
-                int newY = d.height
575
-                        + room.portalItem.getHeight() / 4 * 2
576
-                        - height / 2;
577
-                x = newX;
578
-                y = newY;
579
-                SetRoom(room.portalItem.room);
580
-                level.currentViewer = level.player;
581
-            }
582
-        }
583
-        if (e.getKeyCode() == KeyEvent.VK_F) {
584
-            if (carrying != null) {
585
-                if (carrying instanceof Device) {
586
-                    ((Device) carrying).flip();
587
-                }
305
+    @Override
306
+    protected boolean handleTrain() {
307
+        Item item = level.FindNearestItem(level.gameCursor);
308
+        if (item != null) {
309
+            if (item instanceof Train) {
310
+                item.CanBePickedUp(this);
311
+                return true;
588 312
             }
589 313
         }
590
-        if (e.getKeyCode() == KeyEvent.VK_M) {
591
-            Runtime runtime = Runtime.getRuntime();
592
-            long freemem = runtime.freeMemory();
593
-            long totalmem = runtime.totalMemory();
594
-            System.out.println("Total Memory = " + totalmem
595
-                    + ", (" + totalmem / 1024 + "K), ("
596
-                    + totalmem / 1024 / 1024 + "M)");
597
-            System.out.println("Free Memory = " + freemem
598
-                    + ", (" + freemem / 1024 + "K), ("
599
-                    + freemem / 1024 / 1024 + "M)");
600
-        }
601
-
602 314
         return false;
603 315
     }
604 316
 
605
-    public boolean KeyDown(KeyEvent e) {
606
-        if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
607
-            repeating++;
608
-            if (repeating > 5) {
609
-                if (carriedBy == null) {
610
-                    MoveRight(e.isControlDown());
611
-                }
612
-                return true;
613
-            }
614
-            return false;
615
-        }
616
-        if (e.getKeyCode() == KeyEvent.VK_LEFT) {
617
-            repeating++;
618
-            if (repeating > 5) {
619
-                if (carriedBy == null) {
620
-                    MoveLeft(e.isControlDown());
621
-                }
622
-                return true;
623
-            }
624
-            return false;
625
-        }
626
-        if (e.getKeyCode() == KeyEvent.VK_UP) {
627
-            repeating++;
628
-            if (repeating > 5) {
629
-                if (carriedBy == null) {
630
-                    MoveUp(e.isControlDown());
631
-                }
632
-                return true;
633
-            }
634
-            return false;
635
-        }
636
-        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
637
-            repeating++;
638
-            if (repeating > 5) {
639
-                if (carriedBy == null) {
640
-                    MoveDown(e.isControlDown());
641
-                }
642
-                return true;
643
-            }
644
-            return false;
645
-        }
646
-        if (e.getKeyCode() == KeyEvent.VK_SPACE) {
647
-            if (level.player == level.gameCursor) {
648
-                outline = true;
649
-            }
650
-        }
651
-        return false;
317
+    @Override
318
+    protected void setOutline(boolean outline) {
319
+        this.outline = outline;
320
+    }
321
+
322
+    @Override
323
+    protected boolean isCheatMode() {
324
+        return level.cheatmode;
652 325
     }
653 326
 
654 327
     public void Animate() {
@@ -692,38 +365,38 @@ public class GameCursor extends Item {
692 365
                 }
693 366
             }
694 367
             if (dx > 0) {
695
-                MoveRight(dx);
368
+                moveRight(dx);
696 369
             }
697 370
             if (dx < 0) {
698
-                MoveLeft(-dx);
371
+                moveLeft(-dx);
699 372
             }
700 373
             if (dy > 0) {
701
-                MoveDown(dy);
374
+                moveDown(dy);
702 375
             }
703 376
             if (dy < 0) {
704
-                MoveUp(-dy);
377
+                moveUp(-dy);
705 378
             }
706 379
         }
707 380
         if (automove == 2) {
708 381
             walk = 1 - walk;
709 382
             if (autoX > 0) {
710 383
                 currentIcon = icons[6 + walk].getImage();
711
-                MoveRight(autoX);
384
+                moveRight(autoX);
712 385
             }
713 386
 
714 387
             if (autoX < 0) {
715 388
                 currentIcon = icons[4 + walk].getImage();
716
-                MoveLeft(-autoX);
389
+                moveLeft(-autoX);
717 390
             }
718 391
 
719 392
             if (autoY > 0) {
720 393
                 currentIcon = icons[2 + walk].getImage();
721
-                MoveDown(autoY);
394
+                moveDown(autoY);
722 395
             }
723 396
 
724 397
             if (autoY < 0) {
725 398
                 currentIcon = icons[0 + walk].getImage();
726
-                MoveUp(-autoY);
399
+                moveUp(-autoY);
727 400
             }
728 401
         }
729 402
     }

+ 60
- 1
src/com/droidquest/avatars/HelpCam.java View File

@@ -8,7 +8,7 @@ import java.awt.*;
8 8
 import java.awt.event.KeyEvent;
9 9
 import java.awt.image.BufferedImage;
10 10
 
11
-public class HelpCam extends Item {
11
+public class HelpCam extends Item implements Avatar {
12 12
     public HelpCam(Room r) {
13 13
         charge = 0;
14 14
         x = 28;
@@ -38,4 +38,63 @@ public class HelpCam extends Item {
38 38
     }
39 39
 
40 40
 
41
+    @Override
42
+    public boolean handleGameCursor() {
43
+        return false;
44
+    }
45
+
46
+    @Override
47
+    public boolean handleSolderPen() {
48
+        return false;
49
+    }
50
+
51
+    @Override
52
+    public boolean handleToolbox() {
53
+        return false;
54
+    }
55
+
56
+    @Override
57
+    public boolean handleRadio() {
58
+        return false;
59
+    }
60
+
61
+    @Override
62
+    public boolean handleRotateDevice(int direction) {
63
+        return false;
64
+    }
65
+
66
+    @Override
67
+    public boolean handleHotCursor() {
68
+        return false;
69
+    }
70
+
71
+    @Override
72
+    public boolean handlePaintbrush() {
73
+        return false;
74
+    }
75
+
76
+    @Override
77
+    public boolean handleLoadSmallChip() {
78
+        return false;
79
+    }
80
+
81
+    @Override
82
+    public boolean handleHelp() {
83
+        return false;
84
+    }
85
+
86
+    @Override
87
+    public boolean handleEnterRoom() {
88
+        return false;
89
+    }
90
+
91
+    @Override
92
+    public boolean handleExitRoom() {
93
+        return false;
94
+    }
95
+
96
+    @Override
97
+    public boolean handleFlipDevice() {
98
+        return false;
99
+    }
41 100
 }

+ 70
- 336
src/com/droidquest/avatars/LabCursor.java View File

@@ -1,8 +1,6 @@
1 1
 package com.droidquest.avatars;
2 2
 
3 3
 import com.droidquest.Room;
4
-import com.droidquest.devices.Device;
5
-import com.droidquest.devices.GenericChip;
6 4
 import com.droidquest.devices.SmallChip;
7 5
 import com.droidquest.items.GenericRobot;
8 6
 import com.droidquest.items.Item;
@@ -10,14 +8,12 @@ import com.droidquest.items.ToolBox;
10 8
 
11 9
 import javax.swing.*;
12 10
 import java.awt.*;
13
-import java.awt.event.KeyEvent;
14 11
 import java.awt.image.BufferedImage;
15 12
 
16
-public class LabCursor extends Item {
13
+public class LabCursor extends Player {
17 14
     public boolean hot;
18 15
 
19 16
 
20
-
21 17
     public LabCursor(int X, int Y, Room r) {
22 18
         x = X;
23 19
         y = Y;
@@ -26,6 +22,10 @@ public class LabCursor extends Item {
26 22
         width = 28;
27 23
         height = 32;
28 24
         GenerateIcons();
25
+
26
+        // Lab cursor has a longer key repeat rate than the game cursor
27
+        setKeyRepeatRate(10);
28
+
29 29
     }
30 30
 
31 31
     public void GenerateIcons() {
@@ -63,359 +63,93 @@ public class LabCursor extends Item {
63 63
         return !(i instanceof GenericRobot);
64 64
     }
65 65
 
66
-    public boolean KeyUp(KeyEvent e) {
67
-        if (e.getKeyCode() == KeyEvent.VK_L) {
68
-            if (carrying != null) {
69
-                if (carrying instanceof SmallChip) {
70
-                    FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
71
-                    fd.setDirectory("chips");
72
-                    fd.show();
73
-                    System.out.println("Dialog returned with "
74
-                            + fd.getDirectory()
75
-                            + fd.getFile());
76
-                    if (fd.getFile() != null) {
77
-                        ((SmallChip) carrying).Empty();
78
-                        ((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
79
-                    }
80
-                }
81
-            }
82
-        }
83
-        else if (e.getKeyCode() == KeyEvent.VK_H) {
84
-            hot = !hot;
85
-            if (hot) {
86
-                currentIcon = icons[1].getImage();
87
-            }
88
-            else {
89
-                currentIcon = icons[0].getImage();
90
-            }
91
-            return false;
92
-        }
93
-        else if (e.getKeyCode() == KeyEvent.VK_S) {
94
-            if (level.solderingPen == null) {
95
-                return false;
96
-            }
97
-            if (carrying != null) {
98
-                if (carrying instanceof SmallChip) {
99
-                    FileDialog fd = new FileDialog(level.roomdisplay.dq, "Save Chip", FileDialog.SAVE);
100
-                    fd.setDirectory("chips");
101
-                    fd.show();
102
-                    System.out.println("Dialog returned with "
103
-                            + fd.getDirectory()
104
-                            + fd.getFile());
105
-                    if (fd.getFile() != null) {
106
-                        ((SmallChip) carrying).SaveChip(fd.getDirectory() + fd.getFile());
107
-                    }
108
-                    return false;
109
-                }
110
-            }
111
-            if (carrying != null) {
112
-                Drops();
113
-            }
114
-            level.solderingPen.x = x;
115
-            level.solderingPen.y = y;
116
-            level.solderingPen.room = room;
117
-            room = null;
118
-            if (level.currentViewer == level.player) {
119
-                level.currentViewer = level.solderingPen;
120
-            }
121
-            level.player = level.solderingPen;
122
-            if (level.remote != null) {
123
-                if (level.remote.carriedBy != null) {
124
-                    level.remote.carriedBy = level.player;
125
-                }
126
-            }
127
-        }
128
-        else if (e.getKeyCode() == KeyEvent.VK_R) {
129
-            if (level.remote == null) {
130
-                return false;
131
-            }
132
-            if (level.remote.carriedBy == null) { // Summon Remote
133
-                level.remote.x = 28;
134
-                level.remote.y = -20;
135
-                level.remote.carriedBy = level.player;
136
-                level.remote.room = level.player.room;
137
-                level.electricity = true;
138
-            }
139
-            else { // Hide Remote
140
-                level.remote.carriedBy = null;
141
-                level.remote.room = null;
142
-                level.electricity = false;
143
-            }
144
-//	     if (carrying != null)
145
-//	       Drops();
146
-//	     level.remote.x = x;
147
-//	     level.remote.y = y;
148
-//	     level.remote.room = room;
149
-//	     room = null;
150
-//	     if (level.currentViewer == level.player)
151
-//	       level.currentViewer=level.remote;
152
-//	     level.player = level.remote;
153
-        }
154
-        else if (e.getKeyCode() == KeyEvent.VK_P) {
155
-            if (level.paintbrush == null) {
156
-                return false;
157
-            }
158
-            if (carrying != null) {
159
-                Drops();
160
-            }
161
-            level.paintbrush.x = (x / 28) * 28;
162
-            level.paintbrush.y = (y / 32) * 32;
163
-            level.paintbrush.room = room;
164
-            room = null;
165
-            if (level.currentViewer == level.player) {
166
-                level.currentViewer = level.paintbrush;
167
-            }
168
-            level.player = level.paintbrush;
169
-        }
170
-        else if (e.getKeyCode() == KeyEvent.VK_T) {
171
-            if (level.toolbox == null) {
172
-                return false;
173
-            }
174
-            if (level.toolbox.room != room) {
175
-                // Summon Toolbox
176
-                if (carrying != null) {
177
-                    return false;
178
-                }
179
-                if (((ToolBox) level.toolbox).open) {
180
-                    ((ToolBox) level.toolbox).Toggle();
181
-                }
182
-                level.toolbox.room = room;
183
-                level.toolbox.x = x + 28;
184
-                level.toolbox.y = y + 6;
185
-                PicksUp(level.toolbox);
186
-            }
187
-            else {
188
-                ((ToolBox) level.toolbox).Toggle();
189
-            }
190
-        }
191
-        else if (e.getKeyCode() == KeyEvent.VK_SLASH) {
192
-            if (carrying != null) {
193
-                if (carrying instanceof GenericChip) {
194
-                    ((GenericChip) carrying).ShowText(true);
195
-                    return false;
66
+
67
+    @Override
68
+    protected boolean handleSaveSmallChip() {
69
+        if (carrying != null) {
70
+            if (carrying instanceof SmallChip) {
71
+                FileDialog fd = new FileDialog(level.roomdisplay.dq, "Save Chip", FileDialog.SAVE);
72
+                fd.setDirectory("chips");
73
+                fd.show();
74
+                System.out.println("Dialog returned with "
75
+                        + fd.getDirectory()
76
+                        + fd.getFile());
77
+                if (fd.getFile() != null) {
78
+                    ((SmallChip) carrying).SaveChip(fd.getDirectory() + fd.getFile());
196 79
                 }
80
+                return true;
197 81
             }
198
-            if (level.helpCam == null) {
199
-                return false;
200
-            }
201
-            level.player = level.helpCam;
202
-            level.currentViewer = level.helpCam;
203
-        }
204
-        else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
205
-            if (carriedBy == null) {
206
-                MoveRight(e.isControlDown());
207
-            }
208
-            repeating = 0;
209
-            return true;
210
-        }
211
-        else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
212
-            if (carriedBy == null) {
213
-                MoveLeft(e.isControlDown());
214
-            }
215
-            repeating = 0;
216
-            return true;
217
-        }
218
-        else if (e.getKeyCode() == KeyEvent.VK_UP) {
219
-            if (carriedBy == null) {
220
-                MoveUp(e.isControlDown());
221
-            }
222
-            repeating = 0;
223
-            return true;
224
-        }
225
-        else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
226
-            if (carriedBy == null) {
227
-                MoveDown(e.isControlDown());
228
-            }
229
-            repeating = 0;
230
-            return true;
231 82
         }
232
-        else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
233
-            if (carrying != null) {
234
-                Drops();
235
-            }
236
-            else {
237
-                Item item = level.FindNearestItem(level.gameCursor);
238
-                if (item != null) {
239
-                    if (item.CanBePickedUp(level.gameCursor)) {
240
-                        PicksUp(item);
241
-                    }
242
-                }
243
-            }
244
-            return false;
83
+        return false;
84
+    }
85
+
86
+
87
+    @Override
88
+    public boolean handleHotCursor() {
89
+        hot = !hot;
90
+        if (hot) {
91
+            currentIcon = icons[1].getImage();
245 92
         }
246
-        else if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET) {
247
-            if (carrying != null) {
248
-                if (carrying.isDevice()) {
249
-                    ((Device) carrying).rotate(1);
250
-                }
251
-            }
252
-            return false;
93
+        else {
94
+            currentIcon = icons[0].getImage();
253 95
         }
254
-        else if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) {
255
-            if (carrying != null) {
256
-                if (carrying.isDevice()) {
257
-                    ((Device) carrying).rotate(-1);
258
-                }
259
-            }
96
+
97
+        this.room.level.roomdisplay.dq.setHotCursorSelected(hot);
98
+
99
+        return true;
100
+    }
101
+
102
+    @Override
103
+    public boolean handlePaintbrush() {
104
+        if (level.paintbrush == null) {
260 105
             return false;
261 106
         }
262
-        else if (e.getKeyCode() == KeyEvent.VK_E) {
263
-            Item item = level.FindNearestItem(this);
264
-            if (item != null) {
265
-                if (item.InternalRoom != null) {
266
-                    if (Overlaps(item)) {
267
-                        if (!item.OverWall()) {
268
-                            int newX = 280; // 10 * 28
269
-                            int newY = 176; // 5.5 * 32
270
-                            x = newX;
271
-                            y = newY;
272
-                            SetRoom(item.InternalRoom);
273
-                        }
274
-                    }
275
-                }
276
-            }
107
+        if (carrying != null) {
108
+            Drops();
277 109
         }
278
-        else if (e.getKeyCode() == KeyEvent.VK_X) {
279
-            if (room != null && room.portalItem != null) {
280
-                Dimension d = room.portalItem.GetXY();
281
-                int newX = d.width
282
-                        + room.portalItem.getWidth() / 2
283
-                        - width / 2;
284
-                int newY = d.height
285
-                        + room.portalItem.getHeight() / 4 * 2
286
-                        - height / 2;
287
-                x = newX;
288
-                y = newY;
289
-                SetRoom(room.portalItem.room);
290
-                level.currentViewer = level.player;
291
-            }
292
-        } else if (e.getKeyCode() == KeyEvent.VK_F) {
293
-            if (carrying != null) {
294
-                if (carrying instanceof Device) {
295
-                    ((Device) carrying).flip();
296
-                }
297
-            }
298
-        } else if (e.getKeyCode() == KeyEvent.VK_M) {
299
-            Runtime runtime = Runtime.getRuntime();
300
-            long freemem = runtime.freeMemory();
301
-            long totalmem = runtime.totalMemory();
302
-            System.out.println("Total Memory = " + totalmem
303
-                    + ", (" + totalmem / 1024 + "K), ("
304
-                    + totalmem / 1024 / 1024 + "M)");
305
-            System.out.println("Free Memory = " + freemem
306
-                    + ", (" + freemem / 1024 + "K), ("
307
-                    + freemem / 1024 / 1024 + "M)");
110
+        level.paintbrush.x = (x / 28) * 28;
111
+        level.paintbrush.y = (y / 32) * 32;
112
+        level.paintbrush.room = room;
113
+        room = null;
114
+        if (level.currentViewer == level.player) {
115
+            level.currentViewer = level.paintbrush;
308 116
         }
117
+        level.player = level.paintbrush;
118
+        handleRemote();
309 119
 
310
-        return false;
120
+        level.roomdisplay.dq.selectPaintBrush();
121
+
122
+        return true;
311 123
     }
312 124
 
313
-    public boolean KeyDown(KeyEvent e) {
314
-        if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
315
-            repeating++;
316
-            if (repeating > 10) {
317
-                if (carriedBy == null) {
318
-                    MoveRight(e.isControlDown());
319
-                }
320
-                return true;
321
-            }
125
+    @Override
126
+    public boolean handleToolbox() {
127
+        if (level.toolbox == null) {
322 128
             return false;
323 129
         }
324
-        if (e.getKeyCode() == KeyEvent.VK_LEFT) {
325
-            repeating++;
326
-            if (repeating > 10) {
327
-                if (carriedBy == null) {
328
-                    MoveLeft(e.isControlDown());
329
-                }
330
-                return true;
130
+        if (level.toolbox.room != room) {
131
+            // Summon Toolbox
132
+            if (carrying != null) {
133
+                return false;
331 134
             }
332
-            return false;
333
-        }
334
-        if (e.getKeyCode() == KeyEvent.VK_UP) {
335
-            repeating++;
336
-            if (repeating > 10) {
337
-                if (carriedBy == null) {
338
-                    MoveUp(e.isControlDown());
339
-                }
340
-                return true;
135
+            if (((ToolBox) level.toolbox).open) {
136
+                ((ToolBox) level.toolbox).Toggle();
341 137
             }
342
-            return false;
138
+            level.toolbox.room = room;
139
+            level.toolbox.x = x + 28;
140
+            level.toolbox.y = y + 6;
141
+            PicksUp(level.toolbox);
343 142
         }
344
-        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
345
-            repeating++;
346
-            if (repeating > 10) {
347
-                if (carriedBy == null) {
348
-                    MoveDown(e.isControlDown());
349
-                }
350
-                return true;
351
-            }
352
-            return false;
143
+        else {
144
+            ((ToolBox) level.toolbox).Toggle();
353 145
         }
354
-        return false;
146
+        return true;
355 147
     }
356 148
 
357
-    public void MoveUp(boolean nudge) {
358
-        Item item = level.FindNearestItem(this);
359
-        if (item != null) {
360
-            if (item.InternalRoom != null) {
361
-                if (item.UpEnterOverlap(this)) {
362
-                    int newX = 280; // 10 * 28
363
-                    int newY = 320; // 10 * 32
364
-                    x = newX;
365
-                    y = newY;
366
-                    SetRoom(item.InternalRoom);
367
-                }
368
-            }
369
-        }
370
-        super.MoveUp(nudge);
371
-    }
372 149
 
373
-    public void MoveDown(boolean nudge) {
374
-        Item item = level.FindNearestItem(this);
375
-        if (item != null) {
376
-            if (item.InternalRoom != null) {
377
-                if (item.DownEnterOverlap(this)) {
378
-                    int newX = 280; // 10 * 28
379
-                    int newY = 0; //  0 * 32
380
-                    x = newX;
381
-                    y = newY;
382
-                    SetRoom(item.InternalRoom);
383
-                }
384
-            }
385
-        }
386
-        super.MoveDown(nudge);
387
-    }
388 150
 
389
-    public void MoveLeft(boolean nudge) {
390
-        Item item = level.FindNearestItem(this);
391
-        if (item != null) {
392
-            if (item.InternalRoom != null) {
393
-                if (item.LeftEnterOverlap(this)) {
394
-                    int newX = 532; // 19 * 28
395
-                    int newY = 176; // 5.5 * 32
396
-                    x = newX;
397
-                    y = newY;
398
-                    SetRoom(item.InternalRoom);
399
-                }
400
-            }
401
-        }
402
-        super.MoveLeft(nudge);
403
-    }
404 151
 
405
-    public void MoveRight(boolean nudge) {
406
-        Item item = level.FindNearestItem(this);
407
-        if (item != null) {
408
-            if (item.InternalRoom != null) {
409
-                if (item.RightEnterOverlap(this)) {
410
-                    int newX = 0; // 0 * 28
411
-                    int newY = 176; // 5.5 * 32
412
-                    x = newX;
413
-                    y = newY;
414
-                    SetRoom(item.InternalRoom);
415
-                }
416
-            }
417
-        }
418
-        super.MoveRight(nudge);
419
-    }
152
+
153
+
420 154
 
421 155
 }

+ 93
- 107
src/com/droidquest/avatars/PaintBrush.java View File

@@ -9,10 +9,9 @@ import com.droidquest.materials.RobotBlocker;
9 9
 
10 10
 import javax.swing.*;
11 11
 import java.awt.*;
12
-import java.awt.event.KeyEvent;
13 12
 import java.awt.image.BufferedImage;
14 13
 
15
-public class PaintBrush extends Item {
14
+public class PaintBrush extends Player {
16 15
     // The Paintbrush works just like the original, except it allows
17 16
     // differnt color paints for differnt materials. Pressing 'P' as the
18 17
     // Paintbrush switches the Material Settings.
@@ -34,6 +33,11 @@ public class PaintBrush extends Item {
34 33
         GenerateIcons();
35 34
     }
36 35
 
36
+    @Override
37
+    protected boolean isCheatMode() {
38
+        return true;
39
+    }
40
+
37 41
     public void GenerateIcons() {
38 42
         icons = new ImageIcon[5];
39 43
         icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
@@ -119,115 +123,97 @@ public class PaintBrush extends Item {
119 123
 
120 124
     }
121 125
 
122
-    public boolean KeyUp(KeyEvent e) {
123
-        if (e.getKeyCode() == KeyEvent.VK_C) {
124
-            level.gameCursor.x = x;
125
-            level.gameCursor.y = y;
126
-            level.gameCursor.room = room;
127
-            room = null;
128
-            if (level.currentViewer == level.player) {
129
-                level.currentViewer = level.gameCursor;
130
-            }
131
-            level.player = level.gameCursor;
132
-        }
133
-        if (e.getKeyCode() == KeyEvent.VK_S) {
134
-            if (level.solderingPen == null) {
135
-                return false;
136
-            }
137
-            level.solderingPen.x = x;
138
-            level.solderingPen.y = y;
139
-            level.solderingPen.room = room;
140
-            room = null;
141
-            if (level.currentViewer == level.player) {
142
-                level.currentViewer = level.solderingPen;
143
-            }
144
-            level.player = level.solderingPen;
145
-        }
146
-        if (e.getKeyCode() == KeyEvent.VK_R) {
147
-            if (level.remote == null) {
148
-                return false;
149
-            }
150
-            level.remote.x = x;
151
-            level.remote.y = y;
152
-            level.remote.room = room;
153
-            room = null;
154
-            if (level.currentViewer == level.player) {
155
-                level.currentViewer = level.remote;
156
-            }
157
-            level.player = level.remote;
158
-        }
159
-        if (e.getKeyCode() == KeyEvent.VK_SLASH) {
160
-            if (level.helpCam == null) {
161
-                return false;
162
-            }
163
-            level.player = level.helpCam;
164
-            level.currentViewer = level.helpCam;
165
-        }
166
-        if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
167
-            if (e.isShiftDown()) {
168
-                SetRoom(room.rightRoom);
169
-            }
170
-            if (carriedBy == null) {
171
-                MoveRight(e.isControlDown());
172
-            }
173
-            repeating = 0;
174
-            return true;
175
-        }
176
-        if (e.getKeyCode() == KeyEvent.VK_LEFT) {
177
-            if (e.isShiftDown()) {
178
-                SetRoom(room.leftRoom);
179
-            }
180
-            if (carriedBy == null) {
181
-                MoveLeft(e.isControlDown());
182
-            }
183
-            repeating = 0;
184
-            return true;
185
-        }
186
-        if (e.getKeyCode() == KeyEvent.VK_UP) {
187
-            if (e.isShiftDown()) {
188
-                SetRoom(room.upRoom);
189
-            }
190
-            if (carriedBy == null) {
191
-                MoveUp(e.isControlDown());
192
-            }
193
-            repeating = 0;
194
-            return true;
126
+    @Override
127
+    public boolean handleHelp() {
128
+        handleGameCursor();
129
+        return super.handleHelp();
130
+    }
131
+
132
+    @Override
133
+    public boolean handleLoadSmallChip() {
134
+        return false;
135
+    }
136
+
137
+    @Override
138
+    public boolean handlePaintbrush() {
139
+        paintIndex++;
140
+        if (paintIndex == 5) {
141
+            paintIndex = 0;
195 142
         }
196
-        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
197
-            if (e.isShiftDown()) {
198
-                SetRoom(room.downRoom);
199
-            }
200
-            if (carriedBy == null) {
201
-                MoveDown(e.isControlDown());
202
-            }
203
-            repeating = 0;
204
-            return true;
143
+        matIndex = level.materials.indexOf(paintMats[paintIndex]);
144
+        currentIcon = icons[paintIndex].getImage();
145
+        return true;
146
+    }
147
+
148
+    @Override
149
+    public boolean handleToolbox() {
150
+        // Paintbrush doesn't handle toolbox
151
+        return false;
152
+    }
153
+
154
+    @Override
155
+    public boolean handlePickupDrop() {
156
+        // Paintbrush uses space for painting instead of pickup/drop
157
+        if (!room.editable) {
158
+            return false;
205 159
         }
206
-        if (e.getKeyCode() == KeyEvent.VK_P) {
207
-            paintIndex++;
208
-            if (paintIndex == 5) {
209
-                paintIndex = 0;
210
-            }
211
-            matIndex = level.materials.indexOf(paintMats[paintIndex]);
212
-            currentIcon = icons[paintIndex].getImage();
160
+        int bigX = (x + 14) / 28;
161
+        int bigY = (y + 16) / 32;
162
+        if (room.RoomArray[bigY][bigX] == emptyIndex) {
163
+            room.SetMaterial(bigX, bigY, matIndex);
213 164
         }
214
-        if (e.getKeyCode() == KeyEvent.VK_SPACE) {
215
-            if (!room.editable) {
216
-                return false;
217
-            }
218
-            int bigX = (x + 14) / 28;
219
-            int bigY = (y + 16) / 32;
220
-            if (room.RoomArray[bigY][bigX] == emptyIndex) {
221
-                room.SetMaterial(bigX, bigY, matIndex);
222
-            }
223
-            else {
224
-                room.SetMaterial(bigX, bigY, emptyIndex);
225
-            }
165
+        else {
166
+            room.SetMaterial(bigX, bigY, emptyIndex);
226 167
         }
168
+        return true;
169
+    }
170
+
171
+    @Override
172
+    public boolean handleEnterRoom() {
227 173
         return false;
228 174
     }
229 175
 
230
-    public void MoveUp(boolean nudge) {
176
+    @Override
177
+    public boolean handleExitRoom() {
178
+        return false;
179
+    }
180
+
181
+    @Override
182
+    public boolean handleFlipDevice() {
183
+        return false;
184
+    }
185
+
186
+    @Override
187
+    public boolean handleRotateDevice(int direction) {
188
+        return false;
189
+    }
190
+
191
+
192
+    @Override
193
+    public boolean handleGameCursor() {
194
+        level.gameCursor.x = x;
195
+        level.gameCursor.y = y;
196
+        level.gameCursor.room = room;
197
+        room = null;
198
+        if (level.currentViewer == level.player) {
199
+            level.currentViewer = level.gameCursor;
200
+        }
201
+        level.player = level.gameCursor;
202
+
203
+        handleRemote();
204
+
205
+        level.roomdisplay.dq.selectCursor();
206
+
207
+        return true;
208
+    }
209
+
210
+
211
+    @Override
212
+    protected boolean handleRepeatSpace() {
213
+         return false;
214
+    }
215
+
216
+    public void moveUp(boolean nudge) {
231 217
         int dist = 32;
232 218
         if (nudge) {
233 219
             dist = 2;
@@ -245,7 +231,7 @@ public class PaintBrush extends Item {
245 231
         }
246 232
     }
247 233
 
248
-    public void MoveDown(boolean nudge) {
234
+    public void moveDown(boolean nudge) {
249 235
         int dist = 32;
250 236
         if (nudge) {
251 237
             dist = 2;
@@ -263,7 +249,7 @@ public class PaintBrush extends Item {
263 249
         }
264 250
     }
265 251
 
266
-    public void MoveLeft(boolean nudge) {
252
+    public void moveLeft(boolean nudge) {
267 253
         int dist = 28;
268 254
         if (nudge) {
269 255
             dist = 2;
@@ -281,7 +267,7 @@ public class PaintBrush extends Item {
281 267
         }
282 268
     }
283 269
 
284
-    public void MoveRight(boolean nudge) {
270
+    public void moveRight(boolean nudge) {
285 271
         int dist = 28;
286 272
         if (nudge) {
287 273
             dist = 2;

+ 562
- 0
src/com/droidquest/avatars/Player.java View File

@@ -0,0 +1,562 @@
1
+package com.droidquest.avatars;
2
+
3
+import com.droidquest.devices.Device;
4
+import com.droidquest.devices.GenericChip;
5
+import com.droidquest.devices.SmallChip;
6
+import com.droidquest.items.Item;
7
+import com.droidquest.items.ToolBox;
8
+
9
+import java.awt.*;
10
+import java.awt.event.KeyEvent;
11
+
12
+/**
13
+ * Parent class to handle common Player functions.
14
+ */
15
+public class Player extends Item implements Avatar {
16
+
17
+    private int keyRepeatRate = 5;
18
+
19
+
20
+    protected boolean handleSaveSmallChip() {
21
+        return false;
22
+    }
23
+
24
+    public void handleRemote() {
25
+        if (level.remote != null) {
26
+            if (level.remote.carriedBy != null) {
27
+                level.remote.carriedBy = level.player;
28
+            }
29
+        }
30
+    }
31
+
32
+    public boolean handleSolderPen() {
33
+        if (level.solderingPen == null) {
34
+            return false;
35
+        }
36
+        if (carrying != null) {
37
+            if (handleSaveSmallChip()) {
38
+                // Actually a save small chip command,
39
+                // skip solder pen
40
+                return true;
41
+            }
42
+            Drops();
43
+        }
44
+        level.solderingPen.x = x;
45
+        level.solderingPen.y = y;
46
+        level.solderingPen.room = room;
47
+        room = null;
48
+        if (level.currentViewer == level.player) {
49
+            level.currentViewer = level.solderingPen;
50
+        }
51
+        level.player = level.solderingPen;
52
+
53
+        handleRemote();
54
+
55
+        level.roomdisplay.dq.selectSolderpen();
56
+
57
+        return true;
58
+    }
59
+
60
+    public boolean handleRadio() {
61
+        if (level.remote == null) {
62
+            return false;
63
+        }
64
+        if (level.remote.carriedBy == null) { // Summon Remote
65
+            level.remote.x = 28;
66
+            level.remote.y = -20;
67
+            level.remote.carriedBy = level.player;
68
+            level.remote.room = level.player.room;
69
+            level.electricity = true;
70
+
71
+            level.roomdisplay.dq.setRadioSelected(true);
72
+        }
73
+        else { // Hide Remote
74
+            level.remote.carriedBy = null;
75
+            level.remote.room = null;
76
+            level.electricity = false;
77
+
78
+            level.roomdisplay.dq.setRadioSelected(false);
79
+        }
80
+        return true;
81
+    }
82
+
83
+    public boolean handleHelp() {
84
+        if (carrying != null) {
85
+            if (carrying instanceof GenericChip) {
86
+                ((GenericChip) carrying).ShowText(true);
87
+                return false;
88
+            }
89
+        }
90
+        if (level.helpCam == null) {
91
+            return false;
92
+        }
93
+        level.player = level.helpCam;
94
+        level.currentViewer = level.helpCam;
95
+        return true;
96
+    }
97
+
98
+    public boolean handleToolbox() {
99
+        if (level.toolbox == null) {
100
+            if (carrying != null) {
101
+                Drops();
102
+            }
103
+            level.toolbox = new ToolBox(x, y + 8, room);
104
+            level.items.addElement(level.toolbox);
105
+            ((ToolBox) level.toolbox).Toggle();
106
+            PicksUp(level.toolbox);
107
+        }
108
+        if (level.toolbox.room != room) {
109
+            // Summon Toolbox
110
+            if (carrying != null) {
111
+                return false;
112
+            }
113
+            if (((ToolBox) level.toolbox).open) {
114
+                ((ToolBox) level.toolbox).Toggle();
115
+            }
116
+            level.toolbox.room = room;
117
+            level.toolbox.x = x + 28;
118
+            level.toolbox.y = y + 6;
119
+            PicksUp(level.toolbox);
120
+        }
121
+        else {
122
+            ((ToolBox) level.toolbox).Toggle();
123
+        }
124
+        return true;
125
+    }
126
+
127
+
128
+    public boolean handleLoadSmallChip() {
129
+        if (carrying != null) {
130
+            if (carrying instanceof SmallChip) {
131
+                FileDialog fd = new FileDialog(level.roomdisplay.dq, "Load Chip", FileDialog.LOAD);
132
+                fd.setDirectory("chips");
133
+                fd.show();
134
+                System.out.println("Dialog returned with "
135
+                        + fd.getDirectory()
136
+                        + fd.getFile());
137
+                if (fd.getFile() != null) {
138
+                    ((SmallChip) carrying).Empty();
139
+                    ((SmallChip) carrying).LoadChip(fd.getDirectory() + fd.getFile());
140
+                }
141
+                return true;
142
+            }
143
+        }
144
+        return false;
145
+    }
146
+
147
+    protected boolean handleTrain() {
148
+        return false;
149
+    }
150
+
151
+    @Override
152
+    public void PicksUp(Item item) {
153
+        super.PicksUp(item);
154
+        if (carrying instanceof SmallChip) {
155
+            level.roomdisplay.dq.setLoadChipEnabled(true);
156
+        }
157
+        else {
158
+            level.roomdisplay.dq.setLoadChipEnabled(false);
159
+
160
+            if (carrying.isDevice()) {
161
+                level.roomdisplay.dq.setRotateEnabled(true);
162
+                level.roomdisplay.dq.setFlipDeviceEnabled(true);
163
+            }
164
+            else {
165
+                level.roomdisplay.dq.setRotateEnabled(false);
166
+                level.roomdisplay.dq.setFlipDeviceEnabled(false);
167
+            }
168
+        }
169
+    }
170
+
171
+    @Override
172
+    public void Drops() {
173
+        super.Drops();
174
+        level.roomdisplay.dq.setRotateEnabled(false);
175
+        level.roomdisplay.dq.setLoadChipEnabled(false);
176
+        level.roomdisplay.dq.setFlipDeviceEnabled(false);
177
+    }
178
+
179
+    public boolean handlePickupDrop() {
180
+        if (handleTrain()) {
181
+            return false;
182
+        }
183
+        if (carrying != null) {
184
+            Drops();
185
+        }
186
+        else {
187
+            Item item = level.FindNearestItem(level.gameCursor);
188
+            if (item != null) {
189
+                if (item.CanBePickedUp(level.gameCursor)) {
190
+                    PicksUp(item);
191
+                }
192
+            }
193
+        }
194
+        setOutline(false);
195
+        return true;
196
+    }
197
+
198
+    // Default implementation doesn't do anything,
199
+    // needed by GameCursor to set outline
200
+    protected void setOutline(boolean outline) {
201
+    }
202
+
203
+    public boolean handleRotateDevice(int direction) {
204
+        if (carrying != null) {
205
+            if (carrying.isDevice()) {
206
+                ((Device) carrying).rotate(direction);
207
+            }
208
+        }
209
+        return true;
210
+    }
211
+
212
+    public boolean handleEnterRoom() {
213
+        Item item = level.FindNearestItem(this);
214
+        if (item != null) {
215
+            if (item.InternalRoom != null) {
216
+                if (Overlaps(item)) {
217
+                    if (!item.OverWall()) {
218
+                        int newX = 280; // 10 * 28
219
+                        int newY = 176; // 5.5 * 32
220
+                        x = newX;
221
+                        y = newY;
222
+                        SetRoom(item.InternalRoom);
223
+                        return true;
224
+                    }
225
+                }
226
+            }
227
+        }
228
+        return false;
229
+    }
230
+
231
+    public boolean handleExitRoom() {
232
+        if (room != null && room.portalItem != null) {
233
+            Dimension d = room.portalItem.GetXY();
234
+            int newX = d.width
235
+                    + room.portalItem.getWidth() / 2
236
+                    - width / 2;
237
+            int newY = d.height
238
+                    + room.portalItem.getHeight() / 4 * 2
239
+                    - height / 2;
240
+            x = newX;
241
+            y = newY;
242
+            SetRoom(room.portalItem.room);
243
+            level.currentViewer = level.player;
244
+            return true;
245
+        }
246
+        return false;
247
+    }
248
+
249
+    public boolean handleFlipDevice() {
250
+        if (carrying != null) {
251
+            if (carrying instanceof Device) {
252
+                ((Device) carrying).flip();
253
+            }
254
+        }
255
+        return true;
256
+    }
257
+
258
+    protected boolean handleMemory() {
259
+        Runtime runtime = Runtime.getRuntime();
260
+        long freemem = runtime.freeMemory();
261
+        long totalmem = runtime.totalMemory();
262
+        System.out.println("Total Memory = " + totalmem
263
+                + ", (" + totalmem / 1024 + "K), ("
264
+                + totalmem / 1024 / 1024 + "M)");
265
+        System.out.println("Free Memory = " + freemem
266
+                + ", (" + freemem / 1024 + "K), ("
267
+                + freemem / 1024 / 1024 + "M)");
268
+        return true;
269
+    }
270
+
271
+    protected boolean isCheatMode() {
272
+        return false;
273
+    }
274
+
275
+    public boolean handleMoveDown(boolean isShiftDown, boolean isControlDown) {
276
+        if (isCheatMode()) {
277
+            if (isShiftDown && room != null) {
278
+                SetRoom(room.downRoom);
279
+            }
280
+        }
281
+        if (carriedBy == null) {
282
+            moveDown(isControlDown);
283
+        }
284
+        repeating = 0;
285
+        return true;
286
+    }
287
+
288
+    public boolean handleMoveUp(boolean isShiftDown, boolean isControlDown) {
289
+        if (isCheatMode()) {
290
+            if (isShiftDown && room != null) {
291
+                SetRoom(room.upRoom);
292
+            }
293
+        }
294
+        if (carriedBy == null) {
295
+            moveUp(isControlDown);
296
+        }
297
+        repeating = 0;
298
+        return true;
299
+    }
300
+
301
+    public boolean handleMoveLeft(boolean isShiftDown, boolean isControlDown) {
302
+        if (isCheatMode()) {
303
+            if (isShiftDown && room != null) {
304
+                SetRoom(room.leftRoom);
305
+            }
306
+        }
307
+        if (carriedBy == null) {
308
+            moveLeft(isControlDown);
309
+        }
310
+        repeating = 0;
311
+        return true;
312
+    }
313
+
314
+    public boolean handleMoveRight(boolean isShiftDown, boolean isControlDown) {
315
+        if (isCheatMode()) {
316
+            if (isShiftDown && room != null) {
317
+                SetRoom(room.rightRoom);
318
+            }
319
+        }
320
+        if (carriedBy == null) {
321
+            moveRight(isControlDown);
322
+        }
323
+        repeating = 0;
324
+        return true;
325
+    }
326
+
327
+    public boolean handleHotCursor() {
328
+        return false;
329
+    }
330
+
331
+    public boolean handlePaintbrush() {
332
+        return false;
333
+    }
334
+
335
+    // Default assume that we are already a game cursor
336
+    public boolean handleGameCursor() {
337
+        return false;
338
+    }
339
+
340
+    public boolean KeyUp(KeyEvent e) {
341
+        if (e.getKeyCode() == KeyEvent.VK_L && handleLoadSmallChip()) {
342
+            return false;
343
+        }
344
+        else if (e.getKeyCode() == KeyEvent.VK_C && handleGameCursor()) {
345
+            return false;
346
+        }
347
+        else if (e.getKeyCode() == KeyEvent.VK_H && handleHotCursor()) {
348
+            return false;
349
+        }
350
+        else if (e.getKeyCode() == KeyEvent.VK_S && handleSolderPen()) {
351
+            return false;
352
+        }
353
+        else if (e.getKeyCode() == KeyEvent.VK_R && handleRadio()) {
354
+            return false;
355
+        }
356
+        else if (e.getKeyCode() == KeyEvent.VK_P && handlePaintbrush()) {
357
+            return false;
358
+        }
359
+        else if (e.getKeyCode() == KeyEvent.VK_T && handleToolbox()) {
360
+            return false;
361
+        }
362
+        else if (e.getKeyCode() == KeyEvent.VK_SLASH && handleHelp()) {
363
+            return false;
364
+        }
365
+        else if (e.getKeyCode() == KeyEvent.VK_RIGHT && handleMoveRight(e.isShiftDown(), e.isControlDown())) {
366
+            return true;
367
+        }
368
+        else if (e.getKeyCode() == KeyEvent.VK_LEFT && handleMoveLeft(e.isShiftDown(), e.isControlDown())) {
369
+            return true;
370
+        }
371
+        else if (e.getKeyCode() == KeyEvent.VK_UP && handleMoveUp(e.isShiftDown(), e.isControlDown())) {
372
+            return true;
373
+        }
374
+        else if (e.getKeyCode() == KeyEvent.VK_DOWN && handleMoveDown(e.isShiftDown(), e.isControlDown())) {
375
+            return true;
376
+        }
377
+        else if (e.getKeyCode() == KeyEvent.VK_SPACE && handlePickupDrop()) {
378
+            return false;
379
+        }
380
+        else if (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET && handleRotateDevice(1)) {
381
+            return false;
382
+        }
383
+        else if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET && handleRotateDevice(-1)) {
384
+            return false;
385
+        }
386
+        else if (e.getKeyCode() == KeyEvent.VK_E && handleEnterRoom()) {
387
+            return false;
388
+        }
389
+        else if (e.getKeyCode() == KeyEvent.VK_X && handleExitRoom()) {
390
+            return false;
391
+        }
392
+        else if (e.getKeyCode() == KeyEvent.VK_F && handleFlipDevice()) {
393
+            return false;
394
+        }
395
+        else if (e.getKeyCode() == KeyEvent.VK_M && handleMemory()) {
396
+            return false;
397
+        }
398
+
399
+        return false;
400
+    }
401
+
402
+    protected boolean handleRepeatRight(boolean isControlDown) {
403
+        repeating++;
404
+        if (repeating > getKeyRepeatRate()) {
405
+            if (carriedBy == null) {
406
+                moveRight(isControlDown);
407
+            }
408
+            return true;
409
+        }
410
+        return false;
411
+
412
+    }
413
+
414
+    protected boolean handleRepeatLeft(boolean isControlDown) {
415
+        repeating++;
416
+        if (repeating > getKeyRepeatRate()) {
417
+            if (carriedBy == null) {
418
+                moveLeft(isControlDown);
419
+            }
420
+            return true;
421
+        }
422
+        return false;
423
+    }
424
+
425
+    protected boolean handleRepeatUp(boolean isControlDown) {
426
+        repeating++;
427
+        if (repeating > getKeyRepeatRate()) {
428
+            if (carriedBy == null) {
429
+                moveUp(isControlDown);
430
+            }
431
+            return true;
432
+        }
433
+        return false;
434
+    }
435
+
436
+    protected boolean handleRepeatDown(boolean isControlDown) {
437
+        repeating++;
438
+        if (repeating > getKeyRepeatRate()) {
439
+            if (carriedBy == null) {
440
+                moveDown(isControlDown);
441
+            }
442
+            return true;
443
+        }
444
+        return false;
445
+
446
+    }
447
+
448
+    protected boolean handleRepeatSpace() {
449
+        if (level.player == level.gameCursor) {
450
+            setOutline(true);
451
+            return true;
452
+        }
453
+        return false;
454
+    }
455
+
456
+    public boolean KeyDown(KeyEvent e) {
457
+        if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
458
+            if (handleRepeatRight(e.isControlDown())) {
459
+                return true;
460
+            }
461
+        }
462
+        else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
463
+            if (handleRepeatLeft(e.isControlDown())) {
464
+                return true;
465
+            }
466
+        }
467
+        else if (e.getKeyCode() == KeyEvent.VK_UP) {
468
+            if (handleRepeatUp(e.isControlDown())) {
469
+                return true;
470
+            }
471
+        }
472
+        else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
473
+            if (handleRepeatDown(e.isControlDown())) {
474
+                return true;
475
+            }
476
+        }
477
+        if (e.getKeyCode() == KeyEvent.VK_SPACE) {
478
+            if (handleRepeatSpace()) {
479
+                return false;
480
+            }
481
+        }
482
+        return false;
483
+    }
484
+
485
+
486
+    public int getKeyRepeatRate() {
487
+        return keyRepeatRate;
488
+    }
489
+
490
+    public void setKeyRepeatRate(int keyRepeatRate) {
491
+        this.keyRepeatRate = keyRepeatRate;
492
+    }
493
+
494
+    @Override
495
+    public void moveRight(boolean nudge) {
496
+        Item item = level.FindNearestItem(this);
497
+        if (item != null) {
498
+            if (item.InternalRoom != null) {
499
+                if (item.RightEnterOverlap(this)) {
500
+                    int newX = 0; // 0 * 28
501
+                    int newY = 176; // 5.5 * 32
502
+                    x = newX;
503
+                    y = newY;
504
+                    SetRoom(item.InternalRoom);
505
+                }
506
+            }
507
+        }
508
+        super.moveRight(nudge);
509
+    }
510
+
511
+    @Override
512
+    public void moveLeft(boolean nudge) {
513
+        Item item = level.FindNearestItem(this);
514
+        if (item != null) {
515
+            if (item.InternalRoom != null) {
516
+                if (item.LeftEnterOverlap(this)) {
517
+                    int newX = 532; // 19 * 28
518
+                    int newY = 176; // 5.5 * 32
519
+                    x = newX;
520
+                    y = newY;
521
+                    SetRoom(item.InternalRoom);
522
+                }
523
+            }
524
+        }
525
+        super.moveLeft(nudge);
526
+    }
527
+
528
+    @Override
529
+    public void moveDown(boolean nudge) {
530
+        Item item = level.FindNearestItem(this);
531
+        if (item != null) {
532
+            if (item.InternalRoom != null) {
533
+                if (item.DownEnterOverlap(this)) {
534
+                    int newX = 280; // 10 * 28
535
+                    int newY = 0; //  0 * 32
536
+                    x = newX;
537
+                    y = newY;
538
+                    SetRoom(item.InternalRoom);
539
+                }
540
+            }
541
+        }
542
+        super.moveDown(nudge);
543
+    }
544
+
545
+    @Override
546
+    public void moveUp(boolean nudge) {
547
+        Item item = level.FindNearestItem(this);
548
+        if (item != null) {
549
+            if (item.InternalRoom != null) {
550
+                if (item.UpEnterOverlap(this)) {
551
+                    int newX = 280; // 10 * 28
552
+                    int newY = 320; // 10 * 32
553
+                    x = newX;
554
+                    y = newY;
555
+                    SetRoom(item.InternalRoom);
556
+                }
557
+            }
558
+        }
559
+        super.moveUp(nudge);
560
+    }
561
+
562
+}

+ 76
- 17
src/com/droidquest/avatars/Remote.java View File

@@ -7,7 +7,7 @@ import java.awt.*;
7 7
 import java.awt.event.KeyEvent;
8 8
 import java.awt.image.BufferedImage;
9 9
 
10
-public class Remote extends Item {
10
+public class Remote extends Item implements Avatar {
11 11
     public Remote() {
12 12
         width = 4;
13 13
         height = 20;
@@ -98,28 +98,28 @@ public class Remote extends Item {
98 98
         }
99 99
         else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
100 100
             if (carriedBy == null) {
101
-                MoveRight(e.isControlDown());
101
+                moveRight(e.isControlDown());
102 102
             }
103 103
             repeating = 0;
104 104
             return true;
105 105
         }
106 106
         else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
107 107
             if (carriedBy == null) {
108
-                MoveLeft(e.isControlDown());
108
+                moveLeft(e.isControlDown());
109 109
             }
110 110
             repeating = 0;
111 111
             return true;
112 112
         }
113 113
         else if (e.getKeyCode() == KeyEvent.VK_UP) {
114 114
             if (carriedBy == null) {
115
-                MoveUp(e.isControlDown());
115
+                moveUp(e.isControlDown());
116 116
             }
117 117
             repeating = 0;
118 118
             return true;
119 119
         }
120 120
         else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
121 121
             if (carriedBy == null) {
122
-                MoveDown(e.isControlDown());
122
+                moveDown(e.isControlDown());
123 123
             }
124 124
             repeating = 0;
125 125
             return true;
@@ -134,7 +134,7 @@ public class Remote extends Item {
134 134
         if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
135 135
             repeating++;
136 136
             if (repeating > 10) {
137
-                MoveRight(e.isControlDown());
137
+                moveRight(e.isControlDown());
138 138
                 return true;
139 139
             }
140 140
             return false;
@@ -142,7 +142,7 @@ public class Remote extends Item {
142 142
         else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
143 143
             repeating++;
144 144
             if (repeating > 10) {
145
-                MoveLeft(e.isControlDown());
145
+                moveLeft(e.isControlDown());
146 146
                 return true;
147 147
             }
148 148
             return false;
@@ -150,7 +150,7 @@ public class Remote extends Item {
150 150
         else if (e.getKeyCode() == KeyEvent.VK_UP) {
151 151
             repeating++;
152 152
             if (repeating > 10) {
153
-                MoveUp(e.isControlDown());
153
+                moveUp(e.isControlDown());
154 154
                 return true;
155 155
             }
156 156
             return false;
@@ -158,7 +158,7 @@ public class Remote extends Item {
158 158
         else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
159 159
             repeating++;
160 160
             if (repeating > 10) {
161
-                MoveDown(e.isControlDown());
161
+                moveDown(e.isControlDown());
162 162
                 return true;
163 163
             }
164 164
             return false;
@@ -166,7 +166,7 @@ public class Remote extends Item {
166 166
         return false;
167 167
     }
168 168
 
169
-    public void MoveUp(boolean nudge) {
169
+    public void moveUp(boolean nudge) {
170 170
         Item item = level.FindNearestItem(this);
171 171
         if (item != null) {
172 172
             if (item.InternalRoom != null) {
@@ -179,10 +179,10 @@ public class Remote extends Item {
179 179
                 }
180 180
             }
181 181
         }
182
-        super.MoveUp(nudge);
182
+        super.moveUp(nudge);
183 183
     }
184 184
 
185
-    public void MoveDown(boolean nudge) {
185
+    public void moveDown(boolean nudge) {
186 186
         Item item = level.FindNearestItem(this);
187 187
         if (item != null) {
188 188
             if (item.InternalRoom != null) {
@@ -195,10 +195,10 @@ public class Remote extends Item {
195 195
                 }
196 196
             }
197 197
         }
198
-        super.MoveDown(nudge);
198
+        super.moveDown(nudge);
199 199
     }
200 200
 
201
-    public void MoveLeft(boolean nudge) {
201
+    public void moveLeft(boolean nudge) {
202 202
         Item item = level.FindNearestItem(this);
203 203
         if (item != null) {
204 204
             if (item.InternalRoom != null) {
@@ -211,10 +211,10 @@ public class Remote extends Item {
211 211
                 }
212 212
             }
213 213
         }
214
-        super.MoveLeft(nudge);
214
+        super.moveLeft(nudge);
215 215
     }
216 216
 
217
-    public void MoveRight(boolean nudge) {
217
+    public void moveRight(boolean nudge) {
218 218
         Item item = level.FindNearestItem(this);
219 219
         if (item != null) {
220 220
             if (item.InternalRoom != null) {
@@ -227,7 +227,66 @@ public class Remote extends Item {
227 227
                 }
228 228
             }
229 229
         }
230
-        super.MoveRight(nudge);
230
+        super.moveRight(nudge);
231 231
     }
232 232
 
233
+    @Override
234
+    public boolean handleGameCursor() {
235
+        return false;
236
+    }
237
+
238
+    @Override
239
+    public boolean handleSolderPen() {
240
+        return false;
241
+    }
242
+
243
+    @Override
244
+    public boolean handleToolbox() {
245
+        return false;
246
+    }
247
+
248
+    @Override
249
+    public boolean handleRadio() {
250
+        return false;
251
+    }
252
+
253
+    @Override
254
+    public boolean handleRotateDevice(int direction) {
255
+        return false;
256
+    }
257
+
258
+    @Override
259
+    public boolean handleHotCursor() {
260
+        return false;
261
+    }
262
+
263
+    @Override
264
+    public boolean handlePaintbrush() {
265
+        return false;
266
+    }
267
+
268
+    @Override
269
+    public boolean handleLoadSmallChip() {
270
+        return false;
271
+    }
272
+
273
+    @Override
274
+    public boolean handleHelp() {
275
+        return false;
276
+    }
277
+
278
+    @Override
279
+    public boolean handleEnterRoom() {
280
+        return false;
281
+    }
282
+
283
+    @Override
284
+    public boolean handleExitRoom() {
285
+        return false;
286
+    }
287
+
288
+    @Override
289
+    public boolean handleFlipDevice() {
290
+        return false;
291
+    }
233 292
 }

+ 217
- 97
src/com/droidquest/avatars/SolderingPen.java View File

@@ -13,7 +13,7 @@ import java.awt.event.KeyEvent;
13 13
 import java.awt.event.MouseEvent;
14 14
 import java.awt.image.BufferedImage;
15 15
 
16
-public class SolderingPen extends Device {
16
+public class SolderingPen extends Device implements Avatar {
17 17
     private boolean hot;
18 18