我在实例方面遇到了一些麻烦
我在用户与怪物战斗的java中制作游戏,每个怪物都有自己的类文件,其中包含静态参考信息(健康,攻击,防御,introText和atkText),它们是Monster类的子类。
我开始战斗:
Monster current = new monster();
我的问题是我完全不知道怪物是什么,我不想要一个开关盒 我可以做点什么吗
Monster current = new getClassFromString(monster);
那个?我使用类似数据库的类来存储怪物类型/种族的基本信息,或者像lua表(我更常用于lua):
Dragon = {"health"=100, "atk" = 25, "def" = 10}
Troll = {"health"=50, "atk" = 10, "def" = 0} //these exist in the files as classes
Monsters = { Dragon, Troll } //the ones before are subclasses of Monsters
//after the user selected the monster he wants to fight
current = Monsters[selected] //and now the table current contains all the info I need, without altering the stored one (in Dragon and Troll, and every other kind of monster)
有没有办法在Java中做到这一点,但表是类?