add util for showing items
This commit is contained in:
@@ -1,4 +1,75 @@
|
|||||||
package org.project.util;
|
package org.project.util;
|
||||||
|
|
||||||
|
import org.project.Interface.IDamageUtil;
|
||||||
|
import org.project.Interface.IDefender;
|
||||||
|
import org.project.constants.appConstants.TextColor;
|
||||||
|
import org.project.item.Accessory.Accessory;
|
||||||
|
import org.project.item.Item;
|
||||||
|
import org.project.item.KeyItem;
|
||||||
|
import org.project.item.SellableItem;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
public class DisplayItem {
|
public class DisplayItem {
|
||||||
|
public static void DisplayItems(ArrayList<Item> items) {
|
||||||
|
for (Item item : items) {
|
||||||
|
String result = item.getName();
|
||||||
|
|
||||||
|
if (item instanceof SellableItem) {
|
||||||
|
result += "\n Price = " + ((SellableItem) item).GetPrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item instanceof Accessory) {
|
||||||
|
result += "\n Health = " + ((Accessory) item).GetHealth() + "/" + ((Accessory) item).GetMaxHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item instanceof IDamageUtil) {
|
||||||
|
result += "\n Damage = " + ((IDamageUtil) item).GetDamage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item instanceof IDefender) {
|
||||||
|
result += "\n Damage = " + ((IDefender) item).GetDefense();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<Integer, Item> MenuDisplay(ArrayList<Item> items) {
|
||||||
|
int index = 0;
|
||||||
|
Dictionary<Integer, Item> dictionary = new Hashtable<>();
|
||||||
|
|
||||||
|
for (Item item : items) {
|
||||||
|
String result = index + " > " + item.getName();
|
||||||
|
|
||||||
|
if (item instanceof KeyItem) {
|
||||||
|
result += TextColor.Yellow + " (KEY ITEM)" + TextColor.Reset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item instanceof SellableItem) {
|
||||||
|
result += "\n Price = " + ((SellableItem) item).GetPrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item instanceof Accessory) {
|
||||||
|
result += "\n Health = " + ((Accessory) item).GetHealth() + "/" + ((Accessory) item).GetMaxHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item instanceof IDamageUtil) {
|
||||||
|
result += "\n Damage = " + ((IDamageUtil) item).GetDamage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item instanceof IDefender) {
|
||||||
|
result += "\n Damage = " + ((IDefender) item).GetDefense();
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary.put(index, item);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dictionary;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user