package dungeonmania.entities.inventory;
import java.util.ArrayList;
import java.util.List;
Copyright By PowCoder代写 加微信 powcoder
import java.util.stream.Collectors;
import dungeonmania.entities.BattleItem;
import dungeonmania.entities.Entity;
import dungeonmania.entities.EntityFactory;
import dungeonmania.entities.Player;
import dungeonmania.entities.buildables.Bow;
import dungeonmania.entities.collectables.Arrow;
import dungeonmania.entities.collectables.Key;
import dungeonmania.entities.collectables.Sword;
import dungeonmania.entities.collectables.Treasure;
import dungeonmania.entities.collectables.Wood;
public class Inventory {
private List
public boolean add(InventoryItem item) {
items.add(item);
return true;
public void remove(InventoryItem item) {
items.remove(item);
public List
int wood = count(Wood.class);
int arrows = count(Arrow.class);
int treasure = count(Treasure.class);
int keys = count(Key.class);
List
if (wood >= 1 && arrows >= 3) {
result.add(“bow”);
if (wood >= 2 && (treasure >= 1 || keys >= 1)) {
result.add(“shield”);
return result;
public InventoryItem checkBuildCriteria(Player p, boolean remove, boolean forceShield, EntityFactory factory) {
List
List
List
List
if (wood.size() >= 1 && arrows.size() >= 3 && !forceShield) {
if (remove) {
items.remove(wood.get(0));
items.remove(arrows.get(0));
items.remove(arrows.get(1));
items.remove(arrows.get(2));
return factory.buildBow();
} else if (wood.size() >= 2 && (treasure.size() >= 1 || keys.size() >= 1)) {
if (remove) {
items.remove(wood.get(0));
items.remove(wood.get(1));
if (treasure.size() >= 1) {
items.remove(treasure.get(0));
items.remove(keys.get(0));
return factory.buildShield();
return null;
public
for (InventoryItem item : items)
if (itemType.isInstance(item)) return itemType.cast(item);
return null;
public
int count = 0;
for (InventoryItem item : items)
if (itemType.isInstance(item)) count++;
return count;
public Entity getEntity(String itemUsedId) {
for (InventoryItem item : items)
if (((Entity) item).getId().equals(itemUsedId)) return (Entity) item;
return null;
public List
return items.stream().map(Entity.class::cast).collect(Collectors.toList());
public
return items.stream().filter(clz::isInstance).map(clz::cast).collect(Collectors.toList());
public boolean hasWeapon() {
return getFirst(Sword.class) != null || getFirst(Bow.class) != null;
public BattleItem getWeapon() {
BattleItem weapon = getFirst(Sword.class);
if (weapon == null)
return getFirst(Bow.class);
return weapon;
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com