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();
;
}
}
【蛇精,蜈蚣】
推荐阅读
- 关于欧几里得算法和拓展欧几里得算法
- 程序|android 不销毁当前activity,返回上一层,亲测有效
- c语言while循环打印等腰三角型
- 电子DIY|《电子DIY》之《单片机实践项目》之基于51单片机的TCS230颜色识别模块
- JsonHelper
- Jmysy-Pear-Admin-Layui
- 输出HTML源码进行压缩
- 获取游览器类型
- 框架|Java如何使用Web3j开发以太坊区块链Dapp的教程