蛇精,蜈蚣

package cn.cph.TestHomeWork;
public class Mon {
String name; //怪物名字
int hp; //生命值
int attack; //攻击力
public Mon() {

}
public Mon(String name,int hp,int attack) {
this.name = name;
this.hp = hp;
this.attack = attack;
}
void att() {
System.out.println("怪物"+name+"展开攻击!");
System.out.println("当前生命值:"+hp);
System.out.println("攻击力:"+attack);
}
void main() {

}
}
============================================
package cn.cph.TestHomeWork;
public class Snack extends Mon{
public Snack() {

}
public Snack(String name,int hp,int attack) {
super(name,hp,attack);
}
void addHp() {
hp = hp+20;
System.out.println("实施大蛇补血术.....当前生命值:"+hp);
}
void move() {
System.out.println("我是蛇妖,我走S型路线");
}
}

===================================================
package cn.cph.TestHomeWork;
public class Centipede extends Mon{
public Centipede() {

}
public Centipede(String name,int hp,int attack) {
super(name,hp,attack);
}
void move() {
System.out.println("我是蜈蚣精,御风飞行!");
}
}

=============================
package cn.cph.TestHomeWork;
public class TestMon {
public static void main(String[] args) {
Snack snack = new Snack("蛇妖甲",5,15);
snack.att();
snack.addHp();
snack.move();
System.out.println("=======================");
Centipedecentipede = newCentipede("蜈蚣乙",60,15);
centipede.att();
centipede.move(); ;
}
}

【蛇精,蜈蚣】

    推荐阅读