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   
8   /**
9    * Defines an ADT for Attacks.
10   * 
11   * @see Monster
12   */
13  public class Attack
14  {
15      /**
16       * The Damage associated with the first Attack learned (A1)
17       */
18      public static double DAMAGE1 = .1;
19      /**
20       * The Damage associated with the second Attack learned (A2)
21       */
22      public static double DAMAGE2 = .15;
23      /**
24       * The Damage associated with the third Attack learned (A3)
25       */
26      public static double DAMAGE3 = .2;
27      /**
28       * The Damage associated with the fourth Attack learned (A4)
29       */
30      public static double DAMAGE4 = .25;
31      /**
32       * The Damage associated with the fifth Attack learned (A5)
33       */
34      public static double DAMAGE5 = .4;
35      /**
36       * The Damage associated with the sixth Attack learned (A6)
37       */
38      public static double DAMAGE6 = .5;
39      /**
40       * The Multiplier to use if the Monster is a weak type against the other Monster
41       * 
42       * @see Monster
43       */
44      public static final double DAMAGEMULT = 1.15; // If weak against opp type do this times more damage
45  
46      /**
47       * The name of the attack
48       */
49      private String name;
50      /**
51       * The power of the attack, defined above
52       */
53      private double power;
54  
55      /**
56       * Constructs a new Attack with name and power.
57       * 
58       * @param name The name of the Attack
59       * @param pow the Power of the attack (0<=x<=.5)
60       * @exception InvalidPowerException if pow is not this.DAMAGE*
61       */
62      public Attack(String name, double pow) throws InvalidPowerException
63      {
64          this.name = name;
65          if(pow == DAMAGE1 || pow == DAMAGE2 || pow == DAMAGE3 || pow == DAMAGE4 || pow == DAMAGE5 || pow == DAMAGE6)
66              power = pow;
67          else
68              throw new InvalidPowerException(pow + " is not a valid damage amount");
69      }
70  
71      /**
72       * Get the name associated with the Attack.
73       * 
74       * @return the name of this Attack
75       */
76      public String getName() { return name; }
77      /**
78       * Gets the power of the Attack
79       * 
80       * @return the power of the Attack
81       */
82      public double getPower() { return power; }
83      /**
84       * Compares the Object to this.
85       * 
86       * @param o the Object to compare with this
87       * @return true if equal, false otherwise.
88       */
89      public boolean equals(Object o)
90      {
91          if(o instanceof Attack)
92          {
93              return equals((Attack)o);
94          }
95          return false;
96      }
97      /**
98       * Compares the Attack to this. Uses Power to 
99       * determine equality.
100      * 
101      * @param o the Attack to compare with this
102      * @return true if equal, false otherwise.
103      */
104     public boolean equals(Attack a)
105     {
106         return a.power == this.power;
107     }
108 }