实现效果
英雄类代码
package hero;public class Hero {//静态特征String name; //姓名double aggressivity; //攻击力double defenf; //防御力double vitality; //生命力//构造方法//无参构造public Hero() {}//有参构造方法public Hero(String name, double aggressivity, double defenf, double vitality) {this.name=name;this.aggressivity=aggressivity;this.defenf=defenf;this.vitality=vitality;}//英雄信息输出void information() {System.out.println(name+"\n攻击力:"+aggressivity+"\n防御力:"+defenf+"\n生命值:"+vitality+"\n");}//盖伦普攻寒冰public double GAttick(Hero hanbing,Hero gailun) {System.out.println("盖伦使用普通攻击,攻击了寒冰\n");hanbing.vitality-=(gailun.aggressivity-hanbing.defenf);hanbing.information();return hanbing.vitality;}//寒冰普攻盖伦public double HAttick(Hero gailun,Hero hanbing) {System.out.println("寒冰使用了普通攻击,攻击了盖伦\n");gailun.vitality-=(hanbing.aggressivity-gailun.defenf);gailun.information();return gailun.vitality;}
}
英雄1
package hero;public class Hanbingtest {String q="一技能:在间隔1.5秒的时间内连续普攻三次 \n";
// System.out.println(q);String w="二技能:一次性朝前方发出多只箭,造成伤害破防敌人\n";
// System.out.println(w);String e="三技能:向前方发射一只燃烧长箭照亮视野\n前方出现了不确定因素\n";
// System.out.println(e);String r="四技能:往前方发射一只长箭,定住命中的敌人两秒\n";void skill() {System.out.println(q+w+e+r);}public double Hq(Hero gailun,Hero hanbing) {System.out.println("寒冰使用了一技能,攻击了盖伦\n"+q);gailun.vitality-=(hanbing.aggressivity*3-gailun.defenf);gailun.information();return gailun.vitality;}public double Hw(Hero gailun,Hero hanbing) {System.out.println("寒冰使用了二技能,攻击了盖伦\n"+w);gailun.vitality-=hanbing.aggressivity;gailun.information();return gailun.vitality;}public double He(Hero gailun,Hero hanbing) {System.out.println("寒冰使用了三技能\n"+e);double a=Math.random()*100;a%=10;if(a<=2) {System.out.println("长箭逐渐燃烧,并发生爆炸,对范围内的敌人造成300点真实伤害");gailun.vitality-=300;gailun.information();return gailun.vitality;}else if(a<=5) {System.out.println("长箭照亮了视野,敌方“剑豪”出现在了寒冰的身后,并发动了q技能");hanbing.vitality-=200;hanbing.information();return hanbing.vitality;}else {System.out.println("战场上出现了只蛤蟆怪");return 10000;}}public Hero Hdeid(Hero hanbing) {System.out.println("寒冰阵亡\n");hanbing.aggressivity=0;hanbing.defenf=0;hanbing.vitality=0;hanbing.information();return hanbing;}
}
英雄2
package hero;public class Gailuntest {String q="盖伦的一技能:盖伦为宝剑附加魔力,下一击攻击力额外增加20%\n";
// System.out.println(q);String w="盖伦的二技能:盖伦为自身鼓舞士气,增加自身100点生命\n";
// System.out.println(w);String e="盖伦的三技能:盖伦旋转并挥舞宝剑,对范围内敌人每秒100伤害\n";
// System.out.println(e);String r="盖伦的四技能:盖伦高举大宝剑插入敌人身体,造成400点伤害\n"+ "(斩杀血量低于400的敌人)";void skill() {System.out.println(q+w+e+r);}public double Gq(Hero hanbing,Hero gailun) {System.out.println("盖伦使用了一技能,攻击了寒冰\n"+q);hanbing.vitality-=(gailun.aggressivity*1.2-hanbing.defenf);hanbing.information();return hanbing.vitality;}public double Gw(Hero gailun) {System.out.println("盖伦使用了二技能\n"+w);gailun.vitality+=100;if(gailun.vitality>780.0) {gailun.vitality=780.0;}gailun.information();return gailun.vitality;}public double Gr(Hero hanbing,Hero gailun) {System.out.println("盖伦发动大招,锁定了寒冰\n"+r);if(hanbing.vitality<400) {hanbing.vitality=0;}else {hanbing.vitality-=(400-hanbing.defenf);}hanbing.information();return hanbing.vitality;}public Hero Gdied(Hero gailun) {System.out.println("盖伦阵亡");gailun.aggressivity=0;gailun.defenf=0;gailun.vitality=0;gailun.information();return gailun;}
}
实现类代码
package hero;public class Herotest {public static void main(String[] args) {//英雄信息Hero gailun=new Hero("盖伦",63.0,45.0,780.0);Hero hanbing=new Hero("寒冰",79,34,670);Gailuntest gailunskill=new Gailuntest();Hanbingtest hanbingskill=new Hanbingtest();gailun.information();gailunskill.skill();hanbing.information();hanbingskill.skill();hanbing.vitality=gailun.GAttick(hanbing,gailun);gailun.vitality=hanbing.HAttick(gailun,hanbing);hanbingskill.Hq(gailun, hanbing);gailunskill.Gq(hanbing, gailun);hanbingskill.Hw(gailun, hanbing);gailunskill.Gw(gailun);double a=hanbingskill.He(gailun, hanbing);if(a==10000) {System.out.println("蛤蟆怪登场,凝视着场上的两名英雄");a=Math.random()*100;if(a%2==0) {System.out.println("蛤蟆怪朝天一跃,吐出吞天炮吞噬了寒冰\n");hanbingskill.Hdeid(hanbing);}else {System.out.println("蛤蟆怪喷出熔融毒液淹没盖伦\n");gailunskill.Gdied(gailun);}}else {gailunskill.Gr(hanbing, gailun);if(hanbing.vitality>200) {System.out.println("敌方“剑豪”出现在了寒冰的身后,并发动了e、q二连");hanbingskill.Hdeid(hanbing);}else {hanbingskill.Hdeid(hanbing);}}}
}