Item.java |
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 * Abstract class to represent an Item. 10 * 11 * @see MonsterBallItem 12 * @see PotionItem 13 * @see People 14 */ 15 public abstract class Item 16 { 17 /** 18 * Brand of MonsterBall 19 */ 20 public static final int MONSTERBALL = 0; 21 /** 22 * Brand of Potion 23 */ 24 public static final int POTION = 3; 25 26 /** 27 * The name of this Item 28 */ 29 protected String name; 30 /** 31 * The number amount of this that the People has. 32 */ 33 protected int number; 34 /** 35 * The brand of Item this is. 36 */ 37 protected int brand; 38 39 /** 40 * Sets the name of this Item. 41 * 42 * @param nn the New Name of this. 43 */ 44 public void setName(String nn) 45 { 46 if(nn != null) 47 name = nn; 48 } 49 /** 50 * Gets the name of this Item. 51 * 52 * @return the name of this Item 53 */ 54 public String getName() { return name; } 55 /** 56 * Adds another of this. 57 */ 58 public void addItem() { number++; } 59 /** 60 * Sets the number of this there is. 61 * 62 * @param ic the new Item Count 63 */ 64 public void setItemCount(int ic) 65 { 66 if(ic > 0) 67 this.number = ic; 68 } 69 /** 70 * Gets the number of this there is 71 * 72 * @return the number of this that are available 73 */ 74 public int getItemCount() { return number; } 75 /** 76 * Uses the item on the Monster Specified 77 * 78 * @param m the Monster to use the Item on 79 */ 80 public abstract boolean useItem(Monster m); 81 /** 82 * Gets the Brand of this. 83 * 84 * @return th Brand of this as defined above. 85 */ 86 public int getBrand() { return brand; } 87 /** 88 * Gets the subBrand of this defined in PotionItem and MonsterBallItem 89 * 90 * @return the sub Brand of this. 91 * @see MonsterBallItem 92 * @see PotionItem 93 */ 94 public abstract int getSubBrand(); 95 /** 96 * Determines if there is equality 97 * 98 * @param o the Object to compare to 99 * @return true iff they represent the same Item 100 */ 101 public boolean equals(Object o) 102 { 103 if(o instanceof Item) 104 return equals((Item)o); 105 return false; 106 } 107 /** 108 * Determines if there is equality 109 * 110 * @param i the Item to compare to 111 * @return true iff they represent the same Item, ie have the same Name 112 */ 113 public boolean equals(Item i) 114 { 115 return i.getName().equalsIgnoreCase(name); 116 } 117 }