java鸡你太美hunter类

public class Hunter {  private String name;  private int maxLife;  private int curLife;  private boolean isLive;  private Weapon weapon;

 //增加的攻击力和防御力,损失的生命是攻击力-防御力+7  private int attack;  private int defend;

 //等级和经验值  private int level;  private int exp;

 //增加敏捷和躲避几率  private int agile;  //闪躲最大几率  private int hideRate;

 public String getName() {   return name;  }

 public void setName(String name) {   this.name = name;  }

 public int getMaxLife() {   return maxLife;  }

 public void setMaxLife(int maxLife) {   this.maxLife = maxLife;  }

 public int getCurLife() {   return curLife;  }

 public void setCurLife(int curLife) {   this.curLife = curLife;  }

 public boolean isLive() {   return isLive;  }

 public void setLive(boolean isLive) {   this.isLive = isLive;  }

 public Weapon getWeapon() {   return weapon;  }

 public void setWeapon(Weapon weapon) {   this.weapon = weapon;  }

 public int getAttack() {   return attack;  }

 public void setAttack(int attack) {   this.attack = attack;  }

 public int getDefend() {   return defend;  }

 public void setDefend(int defend) {   this.defend = defend;  }

 public int getLevel() {   return level;  }

 public void setLevel(int level) {   this.level = level;  }

 public int getExp() {   return exp;  }

 public void setExp(int exp) {   this.exp = exp;  }

 public int getAgile() {   return agile;  }

 public void setAgile(int agile) {   this.agile = agile;  }

 public int getHideRate() {   return hideRate;  }

 public void setHideRate(int hideRate) {   this.hideRate = hideRate;  }

 //写一个带有两个参数的构造函数String name,String weapon  public Hunter(String name,Weapon weapon) {   this.name = name;   this.weapon = weapon;   maxLife = 100;   curLife = maxLife;   isLive = true;   attack = 25;   defend = 10;   level = 1;   exp = 0;   agile = 10;   hideRate = 10;  }

 public void fight(Enemy enemy) {   if(!isLive) {    return;   }   if(!enemy.isLive()) {    return;   }   System.out.println(name+"挥舞着"+weapon.getName()+"的"+weapon.getDesc()+"打向"+enemy.getType()+"  鸡你太美!!");   //this表示自己,Monster受伤需要知道是那个对象将其打伤,传递this表示指定是自己这个对象  weapon.damage(this,enemy);   //如果monster没有活着经验增加   if(!enemy.isLive()) {    this.expAdd(enemy);   }  }

 //躲避的方法  public boolean hidden() {   return GameUtil.isHide(this.hideRate,this.agile);  }

//传递是什么对象让自己受伤的  public int injured(Enemy enemy) {   if(hidden()) {    System.out.println(name+":打不到我!!鸡你太美!!");    show();   }   //获取丢失的生命   int lostLife = GameUtil.calLostLife(enemy.getAttack(),this.getDefend());   curLife-=lostLife;   System.out.println(name+":你居然打我!嘤嘤嘤!鸡你太美!!");   show();   if(curLife<=0) {    dead();    return lostLife;   }    return 0;  }

 /**显示当前的状态**/  public void show() {   System.out.println("name:"+name+",weapon:"+weapon.getDesc()+",curLife:"+      curLife+",maxLife:"+maxLife+",isLive:"+isLive+",attack:"+        attack+",defend:"+defend+",level:"+level+",exp:"+exp);  }

 public void dead() {   System.out.println(name+":我死了,嘤嘤嘤!鸡你太美!");   isLive = false;  }

 //经验值增加  public void expAdd(Enemy enemy) {   //1、让exp+monster的生命   this.exp+=enemy.getMaxLife();   //2、判断是否升级   //2.1、获取升级的经验 1*50+2*50+3*50   int needExp = 0;   for(int i=1;i<level+1;i++) {    needExp+=i*50;   }   //2.2、判断当前经验是否>升级所需经验   if(exp>=needExp) {    //3、如果升级调用upgrade方法    this.upgrade();   }  }

 public void upgrade() {   System.out.println("当当当当当当!!!"+name+"升级了!");   // 攻击力增加4,防御力增加3,maxLife增加20,curLife=maxLife   attack+=5;   defend+=5;   maxLife+=20;   curLife = maxLife;   level++;   show();  } }

posted @ 2019-05-09 16:09  18软件工程五班陈星星  阅读(570)  评论(0编辑  收藏  举报