也可以把这四个类直接复制下去放在一个包下面
父类
package Cs1_6;
public abstract class Persion {
public abstract void Attack(Persion p);
public abstract boolean Shan();
public abstract boolean Baoji();
public Persion() {
}
public Persion(int hp, int atk) {
this.hp = hp;
this.atk = atk;
}
private int hp;
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getAtk() {
return atk;
}
public void setAtk(int atk) {
this.atk = atk;
}
private int atk;
}
匪徒类继承人类
package Cs1_6;
public class Fei extends Persion {
public static int shantemp=0;
public Fei() {
}
public Fei(int hp, int atk) {
super(hp, atk);
}
@Override
public String toString() {
return String.format("匪徒的生命为%d,攻击为%d",this.getHp(),this.getAtk());
}
@Override
public void Attack(Persion p) {
if (p instanceof Police){
Police pp = (Police)p;
if (Baoji()){
System.out.println("匪徒达成暴击");
pp.setHp(0);