| ElectricMon.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 import java.util.*;
8
9 /**
10 * A class to define the Monsters of type Electric
11 * handles the leveling up process and naming of
12 * attacks.
13 *
14 * @see Monster
15 * @version 1.2.3.5
16 * @author Matt, Sam
17 */
18 public class ElectricMon extends Monster
19 {
20 /**
21 * The number of levels needed before learning a new attack
22 */
23 protected static final int START = 11;
24 /**
25 * The level at which all attacks have been learned
26 */
27 protected static final int MAX_EARN_ATTACK_LEVEL = 45;
28 /**
29 * The name of the first attack
30 */
31 protected static final String A1 = "Quick";
32 /**
33 * The name of the second attack
34 */
35 protected static final String A2 = "Lightning";
36 /**
37 * The name of the third attack
38 */
39 protected static final String A3 = "Static-Charge";
40 /**
41 * The name of the fourth attack
42 */
43 protected static final String A4 = "Ball-Lightning";
44 /**
45 * The name of the fifth attack
46 */
47 protected static final String A5 = "EMP";
48 /**
49 * The name of the sixth attack
50 */
51 protected static final String A6 = "Mega-Shock";
52 /**
53 * The last attack learned (2 <= x <= 5)
54 */
55 protected int lastAttack = 2;
56 /**
57 * Construct a Electric Monster with the default values:
58 * name is Alligatrix
59 * level is two.
60 */
61 public ElectricMon()
62 {
63 type = MapObject.MONSTER;
64 attacks = new Vector();
65 maxLevel = START;
66 name = "Shockachu";
67 kind = ELECTRIC;
68 enterable = true;
69
70 level = 2;
71 int lev6 = 6*level;
72 int lev7 = 7*level;
73 int lev10 = 10*level;
74 hp = lev6;
75 defp = lev7;
76 attp = lev10;
77 maxHP = lev6;
78 maxDef = lev7;
79 maxAtt = lev10;
80 exp = 0;
81 maxExp = lev10;
82 addAttack(A1);
83 addAttack(A2);
84 }
85
86 /**
87 * Constructs a Electric Monster with the name name.
88 * level is two.
89 *
90 * @param name the name of the Electric Monster
91 */
92 public ElectricMon(String name)
93 {
94 type = MapObject.MONSTER;
95 attacks = new Vector();
96 maxLevel = START;
97 if(name != null)
98 this.name = name;
99 else
100 name = "Shockachu";
101 kind = ELECTRIC;
102 enterable = true;
103
104 level = 2;
105 int lev6 = 6*level;
106 int lev7 = 7*level;
107 int lev10 = 10*level;
108 hp = lev6;
109 defp = lev7;
110 attp = lev10;
111 maxHP = lev6;
112 maxDef = lev7;
113 maxAtt = lev10;
114 exp = 0;
115 maxExp = lev10;
116 addAttack(A1);
117 addAttack(A2);
118 }
119
120 /**
121 * Empty implemntation unneeded as Monsters are
122 * only displayed in battle
123 */
124 public void setImage(Image[] img) { } // Figure out how to make me work
125 /**
126 * Sets the max level
127 * always is START + previousMaxLevel
128 *
129 * @param nml the new Max Level
130 */
131 protected void setMaxLevel(byte nml)
132 {
133 if(nml > maxLevel && nml < MAX_EARN_ATTACK_LEVEL)
134 maxLevel = nml;
135 }
136 /**
137 * Preforms a level up on the Monster, Adds new Attacks
138 * if needed, increases HP, Attack Points, etc.
139 *
140 * @exception AttacksFullException if this has Monster.MAXATTACKS Attacks
141 * @see Monster
142 * @see Attack
143 */
144 protected void levelUp() throws AttacksFullException
145 {
146 super.levelUp();
147
148 if(level >= maxLevel && level < MAX_EARN_ATTACK_LEVEL)
149 {
150 setMaxLevel((byte)(maxLevel+START));
151 try
152 {
153 Attack a;
154 switch(lastAttack)
155 {
156 case 2:
157 {
158 a = new Attack(A3, Attack.DAMAGE3);
159 lastAttack++;
160 break;
161 }
162 case 3:
163 {
164 a = new Attack(A4, Attack.DAMAGE4);
165 lastAttack++;
166 break;
167 }
168 case 4:
169 {
170 a = new Attack(A5, Attack.DAMAGE5);
171 lastAttack++;
172 break;
173 }
174 case 5:
175 {
176 a = new Attack(A6, Attack.DAMAGE6);
177 lastAttack++;
178 }
179 default:
180 return;
181 }
182 if(attacks.size() < MAXATTACKS)
183 {
184 attacks.add(a);
185 }
186 else
187 throw new AttacksFullException("Attacks are full to the brim remove one to add a new one", a);
188 }
189 catch(InvalidPowerException e) { } // CANNOT HAPPEN HERE
190 }
191 }
192
193 /**
194 * Adds the attack specified by its name as parameter att to the Monster
195 * if it has less than Monster.MAXATTACKS
196 *
197 * @see Monster
198 * @param att the Name of the Attack to add
199 */
200 public void addAttack(String att) // Only used for instancitating the grid from a MapLoader
201 {
202 if(!(getNumberOfAttacks() < Monster.MAXATTACKS))
203 return;
204 Attack at;
205 for(int i = 0; i < attacks.size(); i++)
206 {
207 at = (Attack)attacks.get(i);
208 if(at.getName().equalsIgnoreCase(att))
209 return;
210 }
211 try
212 {
213 if(att.equalsIgnoreCase(A1))
214 {
215 attacks.add(new Attack(A1, Attack.DAMAGE1));
216 lastAttack = 1;
217 }
218 else if(att.equalsIgnoreCase(A2))
219 {
220 attacks.add(new Attack(A2, Attack.DAMAGE2));
221 lastAttack = 2;
222 }
223 else if(att.equalsIgnoreCase(A3))
224 {
225 attacks.add(new Attack(A3, Attack.DAMAGE3));
226 lastAttack = 3;
227 }
228 else if(att.equalsIgnoreCase(A4))
229 {
230 attacks.add(new Attack(A4, Attack.DAMAGE4));
231 lastAttack = 4;
232 }
233 else if(att.equalsIgnoreCase(A5))
234 {
235 attacks.add(new Attack(A5, Attack.DAMAGE5));
236 lastAttack = 5;
237 }
238 else if(att.equalsIgnoreCase(A6))
239 {
240 attacks.add(new Attack(A6, Attack.DAMAGE6));
241 lastAttack = 6;
242 }
243 }
244 catch(InvalidPowerException e) { } // CANNOT HAPPEN
245 }
246
247 /**
248 * Removes an Attack and adds a new Attack to the end.
249 *
250 * @param removed the Attack to remove
251 * @param added the Attack to add
252 * @return true if could remove the Attack and add the new one
253 */
254 public boolean substituteAttack(Attack removed, Attack added)
255 {
256 if(attacks.remove(removed))
257 {
258 attacks.add(added);
259 return true;
260 }
261 else
262 return false;
263 }
264
265 /**
266 * Returns the name of Attack A1
267 *
268 * @return A1
269 */
270 public String getA1() { return A1; }
271
272 /**
273 * Returns the name of Attack A2
274 *
275 * @return A2
276 */
277 public String getA2() { return A2; }
278
279 /**
280 * Returns the name of Attack A3
281 *
282 * @return A3
283 */
284 public String getA3() { return A3; }
285
286 /**
287 * Returns the name of Attack A4
288 *
289 * @return A4
290 */
291 public String getA4() { return A4; }
292
293 /**
294 * Returns the name of Attack A5
295 *
296 * @return A5
297 */
298 public String getA5() { return A5; }
299
300 /**
301 * Returns the name of Attack A6
302 *
303 * @return A6
304 */
305 public String getA6() { return A6; }
306
307 /**
308 * Returns a new Electric Monster with
309 * the same name as this.
310 */
311 public MapObject getClone() { return new ElectricMon(name); }
312 }