吉软-人文精英班-第四次作业


public class Hunter {
    String name;
    int life;   //生命值
    String weapon;  //武器
    boolean isLive;  //是否活着
    int att;        // 人类的伤害值
    int blood;      // 僵尸剩余血量
    Hunter(String name,int life,String weapon,boolean isLive){   //构造方法
        this.name=name;
        this.life=life;
        this.isLive=isLive;
        if(weapon.equals("大型武器")){     //选择武器
            att=50;
        }else{
            att=20;
        }
    }
    public void fight(Monster m){  //定义一个方法,僵尸暂时的状态。   
        m.life=m.life-att;      //调用僵尸生命值=生命值-伤害值
        blood=m.life;
        if(blood<=0){         
            m.dead();
        }else{
            m.injured();
            show();
            
        }
    }
    public void injured(){                //三个方法
        System.out.println(name+"受伤了");
    }
    public void dead(){
        System.out.println(name+"已经死亡");
    }
    public void show(){
        System.out.println("此时还剩余:"+blood+"HP");
    }
}

 

 


public class Monster {
    String type;  //类型
    boolean isLive; 
    int life;
    int arr;     //僵尸伤害值
    int bloodd;   //猎人剩余血量
    
    Monster(String type,boolean isLive,int life){
        this.type=type;
        this.isLive=isLive;
        this.life=life;
        if(type.equals("僵尸王")){         //僵尸类型
            life=1000;
            arr=30;
        }
        if(type.equals("小僵尸")){
            life=700;
            arr=20;
        }
    }
    public void injured(){           //定义一个受伤的方法
        System.out.println(type+"受伤");
    }
    public void kill(Hunter h){
        h.life=h.life-arr;
        bloodd=h.life;
        if(bloodd<=0){
            h.dead();
        }else{
            h.injured();
            show();
        }
    }
    public void dead(){
        System.out.println("僵尸死亡");
    }
    public void show(){
        System.out.println("此时还剩余"+bloodd+"HP");
    }
}
 

 

 


public class TestGame {
    public static void main(String[] args) {
        Hunter h=new Hunter("强强猎人",500,"大型武器",true);   //创建猎人的对象
        Monster m=new Monster("僵尸王",true,1000);          //创建僵尸的对象
        for(int i=1;;i++){
            System.out.println();
            System.out.println("第"+i+"回合");
            h.fight(m);
            m.kill(h);
            if(h.life<=0){
                System.out.println(h.name+"已经阵亡,游戏结束");
                break;            
            }if(m.life<=0){
                System.out.println(m.type+"已经阵亡,游戏技术");
                break;
            }
        }
        
        
    }
        
        
        
}

204212_nFs7_3858314.png

 


204138_gcAt_3858314.png

 

 

转载于:https://my.oschina.net/u/3858314/blog/1815399

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值