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 Gas
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 GasMon extends Monster
18  {
19      /**
20       * The number of levels needed before learning a new attack
21       */
22      protected static final int START = 11;
23      /**
24       * The level at which all attacks have been learned
25       */
26      protected static final int MAX_EARN_ATTACK_LEVEL = 45;
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 = "Finger-Pulled";
35      /**
36       * The name of the third attack
37       */
38      protected static final String A3 = "Make-U-Reek";
39      /**
40       * The name of the fourth attack
41       */
42      protected static final String A4 = "Silent-But-Deadly";
43      /**
44       * The name of the fifth attack
45       */
46      protected static final String A5 = "Ate-Some-Beans";
47      /**
48       * The name of the sixth attack
49       */
50      protected static final String A6 = "Mega-Fart";
51      /**
52       * The last attack learned (2 <= x <= 5)
53       */
54      protected int lastAttack = 2;
55      /**
56       * Construct a Gas Monster with the default values:
57       * name is Alligatrix
58       * level is two. 
59       */
60      public GasMon()
61      {
62          type = MapObject.MONSTER;
63          attacks = new Vector();
64          maxLevel = START;
65          name = "Eurekasaur";
66          kind = GAS;
67          enterable = true;
68  
69          level = 2;
70          int lev6 = 6*level;
71          int lev7 = 7*level;
72          int lev10 = 10*level;
73          hp = lev7;
74          defp = lev10;
75          attp = lev6;
76          maxHP = lev7;
77          maxDef = lev10;
78          maxAtt = lev6;
79          exp = 0;
80          maxExp = lev10;
81          addAttack(A1);
82          addAttack(A2);
83      }
84  
85      /**
86       * Constructs a Gas Monster with the name name.
87       * level is two.
88       * 
89       * @param name the name of the Gas Monster
90       */
91      public GasMon(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 = "Eurekasaur";
100         kind = GAS;
101         enterable = true;
102 
103         level = 2;
104         int lev6 = 6*level;
105         int lev7 = 7*level;
106         int lev10 = 10*level;
107         hp = lev7;
108         defp = lev10;
109         attp = lev6;
110         maxHP = lev7;
111         maxDef = lev10;
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      * 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     /**
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 Gas Monster with
309      * the same name as this.
310      */
311     public MapObject getClone() { return new GasMon(name); }
312 }