我正在制作一个游戏,一个rpg (是的,又是另一个试图制作其中之一的家伙),我已经成功地制作了其中的大部分,除了库存和它与世界其他地方的行为,现在我想以一种逻辑的方式在列表之间移动项目,例如,我杀死了一个怪物,怪物会在ArrayList worldInventory中创建一个番茄,番茄()将在x,y,如果玩家经过番茄,番茄应该被移动到ArrayList库存,如果玩家想装备番茄,番茄应该被移动到ArrayList装备。
因此,为了使事情更容易理解,我有3份清单:
ArrayList<Item> worldInventory
ArrayList<Item> Inventory
ArrayList<Item> equipped.我希望在它们之间移动Tomato()的副本,如果一个Tomato()的值在列表中被更改,并且它被移动了,我希望该Tomato()保留它的值。
我会给帮助我的人一个大尺寸的网络巧克力饼干,非常感谢。谢谢n.n .
发布于 2015-01-19 13:43:53
关于物品下降:
Tomato tomato = new Tomato();
worldInventory.add(tomato);在收件上:
worldInventory.remove(tomato);
inventory.add(tomato);关于装备:
inventory.remove(tomato);
equipped.add(tomato);只是想知道你为什么需要装备好的ArrayList?
您可以在您的WorldObject ( boolean equipped = false)中设置一个布尔标志,并将其设置为true。
发布于 2015-01-19 13:43:51
如果将对象添加到列表中,则该对象将保留其所有字段值。只是:
Tomato yourTomatoObject = otherList.remove(index);
inventory.add(yourTomatoObject);发布于 2015-01-19 13:44:22
你可以这样做:
public static void main(String[] args) {
ArrayList<String> test = new ArrayList<String>();
ArrayList<String> test1 = new ArrayList<String>();
test.add("test");
test1.add(test.get(0));
test.remove(0);
System.out.println("" + test.size());
System.out.println("" + test1.get(0));
}您可以将它添加到一个数组列表中,然后从另一个数组中删除它。
https://stackoverflow.com/questions/28025974
复制相似问题