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