栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

游戏,作业

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

游戏,作业

public class Plater {
    public String name;
    public String type;
    public int life;
    public int defense;
    public int attack;
 
   
    Random a = new Random();
    Random b = new Random();
    Random c = new Random();
    public void say(){
        System.out.println("我是"+name+",一个"+type);
        System.out.println(",血量"+life+",防御"+defense+"攻击"+attack);
    }
 
    public void pk(Plater p){
        int flag = 0;
        //回合制,直至一方死亡
        while (true) {
            this.say();
            p.say();
 
            if (flag == 0) {
                int harm = this.attack - p.defense;
                int t = b.nextInt(2);
                if (t!=0){
                    System.out.println(p.name + "掉血" + harm);
                    p.life -= harm;
                }else {
                    System.out.println("暴击!致命一击!");
                    System.out.println(p.name + "掉血" + harm*2);
                    p.life -= harm*2;
                }
                flag = 1;
            } else {
                int harm = p.attack - this.defense;
                int l = c.nextInt(2);
                if (l!=0){
                    System.out.println(this.name + "掉血" + harm);
                    this.life -= harm;
                }else {
                    System.out.println("暴击");
                    System.out.println(this.name + "掉血" + harm*2);
                    this.life -= harm*2;
                }
                flag = 0;
            }
            //有血量<=0,战斗结束
            if(this.life<=0){
                System.out.println(p.name+"打败了"+this.name);
                break;
            }
            if(p.life<=0){
                System.out.println(this.name+"打败了"+p.name);
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
 
 
        String [] stu = {"奖励1200经济","黑色切割者","名刀司命","破甲弓","十块钱人民币"," "};
        for (int z = 0; z < stu.length; z++) {
            z = a.nextInt(6);
            System.out.println("恭喜你五连绝世并获得"+stu[z]);
            break;
        }
    }
    
    public Plater() {
    }
    public Plater(String name, String type, int life, int defense, int attack) {
        this.name = name;
        this.type = type;
        this.life = life;
        this.defense = defense;
        this.attack = attack;
    }
 
       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 getDefense() {
        return defense;
    }
 
    public void setDefense(int defense) {
        this.defense = defense;
    }
 
    public int getAttack() {
        return attack;
    }
 
    public void setAttack(int attack) {
        this.attack = attack;
    }
}

public class PlayerTest {
    public static void main(String[] args) {
       
        Plater p1 = new Plater("无名", "战士", 1000, 120, 300);
        Plater p2 = new Plater("影", "法师", 1200, 130, 280);
 
  
        p1.pk(p2);
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1007259.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号