某公司要开发新游戏,请用面向对象的思想,设计游戏中的蛇怪和蜈蚣精
设定
- 蛇怪类:
属性包括:怪物名字,生命值,攻击力
方法包括:攻击,移动(曲线移动),补血(当生命值<10时,可以补加20生命值) - 蜈蚣精类:
属性包括:怪物名字,生命值,攻击力
方法包括:攻击,移动(飞行移动)
要求
- 分析蛇怪和蜈蚣精的公共成员,提取出父类—怪物类
- 利用继承机制,实现蛇怪类和蜈蚣精类
- 攻击方法,描述攻击状态。内容包括怪物名字,生命值,攻击力
- 编写测试类,分别测试蛇怪和蜈蚣精的对象及相关方法
public class Monster {
// 怪物类
// 名字
private String name;
// 生命力
private int hitPoints;
// 攻击力
private int attack;
public Monster() {
super();
}
public Monster(String name, int hitPoints, int attack) {
super();
this.name = name;
this.hitPoints = hitPoints;
this.attack = attack;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name &