假设我有这些怪物(已经配置了它们的名称、攻击力、等级、经验值等),但是跟踪它们的 X 和 Y 的好方法是什么?
也许是ArrayList<>
?就像在 arraylist 1|12|8|3
中添加一样哪里1
是怪物的ID(稍后用作m 1
.gif,12是X,8是Y,3是 map 编号。
你认为用Java在 map 中存储怪物的好方法是什么?
最佳答案
嗯,您当然不想通过使用面向对象语言中的对象来利用封装。
class Monster
{
private String myName;
private int attack;
private int level;
private int experience;
public Monster(String n, int att, int lvl, int e)
{
myName = n;
attack = att;
level = lvl;
experience = e;
}
// other useful methods go here!
}
关于java - 在Java中存储多个变量的好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4982662/