无标题文章

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;

}

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • JAVA面试题 1、作用域public,private,protected,以及不写时的区别答:区别如下:作用域 ...
    JA尐白阅读 1,193评论 1 0
  • 转至元数据结尾创建: 董潇伟,最新修改于: 十二月 23, 2016 转至元数据起始第一章:isa和Class一....
    40c0490e5268阅读 1,838评论 0 9
  • 每日要点 修改器和访问器 修改器 - 属性的setter方法 访问器 - 属性的getter方法 toString...
    迷茫o阅读 274评论 0 0
  • ``` /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject ...
    非专业码农阅读 355评论 0 0
  • 小溪和前男友分手已经快两年了,现在再提起当初那个人,很多事情在记忆里已经模糊。可是每每有朋友问起,她总是会笑着说他...
    一杯甜酒阅读 3,074评论 0 1