1.玩家类pk 增加暴击 增加物品掉落(击杀敌人后随机掉落物品)

public class Demo01 {
    public String name;//名字
    public String type;//类型
    public int  life;//血量
    public int  attack;//攻击力
    public int  defense;//防御力

    public void say(){
        System.out.println("我叫"+name+",是一个"+type+",我的生命值高达"+life+",防御"+defense+",攻击"+attack);
    }

    public void pk(Demo01 p){

        while (true){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //每次都显示剩余的生命值
            this.say();
            p.say();
            //定义一个标记,0表示我方进攻,1表示敌方进攻
            int flag=0;//默认我方先进攻
            if(flag==0){
                int harm=this.attack-p.defense;//敌方得到的伤害
                p.setLife(p.life-harm);//敌人掉血
                System.out.println(p.name+"掉血" + harm);
                flag = 1;//交换进攻方
            }
            if(flag==1){
                int harm=p.attack-this.defense;//我方得到的伤害
                this.setLife(this.life-harm);//我方掉血
                System.out.println(this.name+"掉血" + harm);
                flag = 0;//交换进攻方
            }
            if (this.life<=0){
                System.out.println(this.name+"被KO了");
                break;//有人倒下,停止战斗
            }
            if (p.life<=0){
                System.out.println(p.name+"被KO了");
                break;//有人倒下,停止战斗
            }
        }
    }

    public String getName() {
        return name;
    }

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

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public int getAttack() {
        return attack;
    }

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

    public int getDefense() {
        return defense;
    }

    public void setDefense(int defense) {
        this.defense = defense;
    }
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值