| Redirect.java |
1 import java.awt.*;
2 import javax.swing.*;
3 import java.applet.*;
4 import java.awt.image.*;
5 import java.awt.geom.*;
6 import java.net.*;
7 /**
8 * Class to define the Redirectors to direct to
9 * other maps.
10 *
11 * @see MapLoader
12 * @see Game
13 * @see MapObject
14 * @see Grid
15 */
16 public class Redirect extends MapObject
17 {
18 /**
19 * The Image to display
20 */
21 protected static Image img;
22 /**
23 * The Number of Badges required before can be used
24 */
25 protected int numBadgesReq;
26 /**
27 * filename of where to go
28 */
29 String mapTo;
30 /**
31 * The Default MapObject to display behind.
32 *
33 * @see MapObject
34 * @see Grid
35 */
36 static MapObject behind;
37 /**
38 * Default constructor, sets Map to Load
39 * to Saphire.
40 */
41 public Redirect()
42 {
43 enterable = false;
44 type = MapObject.REDIRECT;
45 mapTo = "Saphire";
46 numBadgesReq = 0;
47 }
48 /**
49 * Create a new Redirector pointing to the map
50 * specified.
51 *
52 * @param mapTo the map to load.
53 */
54 public Redirect(String mapTo)
55 {
56 enterable = false;
57 type = MapObject.REDIRECT;
58 if(mapTo != null)
59 this.mapTo = mapTo;
60 else
61 this.mapTo = "Saphire";
62 numBadgesReq = 0;
63 }
64 /**
65 * Sets the image to paint.
66 *
67 * @param img the array of images to load, needs to be of length 1
68 */
69 public void setImage(Image[] img)
70 {
71 if(img.length == 1)
72 this.img = img[0];
73 }
74 /**
75 * Sets the map to load.
76 *
77 * @param mapTo the Map to load.
78 */
79 public void setMapTo(String mapTo)
80 {
81 if(mapTo != null)
82 this.mapTo = mapTo;
83 }
84 /**
85 * Gets the map to load.
86 *
87 * @return the map to load
88 */
89 public String getMapTo() { return mapTo; }
90
91 /**
92 * Sets the number of Badges required to use this.
93 *
94 * @param numBadges the NUmber of Badges required to use this
95 */
96 public void setNumberBadgesRequired(int numBadges)
97 {
98 if(numBadges >= 0)
99 numBadgesReq = numBadges;
100 }
101 /**
102 * Gets the number of badges required to use this.
103 *
104 * @return the number of badges required to use this
105 */
106 public int getNumberBadgesRequired() { return numBadgesReq; }
107 /**
108 * returns a clone of this
109 *
110 * @return a clone of this
111 */
112 public MapObject getClone() { return new Redirect(mapTo); }
113 /**
114 * Sets the MapObject that this is over.
115 *
116 * @param m the MapObject this is over.
117 */
118 public void setBehind(MapObject m)
119 {
120 if(m == null)
121 return;
122 else if(m.canBeEntered())
123 {
124 this.behind = m;
125 }
126 }
127 /**
128 * Draws the redirector.
129 *
130 * @param g the Graphics.
131 */
132 public void paint(Graphics g)
133 {
134 behind.paint(g);
135 g.drawImage(img, 0, 0, this);
136 }
137 }