package week0203;
public class ULtraman {
private String name;
private int hp; //生命值
private int mp;
public String getName() {
return name;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp<0?0:hp;
}
public int getMp(){
return mp;
}
public ULtraman(String name, int hp, int mp) {
this.name = name;
this.hp = hp;
this.mp = mp;
}
public String info() {
return String.format("%s奥特曼 - 生命值:%d, 魔法值:%d",name,hp,mp);
}
public void attack(Monseter m) {
int injury=(int)(Math.random()*11+10);
m.setHp(m.getHp() - injury);
}
public void hugeAttack(Monseter m){
if(mp>=40){
int injury=m.getHp()/4*3>50?m.getHp()/4*3:50;
m.setHp(m.getHp() - injury);
mp-=40;
}
}
public void magicAttack(Monseter[] mArray) {
if(mp>=15){
for(Monseter m:mArray){
int injury=(int)(Math.random()*11+5);
m.setHp(m.getHp() - injury);
}
mp=mp-15;
}
}
}
网友评论