MonkeyDjack :
I have a task to make a project in java with the usage of ArrayList, hashmap, abstract classes, and interface. I decided to develop a text-based RPG in java. I want to use abstract classes for monsters, ArrayList for inventory and hashmap for equipping armors and weapons, however, I don't really figure out if it is possible to make equip function with hashmap. I was thinking to make something like this
public HashMap<PartOfBody , Weapon/Armor> equipment;
I would love to hear from you about any ideas about how to do it.
AK47 :
You could implement something along the lines of this:
public Abstract class Equipment {}
public class Weapon extends Equipment {}
public class Armor extends Equipment {}
public class BodyPart {
String part;
public BodyPart(String part) {
this.part = part;
}
}
public class RPG {
public static void main(String args[]) {
HashMap<BodyPart, Equipment> equipment = new HashMap<BodyPart, Equipment>();
equipment.put(new BodyPart("Arm"), new Weapon());
equipment.put(new BodyPart("Head"), new Armor());
equipment.put(new BodyPart("Arm"), new Armor());
}
}
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=358538&siteId=1