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    * Class to define the Potions, HP Up's, Attack Up's, and Defense Up's.
10   * 
11   * @see Item
12   * @see People 
13   */
14  public class PotionItem extends Item
15  {
16      /**
17       * The HP Up half subBrand Identifier
18       */
19      public static final int HPUPHALF = 4;
20      /**
21       * The Defense Up subBrand Identifier
22       */
23      public static final int DEFUP = 5;
24      /**
25       * The Attack Up subBrand Identifier
26       */
27      public static final int ATTUP = 6;
28      /**
29       * The HP Up full subBrand Identifier
30       */
31      public static final int HPUPFULL = 7;
32      /**
33       * The HP Up third subBrand Identifier
34       */
35      public static final int HPUPTHIRD = 8;
36  
37      /**
38       * The type
39       */
40      private int subBrand;
41  
42      /**
43       * Create a new PotionItem with the specified name, and subBrand.
44       * 
45       * @param name the name of the Item
46       * @param subBrand the type of Item defined above
47       */
48      public PotionItem(String name, int subBrand)
49      {
50          if(name != null)
51              this.name = name;
52          else
53              this.name = "Potion";
54          brand = POTION;
55          if(subBrand == HPUPHALF || subBrand == DEFUP || subBrand == ATTUP || subBrand == HPUPFULL || subBrand == HPUPTHIRD)
56              this.subBrand = subBrand;
57          else
58              this.subBrand = HPUPTHIRD;
59          number = 1;
60      }
61      /**
62       * Returns the type of Item this is.
63       * 
64       * @return the type of Item this is.
65       */
66      public int getSubBrand() { return subBrand; }
67  
68      /**
69       * Use this on the specified Monster
70       * 
71       * @param m The Monster to use this on, should be the Players Monster.
72       * @return true
73       */
74      public boolean useItem(Monster m) // Your Monster
75      {
76          int i = m.getKind();
77          number--;
78          switch(subBrand)
79          {
80              case HPUPHALF:
81              {
82                  m.setHP(m.getHP() + m.getMaxHP()/2);
83                  break;
84              }
85              case HPUPFULL:
86              {
87                  m.setHP(m.getMaxHP());
88                  break;
89              }
90              case HPUPTHIRD:
91              {
92                  m.setHP(m.getHP() + m.getMaxHP()/3);
93                  break;
94              }
95              case DEFUP:
96              {
97                  if(i == m.ELECTRIC)
98                  {
99                      m.setMaxDefense(m.getMaxDefense() + 7);
100                     m.setDefense(m.getMaxDefense());
101                 }
102                 else if(i == m.EARTH)
103                 {
104                     m.setMaxDefense(m.getMaxDefense() + 6);
105                     m.setDefense(m.getMaxDefense());
106                 }
107                 else if(i == m.WATER)
108                 {
109                     m.setMaxDefense(m.getMaxDefense() + 10);
110                     m.setDefense(m.getMaxDefense());
111                 }
112                 else if(i == m.FIRE)
113                 {
114                     m.setMaxDefense(m.getMaxDefense() + 7);
115                     m.setDefense(m.getMaxDefense());
116                 }
117                 else if(i == m.GAS)
118                 {
119                     m.setMaxDefense(m.getMaxDefense() + 10);
120                     m.setDefense(m.getMaxDefense());
121                 }
122                 break;
123             }
124             case ATTUP:
125             {
126                 if(i == m.ELECTRIC)
127                 {
128                     m.setMaxAttack(m.getMaxAttack() + 10);
129                     m.setAttack(m.getMaxAttack());
130                 }
131                 else if(i == m.EARTH)
132                 {
133                     m.setMaxAttack(m.getMaxAttack() + 7);
134                     m.setAttack(m.getMaxAttack());
135                 }
136                 else if(i == m.FIRE)
137                 {
138                     m.setMaxAttack(m.getMaxAttack() + 6);
139                     m.setAttack(m.getMaxAttack());
140                 }
141                 else if(i == m.WATER)
142                 {
143                     m.setMaxAttack(m.getMaxAttack() + 7);
144                     m.setAttack(m.getMaxAttack());
145                 }
146                 else if(i == m.GAS)
147                 {
148                     m.setMaxAttack(m.getMaxAttack() + 6);
149                     m.setAttack(m.getMaxAttack());
150                 }
151                 break;
152             }
153         }
154         return true;
155     }
156 }