写了挺多,脑子都炸了,眼都花了。。注释以后再加吧。
package com.maya.chongwu; import java.util.Date; public class Pet { private int Hp; boolean lock = true; private String name; private String name1; public int num; boolean lock1 = true; private String sex; private int age; private String pinzhong; private Date birthday; private int healthy; // 健康 private int hungry; // 饥饿 private int happy; // 心情 private int intelligence;// 智力 private int strength;// 力量 private int agility;// 敏捷 private double crit;// 暴击率 private double evade;// 闪避率 private double skil;// 技能发动几率 public int victory = 0;// 胜场 public static String[] npc = { "董世豪", "王林飞", "封鹏", "白念钊", "杨其帅", "郭世森", "巩慧鑫", "刘超", "吕正茂", "焦震", "尹延磊", "班巍", "朱士峻", "郇丽君" }; // 构造函数 public Pet(String name, String sex) { super(); this.name = name; this.age = 1; this.sex = sex; this.birthday = new Date(); this.healthy = 100; this.hungry = 80; this.happy = 60; } public Pet() { } // 打印信息 public void printInfo() { System.out.println( "宠物名称: " + name + ", 今天" + age + "岁, " + "宠物性别: " + sex + ", 宠物生日: " + DateFormat.convert(birthday)); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("健康值: " + healthy); System.out.println("饥饿度: " + hungry); System.out.println("心情值: " + happy); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("生命值: " + Hp); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("力量值: " + strength); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("敏捷值: " + agility); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("智力值: " + intelligence); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("暴击率: " + crit); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("闪避率: " + evade); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("技能率: " + skil); if (healthy < 30) { System.out.println("宠物生病了, 快去吃药吧 !"); } if (hungry > 80) { System.out.println("宝宝饿的不行了, 我要吃大餐 !"); } if (happy < 30) { System.out.println("无聊空虚寂寞冷, 快来陪我玩 !"); } } // 对战信息 public void fightinfor() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("我的宠物: " + Main.a + Main.b + Main.c); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("生命值: " + Hp); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("力量值: " + strength); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("暴击率: " + crit); } // 性别影响的属性 public void sex() { if (this.sex.equalsIgnoreCase("男")) { this.setStrength(this.getStrength() + 10); } else if (this.sex.equals("女")) { this.setAgility(this.getAgility() + 5); this.setStrength(this.getStrength() + 5); } else if (this.sex.equals("妖")) { this.setStrength(this.getStrength() + 10); this.setAgility(this.getAgility() + 10); } } // 随机生成属性 public void attribute() { double x, y; x = Math.random() / 2; y = Math.random() / 2; this.setAgility((int) (Math.random() * 10)); this.setHp((int) (Math.random() * 250)); this.setCrit(x); this.setEvade((double) (Math.random() / 3)); this.setIntelligence((int) (Math.random() * 10)); this.setStrength((int) (Math.random() * 10)); this.setSkil(y); } // 吃饭 public void eatFood() { System.out.println("与" + this.getName() + "一起吃饭, 心情值 + 2, 饥饿度 - 10"); this.setHappy(this.getHappy() + 2); this.setHungry(this.getHungry() - 10); } // 吃药 public void eatMidical() { System.out.println("喂" + this.getName() + "吃药, 心情值 - 5, 饥饿度 + 10, 健康值 + 50,生命值+70"); this.setHappy(this.getHappy() - 5); this.setHungry(this.getHungry() + 10); this.setHealthy(this.getHealthy() + 50); this.setHp(this.getHp() + 100); } // 玩耍 public void play() { System.out.println("与" + this.getName() + "玩耍, 心情值 + 10, 饥饿度 + 5, 健康值 + 5"); this.setHappy(this.getHappy() + 10); this.setHungry(this.getHungry() + 5); this.setHealthy(this.getHealthy() + 5); } // 竞技场 public void fight() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("今天新的一轮竞技场即将开始,让我们介绍一下双方选手!"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("一阵清风吹过。.登上擂台的是:" + this.getName()); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } JingjichangYanyuan i = new JingjichangYanyuan(); i.attribute1(); num = (int) Math.floor(Math.random() * 13); System.out.println("看起来霸气十足的实力派送分选手:" + i.getName()); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("让我们花5秒钟对比一下双方的实力"); this.fightinfor(); i.printInfo1(); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("双方选手就位,战斗开始!"); do { if (this.getAgility() >= i.getAgility()) { lock1 = false; if (lock) { System.out.println(this.getName() + "率先发起攻击。"); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } double iE = Math.random(); double tC = Math.random(); // 暴击攻击 if (tC <= this.getCrit() && iE > i.getEvade()) { int damage = (int) ((this.getStrength() * 3 * (this.getHealthy() / 100) - (this.getHungry() / 10) + (this.getHappy() / 10)) + Math.random() * 50); System.out.println(this.getName() + "打出了暴击!!!!对" + i.getName() + "造成了" + damage + "点伤害"); i.setHp(i.getHp() - damage); } // 技能攻击 else if ((this.getCrit() + this.getSkil()) >= tC && tC > this.getCrit() && iE > i.getEvade()) { int damage1 = (int) ((this.getStrength() * (this.getHealthy() / 100) - (this.getHungry() / 10) + (this.getHappy() / 10)) + Math.random() * 10); System.out.println(this.getName() + "对" + i.getName() + "造成了" + this.skill(damage1) + "点伤害"); i.setHp(i.getHp() - this.skill(damage1)); } // 普通攻击 else if ((this.getCrit() + this.getSkil()) < tC && iE > i.getEvade()) { int damage2 = (int) ((this.getStrength() * (this.getHealthy() / 100) - (this.getHungry() / 10) + (this.getHappy() / 10)) + Math.random() * 10); System.out.println(this.getName() + "对" + i.getName() + "造成了" + damage2 + "点伤害"); i.setHp(i.getHp() - damage2); } // 闪避 else { System.out.println(this.getName() + "发动狂暴攻击,但是" + i.getName() + "发动了王者走位,轻松躲过所有伤害。"); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(this.getName() + "剩余生命值" + this.getHp()); System.out.println(i.getName() + "剩余生命值" + i.getHp()); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } if (this.getHp() <= 0) { System.out.println(this.getName() + "竟然连演员都干不过,回家种地吧!"); System.out.println(this.getName() + "大发神威,完成了1穿" + this.victory + "的壮举。"); break; } else if (i.getHp() <= 0) { System.out.println(this.getName() + "历尽千辛万苦,击败了强大的" + i.getName()); this.victory += 1; this.fight(); break; } System.out.println(i.getName() + "奋起反击。"); double iE1 = Math.random(); double tC1 = Math.random(); if (tC1 <= i.getCrit() && iE1 > this.getEvade()) { int damage3 = (int) ((i.getStrength() * (4) + 9) + Math.random() * 50); System.out.println(i.getName() + "打出了暴击!!!!对" + this.getName() + "造成了" + damage3 + "点伤害"); this.setHp(this.getHp() - damage3); } else if ((i.getCrit() + i.getSkil()) >= tC1 && tC1 > i.getCrit() && iE1 > this.getEvade()) { int damage4 = (int) ((i.getStrength() * (0.9) + 9) + Math.random() * 10); num = (int) Math.floor(Math.random() * 13); if (num == 0) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:演员的愤怒!造成了" + i.skill13(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill13(damage4)); } if (num == 1) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*天狗吞日造成了" + i.skill1(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill1(damage4)); } if (num == 2) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*大闹天宫造成了" + i.skill2(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill2(damage4)); } if (num == 3) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*虎啸山林,力量增加"); this.setHp(this.getHp() - i.skill3(damage4)); } if (num == 4) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*神佑复生"); this.setHp(this.getHp() - i.skill4(damage4)); } if (num == 5) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*神龙降世造成了" + i.skill5(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill5(damage4)); } if (num == 6) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*草泥马造成了" + i.skill6(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill6(damage4)); } if (num == 7) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*混世魔王,增加暴击率"); this.setHp(this.getHp() - i.skill7(damage4)); } if (num == 8) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*死亡缠绕造成了" + i.skill8(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill8(damage4)); } if (num == 9) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*偷梁换柱造成了" + i.skill9(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill9(damage4)); } if (num == 10) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*月宫玉兔恢复70生命值"); this.setHp(this.getHp() - i.skill10(damage4)); } if (num == 11) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*咩造成了" + i.skill11(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill11(damage4)); } if (num == 12) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*天篷之威造成了" + i.skill12(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill12(damage4)); } } else if ((i.getCrit() + i.getSkil()) < tC1 && iE1 > this.getEvade()) { int damage5 = (int) ((i.getStrength() * (0.9) + 9) + Math.random() * 10); System.out.println(i.getName() + "对" + this.getName() + "造成了" + damage5 + "点伤害"); this.setHp(this.getHp() - damage5); } else { System.out.println(i.getName() + "发动狂暴攻击,但是" + this.getName() + "发动了王者走位,轻松躲过所有伤害。"); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(this.getName() + "剩余生命值" + this.getHp()); System.out.println(i.getName() + "剩余生命值" + i.getHp()); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } if (this.getHp() <= 0) { System.out.println(this.getName() + "竟然连演员都干不过,回家种地吧!"); System.out.println(this.getName() + "大发神威,完成了1穿" + this.victory + "的壮举。"); break; } else if (i.getHp() <= 0) { System.out.println(this.getName() + "历尽千辛万苦,击败了强大的竞技场演员!"); this.victory += 1; this.fight(); break; } lock = false; } else { lock = false; if (lock1) { System.out.println(i.getName() + "率先发起攻击。"); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } double iE1 = Math.random(); double tC1 = Math.random(); if (tC1 <= i.getCrit() && iE1 > this.getEvade()) { int damage3 = (int) ((i.getStrength() * (4) + 9) + Math.random() * 50); System.out.println(i.getName() + "打出了暴击!!!!对" + this.getName() + "造成了" + damage3 + "点伤害"); this.setHp(this.getHp() - damage3); } else if ((i.getCrit() + i.getSkil()) >= tC1 && tC1 > i.getCrit() && iE1 > this.getEvade()) { int damage4 = (int) ((i.getStrength() * (0.9) + 9) + Math.random() * 10); num = (int) Math.floor(Math.random() * 13); if (num == 0) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:演员的愤怒!造成了" + i.skill13(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill13(damage4)); } if (num == 1) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*天狗吞日造成了" + i.skill1(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill1(damage4)); } if (num == 2) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*大闹天宫造成了" + i.skill2(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill2(damage4)); } if (num == 3) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*虎啸山林,力量增加"); this.setHp(this.getHp() - i.skill3(damage4)); } if (num == 4) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*神佑复生"); this.setHp(this.getHp() - i.skill4(damage4)); } if (num == 5) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*神龙降世造成了" + i.skill5(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill5(damage4)); } if (num == 6) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*草泥马造成了" + i.skill6(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill6(damage4)); } if (num == 7) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*混世魔王,增加暴击率"); this.setHp(this.getHp() - i.skill7(damage4)); } if (num == 8) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*死亡缠绕造成了" + i.skill8(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill8(damage4)); } if (num == 9) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*偷梁换柱造成了" + i.skill9(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill9(damage4)); } if (num == 10) { System.out.println(i.getName() + "对" + this.getName() + "%%%发动技能:真*月宫玉兔恢复70生命值"); this.setHp(this.getHp() - i.skill10(damage4)); } if (num == 11) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*咩造成了" + i.skill11(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill11(damage4)); } if (num == 12) { System.out.println( i.getName() + "对" + this.getName() + "%%%发动技能:真*天篷之威造成了" + i.skill12(damage4) + "点伤害"); this.setHp(this.getHp() - i.skill12(damage4)); } } else if ((i.getCrit() + i.getSkil()) < tC1 && iE1 > this.getEvade()) { int damage5 = (int) ((i.getStrength() * (0.9) + 9) + Math.random() * 10); System.out.println(i.getName() + "对" + this.getName() + "造成了" + damage5 + "点伤害"); this.setHp(this.getHp() - damage5); } else { System.out.println(i.getName() + "发动狂暴攻击,但是" + this.getName() + "发动了王者走位,轻松躲过所有伤害。"); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(this.getName() + "剩余生命值" + this.getHp()); System.out.println(i.getName() + "剩余生命值" + i.getHp()); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } if (this.getHp() <= 0) { System.out.println(this.getName() + "竟然连演员都干不过,回家种地吧!"); System.out.println(this.getName() + "大发神威,完成了1穿" + this.victory + "的壮举。"); break; } else if (i.getHp() <= 0) { System.out.println(this.getName() + "历尽千辛万苦,击败了强大的竞技场演员!"); this.victory += 1; this.fight(); break; } System.out.println(this.getName() + "奋起反击。"); double iE = Math.random(); double tC = Math.random(); if (tC <= this.getCrit() && iE > i.getEvade()) { int damage = (int) ((this.getStrength() * 3 * (this.getHealthy() / 100) - (this.getHungry() / 10) + (this.getHappy() / 10)) + Math.random() * 50); System.out.println(this.getName() + "打出了暴击!!!!对" + i.getName() + "造成了" + damage + "点伤害"); i.setHp(i.getHp() - damage); } else if ((this.getCrit() + this.getSkil()) >= tC && tC > this.getCrit() && iE > i.getEvade()) { int damage1 = (int) ((this.getStrength() * (this.getHealthy() / 100) - (this.getHungry() / 10) + (this.getHappy() / 10)) + Math.random() * 10); System.out.println(this.getName() + "对" + i.getName() + "造成了" + this.skill(damage1) + "点伤害"); i.setHp(i.getHp() - this.skill(damage1)); } else if ((this.getCrit() + this.getSkil()) < tC && iE > i.getEvade()) { int damage2 = (int) ((this.getStrength() * (this.getHealthy() / 100) - (this.getHungry() / 10) + (this.getHappy() / 10)) + Math.random() * 10); System.out.println(this.getName() + "对" + i.getName() + "造成了" + damage2 + "点伤害"); i.setHp(i.getHp() - damage2); } else { System.out.println(this.getName() + "发动狂暴攻击,但是" + i.getName() + "发动了王者走位,轻松躲过所有伤害。"); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } if (this.getHp() <= 0) { System.out.println(this.getName() + "竟然连演员都干不过,回家种地吧!"); System.out.println(this.getName() + "大发神威,完成了1穿" + this.victory + "的壮举。"); break; } else if (i.getHp() <= 0) { System.out.println(this.getName() + "历尽千辛万苦,击败了强大的竞技场演员!"); this.victory += 1; this.fight(); break; } System.out.println(this.getName() + "剩余生命值" + this.getHp()); System.out.println(i.getName() + "剩余生命值" + i.getHp()); lock1 = false; } } while (this.getHp() > 0 && i.getHp() > 0); } // 技能 public int skill(int damage) { return damage; } /** * 可以改变的属性 * * @return */ public String getName() { return name; } public int getHp() { return Hp; } public void setHp(int hp) { this.Hp = hp; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getPinzhong() { return pinzhong; } public void setPinzhong(String pinzhong) { this.pinzhong = pinzhong; } public int getHealthy() { return healthy; } public void setHealthy(int healthy) { this.healthy = healthy; } public int getHungry() { return hungry; } public void setHungry(int hungry) { this.hungry = hungry; } public void setName(String name) { this.name = name; } public String getName1() { return name1; } public void setName1(String name1) { this.name1 = name1; } public int getHappy() { return happy; } public void setHappy(int happy) { this.happy = happy; } public int getIntelligence() { return intelligence; } public void setIntelligence(int intelligence) { this.intelligence = intelligence; } public int getStrength() { return strength; } public void setStrength(int strength) { this.strength = strength; } public int getAgility() { return agility; } public void setAgility(int agility) { this.agility = agility; } public double getCrit() { return crit; } public void setCrit(double crit) { this.crit = crit; } public double getEvade() { return evade; } public void setEvade(double evade) { this.evade = evade; } public double getSkil() { return skil; } public void setSkil(double skil) { this.skil = skil; } }