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