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