为RPG游戏(Java)中的道具系统寻求建议

  • 本文关键字:系统 游戏 RPG Java java
  • 更新时间 :
  • 英文 :


大家好!所以我一直在我的空闲时间做一些游戏创意,我目前正在创建rpg项目系统。首先,我制作了基类Item。它实现了Comparable,我根据游戏名称设置了它的自然顺序。

public abstract class Item implements Comparable<Item> {

protected String inGameName;
protected String description;
protected int id;
protected int value;

public Item(int id, String inGameName, String description, int value) {
this.id = id;
this.inGameName = inGameName;
this.description = description;
this.value = value;
}

public String getInGameName() {
return this.inGameName;
}

public String getDescription() {
return this.description;
}

public int getId() {
return this.id;
}

public int getValue() {
return this.value;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Item))
return false;
else {
Item otherItem = (Item) obj;
Integer thisId = this.getId();
Integer otherId = otherItem.getId();
return thisId.equals(otherId);
}
}

@Override
public int compareTo(Item otherItem) {
return this.inGameName.compareTo(otherItem.getInGameName());
}
}

之后,我创建了类StackableItem,它实现了Stackable接口。此类表示库存中可堆叠的物品,如材料、药剂等。

public interface Stackable {

public int getStackLimit();
public int getStackSize();
public void setStackSize(int size);

}
public abstract class StackableItem extends Item implements Stackable {

private int stackLimit;
private int stackSize;

public StackableItem(int id, String inGameName, String description, int value, int stackLimit, int stackSize) {
super(id, inGameName, description, value);
this.stackLimit = stackLimit;
this.stackSize = stackSize;
}

public int getStackLimit() {
return this.stackLimit;
}

public int getStackSize() {
return this.stackSize;
}

public void setStackSize(int size) {
this.stackSize = size;
}

}

最后,我创建了实现Consumerable接口的consumerItem类。

public interface Consumable {

public boolean isItemOnCooldown();
public int getCooldownTime();

}

public class ConsumableItem extends StackableItem implements Consumable {

private boolean onCooldown;
private int cooldownTime;

public ConsumableItem(int id, String inGameName, String description, int value, int stackLimit, int stackSize, int cooldownTime) {
super(id, inGameName, description, value, stackLimit, stackSize);
this.cooldownTime = cooldownTime;
this.onCooldown = false;
}

public boolean isItemOnCooldown() {
return this.onCooldown;
}

public int getCooldownTime() {
return this.cooldownTime;
}
}

显然,还有一些功能缺失,比如对消费的影响,但这些都是第一个想法。既然我有了ConsumerItem类,我应该为我想要创建的每个项目创建子类吗,例如Small Health Potion、Large Health Potion和Magic Scroll等,还是最好为每个项目创建具有预定义值的Enum并使用该信息来实例化ConsumerItem?

这只是一个提醒,这是一个提问的空间,比如"为什么这不起作用";,而这应该在讨论论坛上进行(规则明确规定SO不是(。只是为了未来:(

话虽如此,我还是会列举,因为作为一名游戏设计师,你永远不知道自己要强制添加多少项目,而为每个项目都有一个子类会让人很累。

最新更新