德玛西亚的生与死

//英雄类
public class Hero {
    String name;
    int power=100;//满血
    //增加体力
    void eat(String food,int value){
        System.out.println(this.name+"吃了"+food+"增加血量");
    power=(power+value>100)?100:(power+value);
    
    }
    
    //受到伤害
    void hurt(){
    power-=20;
    System.out.println("你伤害了我,还一笑而过");
    if(power<=0){
        System.out.println(name+"over");
    }
    
  }    

}
public class Test {

    public static void main(String[] args) {
 Hero h=new Hero();
 h.name="德玛西亚";
  h.eat("大血瓶",50);
  for(int i=0;i<2;i++){
      h.hurt();
  }
h.eat("烤冷面",30);
    }
    }

 

posted @ 2017-04-04 21:12  苏轼的红烧肉  阅读(104)  评论(0编辑  收藏  举报