1 回答

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個贊
有幾個可能的答案。
我知道你不想聽到它 - 但在這種情況下,另一個類真的會成為你最好的朋友,因?yàn)槟阌幸粋€ List,它可以簡單地從 String 類型更改為 Spell 類型(這將接受你的描述)。但請記住,這僅需要一個 Class,而不是每個元素一個 Class,所以工作量不大!
例子:
class Spell {
private String name;
private String description;
public Spell(String name, String description) {
this.name = name;
this.description = description;
}
//add getters
}
使用如下
spells.add(new Spell("Aid", "Your spell bolsters your allies with to..."));
另一種方法是使用 Enum (然后您可以使用.values()并丟棄列表)。但這不一定是最好的方法。在我看來,最好的解決方案是 - 不要自己做任何事情!
您現(xiàn)在是否有包含此信息的 API?http://www.dnd5eapi.co/
為什么不交換端點(diǎn)的字符串 - 使用 Rest API 加載您需要的所有信息。
作為Aid法術(shù)的示例,您將查找http://dnd5eapi.co/api/spells/?name=Aid返回的端點(diǎn):
"url": "http://www.dnd5eapi.co/api/spells/3"
當(dāng)您訪問該端點(diǎn)時,您可以獲得您的法術(shù)名稱和描述(以及更多)
{
_id: "5a52bc3a559f00418e532f2f",
index: 3,
name: "Aid",
desc: [
"Your spell bolsters your allies with toughness and resolve. Choose up to three creatures within range. Each targeta€?s hit point maximum and current hit points increase by 5 for the duration."
],
...
}
添加回答
舉報