1   import java.awt.*;
2   import java.applet.*;
3   import javax.swing.*;
4   import java.awt.image.*;
5   import java.awt.geom.*;
6   import java.net.*;
7   import java.util.*;
8   /**
9    * Simple class for an Item used to catch Monsters
10   * 
11   * @see Monster
12   * @see Item
13   */
14  public class MonsterBallItem extends Item
15  {
16      /**
17       * Normal MonsterBall subBrand
18       */
19      public static final int NORMAL = 1;
20      /**
21       * Master MonsterBall subBrand
22       */
23      public static final int MASTER = 2;
24  
25      /**
26       * the subBrand
27       */
28      private int subBrand;
29  
30      /**
31       * Construct a MonsterBallItem based upon name and subBrand.
32       * 
33       * @param name The name for this
34       * @param subBrand the subBrand as defined above
35       */
36      public MonsterBallItem(String name, int subBrand)
37      {
38          brand = MONSTERBALL;
39          if(name != null)
40              this.name = name;
41          else
42              name = "Normal MonsterBall";
43          brand = MONSTERBALL;
44          if(subBrand == NORMAL || subBrand == MASTER)
45              this.subBrand = subBrand;
46          else
47              this.subBrand = NORMAL;
48          number = 1;
49      }
50      /**
51       * Gets the subBrand of this
52       * 
53       * @return the subBrand of this
54       */
55      public int getSubBrand() { return subBrand; }
56  
57      /**
58       * Attempts to use the MonsterBall on the Monster.  If
59       * this is successful then returns true, else returns false.  Needs
60       * to be passed the opposing Monster the Player is trying to catch
61       * 
62       * @param m the opposing Monster trying to catch
63       * @return true iff Monster was able to be caught, still needs to be added to Player.  Else false
64       * @see Player
65       * @see Monster
66       */
67      public boolean useItem(Monster m) // Monster trying to capture
68      {
69          double r = Math.random();
70          number--;
71          if(getSubBrand() == NORMAL)
72          {
73              if(m.getLevel() < 20)
74              {
75                  if(r < .9) // Works 90% of the time
76                      return true;
77                  else
78                      return false;
79              }
80              else
81              {
82                  if(r < .2) // Works 20% of the time
83                      return true;
84                  else
85                      return false;
86              }
87          }
88          else
89          {
90              if(r < 9) // Works 90% of the time
91                  return true;
92              else
93                  return false;
94          }
95      }
96  }