任务要求:

  • 定义一个描述战斗单位的类,此类必须包含以下成员变量:名称,生命值,攻击力,防御力,命中率。此类还必须包含以下成员方法:遭到攻击时的处理函数,阵亡时的处理函数。请自行设计生命值,攻击力,防御力,命中率之间的关系。请自行设计各处理函数被执行时的提示信息。
  • 此游戏中存在多种战斗角色,每种角色都是由要求1所定义的类派生出来的子类。每种角色类除了继承自父类的成员变量和函数之外,可以增加一些成员变量和成员函数,例如增加防御这一动作的处理函数。
    战斗角色例:战士,生命高,普通攻击敌人,攻击力中,防御力高
    骑兵,生命中,普通攻击敌人,攻击力高,防御力高
    法师,生命极低,法术攻击敌人,攻击力极高,防御力低
  • 此游戏采用回合制,人对人或人对电脑。每个角色对象依次顺序被使用,游戏操作者通过选菜单的方式操作角色对象的攻击、攻击谁、防御等等动作。游戏以某方全体阵亡而结束。
  • 游戏必须具有完备的提示信息,例如每个回合都要提示轮到那方的那名角色对象行动,每个回合菜单之前都必须显示敌我双方每一个角色对象的各种参数值,并且每个回合必须重新刷新显示屏幕上的提示内容等。

任务的理解:

难点主要在于如何实现回合制以及当玩家选择角色时如何创建对象,起初我的思想是通过if判断语句来判断玩家的输入然后根据输入的信息进行创建对象,但是我发现在if语句中创建的对象不能在if语句之外进行调用,所以只好采用笨的办法,采用switch语句来判断输入的信息然后再进行创建对象,就是说3个角色在在代码中需要创建18个对象,通过重复的语句实现功能。回合制的实现是通过在for语句中嵌套一个if语句判断for循环中的变量i是奇数还是偶数,奇数则玩家1操作,偶数则玩家2操作,以此来实现回合制的功能。

代码部分:

import java.io.IOException;             //导入异常处理类
import java.util.Scanner;               //导入扫描类
import java.util.Random;                //导入随机类
public class task1_2challenge{          //创建主类String name;                        //定义成员变量名字int healthValue;                    //定义成员变量生命值int aggressivity;                   //定义成员变量攻击力int defense;                        //定义成员变量防御力//double hitRate;//hitRate=0.8;public static int beAttacked(int healthValue,int aggressivity,int defense){//定义一个攻击时造成伤害的函数double damageValue;             //定义变量伤害值Random d=new Random();          //创建一个随机数的对象int e=d.nextInt(5);             //生成一个0-5之间的随机数并赋值给edouble jianmian;                //定义一个变量存放减免伤害的百分数double defenses=(double)defense;//把防御力转化为小数型的变量double aggressivitys=(double)aggressivity;//把攻击力转化为小数型的变量jianmian=(defenses/(defenses+100));       //计算减免伤害的百分比damageValue=aggressivitys*(1-jianmian)+e;//造成伤害的计算公式int damageValues=(int)damageValue;//将伤害值强制转为整数        System.out.println("漂亮的一击,造成了"+damageValues+"点伤害");//输出一段文字描述造成的伤害return damageValues;            //返回伤害值}public static int hitRatio(){       //定义一个命中率的方法Random r=new Random();          //实例化一个随机数对象int a=r.nextInt(100);           //生成一个0-100之间的随机数并赋值给aint b;                          //定义一个整数b作为方法的返回值if(a<=80){                      //判断随机数a的大小b=1;                        //小于等于80时b=1}else{                          //b=0;                        //大于80时b=0}return b;                       //返回b的值}public static boolean fallInBattle(int healthValue){   //定义阵亡的处理函数if(healthValue<=0){                                //如果生命值低于0System.out.println("You are die,game is over!");//则输出一段文字return false;                                   //并返回false}else{return true;                                    //否则返回true}}public task1_2challenge(){                              //构造函数}public static void main(String[] args)throws IOException, InterruptedException {//main主函数System.out.println("请玩家选择角色\n1:战士    2:射手    3:法师");             //输出一段信息Scanner s1=new Scanner(System.in);                  //创建一个扫描器对象s1String a;                                           //定义字符串a                        a=s1.nextLine();                                    //将键盘获取的值赋予aScanner s2=new Scanner(System.in);                  //创建一个扫描器s2String b;                                           //定义字符串bb=s2.nextLine();                                    //将扫面值赋予bString c=a+b;                                       //定义c=a+bswitch(c){                                          //switch语句case "11":                                          //都选择战士时的处理语句System.out.println("战士VS战士");                //输出文字Combatant combatant1=new Combatant();           //创建一个子类Combatant的对象Combatant combatant2=new Combatant();           //再创建一个子类Combatant的对象for(int i=1;i<=50;i++){                         //for循环语句对回合制进行循环操作int d=hitRatio();                               //将命中率函数的返回值赋给dThread.currentThread().sleep(1000 * 2);         //调用线程,休眠2000毫秒cls();                                          //调用清屏方法//输出人物的信息System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+combatant1.healthValue+"  攻击力为:"+combatant1.aggressivity+"  防御力为:"+combatant1.defense+"\n玩家2的生命值为:"+combatant2.healthValue+"  攻击力为:"+combatant2.aggressivity+"  防御力为:"+combatant2.defense);boolean p1=fallInBattle(combatant1.healthValue);//调用死亡处理函数判断玩家1的情况boolean p2=fallInBattle(combatant2.healthValue);//玩家2if((i%2)==0){                                   //判断回合数if(p1&&p2){                                 //玩家1和玩家2都没死的情况下System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");//输出文字Scanner k1=new Scanner(System.in);//创建扫描器String k11=k1.nextLine();  //把输入的值赋给k11switch(k11){ case "a": // 如果是a,调用这个方法if(d==1){int damageValues= beAttacked(combatant1.healthValue,combatant2.aggressivity,combatant1.defense);//确定伤害combatant1.healthValue=combatant1.healthValue - damageValues;//计算生命值}else{System.out.println("未命中目标");}break;case "b":combatant2.defense=Combatant.shield(combatant2.defense);//技能方法,赋值System.out.println("防御力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");//对象死亡,结束循环break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(combatant2.healthValue,combatant1.aggressivity,combatant2.defense);combatant2.healthValue=combatant2.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":combatant1.defense=Combatant.shield(combatant1.defense);System.out.println("防御力增加");break;case "c":break;}                  }else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "12":System.out.println("战士VS射手");Combatant combatant3=new Combatant();Shooter shooter1=new Shooter();for(int i=1;i<=50;i++){ int d=hitRatio();Thread.currentThread().sleep(1000 * 2);cls();           System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+combatant3.healthValue+"  攻击力为:"+combatant3.aggressivity+"  防御力为:"+combatant3.defense+"\n玩家2的生命值为:"+shooter1.healthValue+"  攻击力为:"+shooter1.aggressivity+"  防御力为:"+shooter1.defense);boolean p1=fallInBattle(combatant3.healthValue);boolean p2=fallInBattle(shooter1.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(combatant3.healthValue,shooter1.aggressivity,combatant3.defense);combatant3.healthValue=combatant3.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":shooter1.aggressivity=Shooter.criticalStrike(shooter1.aggressivity);System.out.println("攻击力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(shooter1.healthValue,combatant3.aggressivity,shooter1.defense);shooter1.healthValue=shooter1.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":combatant3.defense=Combatant.shield(combatant3.defense);System.out.println("防御力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "13":System.out.println("战士VS法师");Combatant combatant4=new Combatant();DeathRite deathrite1=new DeathRite();for(int i=1;i<=50;i++){ int d=hitRatio(); Thread.currentThread().sleep(1000 * 2);cls();          System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+combatant4.healthValue+"  攻击力为:"+combatant4.aggressivity+"  防御力为:"+combatant4.defense+"\n玩家2的生命值为:"+deathrite1.healthValue+"  攻击力为:"+deathrite1.aggressivity+"  防御力为:"+deathrite1.defense);boolean p1=fallInBattle(combatant4.healthValue);boolean p2=fallInBattle(deathrite1.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(combatant4.healthValue,deathrite1.aggressivity,combatant4.defense);combatant4.healthValue=combatant4.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":deathrite1.healthValue=DeathRite.returnedBlood(deathrite1.healthValue);System.out.println("加血");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(deathrite1.healthValue,combatant4.aggressivity,deathrite1.defense);deathrite1.healthValue=deathrite1.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":combatant4.defense=Combatant.shield(combatant4.defense);System.out.println("防御力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "21":System.out.println("射手VS战士");Shooter shooter2=new Shooter();Combatant combatant5=new Combatant();for(int i=1;i<=50;i++){ int d=hitRatio();Thread.currentThread().sleep(1000 * 2);cls();           System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+shooter2.healthValue+"  攻击力为:"+shooter2.aggressivity+"  防御力为:"+shooter2.defense+"\n玩家2的生命值为:"+combatant5.healthValue+"  攻击力为:"+combatant5.aggressivity+"  防御力为:"+combatant5.defense);boolean p1=fallInBattle(shooter2.healthValue);boolean p2=fallInBattle(combatant5.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(shooter2.healthValue,combatant5.aggressivity,shooter2.defense);shooter2.healthValue=shooter2.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":combatant5.defense=Combatant.shield(combatant5.defense);System.out.println("防御力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(combatant5.healthValue,shooter2.aggressivity,combatant5.defense);combatant5.healthValue=combatant5.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":shooter2.aggressivity=Shooter.criticalStrike(shooter2.aggressivity);System.out.println("攻击力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "22":System.out.println("射手VS射手");Shooter shooter3=new Shooter();Shooter shooter4=new Shooter();for(int i=1;i<=50;i++){ int d=hitRatio();Thread.currentThread().sleep(1000 * 2);cls();           System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+shooter3.healthValue+"  攻击力为:"+shooter3.aggressivity+"  防御力为:"+shooter3.defense+"\n玩家2的生命值为:"+shooter4.healthValue+"  攻击力为:"+shooter4.aggressivity+"  防御力为:"+shooter4.defense);boolean p1=fallInBattle(shooter3.healthValue);boolean p2=fallInBattle(shooter4.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(shooter3.healthValue,shooter4.aggressivity,shooter3.defense);shooter3.healthValue=shooter3.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":shooter4.aggressivity=Shooter.criticalStrike(shooter4.aggressivity);System.out.println("攻击力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(shooter4.healthValue,shooter3.aggressivity,shooter4.defense);shooter4.healthValue=shooter4.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":shooter3.aggressivity=Shooter.criticalStrike(shooter3.aggressivity);System.out.println("攻击力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "23":System.out.println("射手VS法师");Shooter shooter5=new Shooter();DeathRite deathrite2=new DeathRite();for(int i=1;i<=50;i++){ int d=hitRatio();Thread.currentThread().sleep(1000 * 2);cls();           System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+shooter5.healthValue+"  攻击力为:"+shooter5.aggressivity+"  防御力为:"+shooter5.defense+"\n玩家2的生命值为:"+deathrite2.healthValue+"  攻击力为:"+deathrite2.aggressivity+"  防御力为:"+deathrite2.defense);boolean p1=fallInBattle(shooter5.healthValue);boolean p2=fallInBattle(deathrite2.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(shooter5.healthValue,deathrite2.aggressivity,shooter5.defense);shooter5.healthValue=shooter5.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":deathrite2.healthValue=DeathRite.returnedBlood(deathrite2.healthValue);System.out.println("加血");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(deathrite2.healthValue,shooter5.aggressivity,deathrite2.defense);deathrite2.healthValue=deathrite2.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":shooter5.aggressivity=Shooter.criticalStrike(shooter5.aggressivity);System.out.println("攻击力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "31":System.out.println("法师VS战士");DeathRite deathrite3=new DeathRite();Combatant combatant6=new Combatant();for(int i=1;i<=50;i++){ int d=hitRatio();Thread.currentThread().sleep(1000 * 2);cls();           System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+deathrite3.healthValue+"  攻击力为:"+deathrite3.aggressivity+"  防御力为:"+deathrite3.defense+"\n玩家2的生命值为:"+combatant6.healthValue+"  攻击力为:"+combatant6.aggressivity+"  防御力为:"+combatant6.defense);boolean p1=fallInBattle(deathrite3.healthValue);boolean p2=fallInBattle(combatant6.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(deathrite3.healthValue,combatant6.aggressivity,deathrite3.defense);deathrite3.healthValue=deathrite3.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":combatant6.defense=Combatant.shield(combatant6.defense);System.out.println("防御力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(combatant6.healthValue,deathrite3.aggressivity,combatant6.defense);combatant6.healthValue=combatant6.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":deathrite3.healthValue=DeathRite.returnedBlood(deathrite3.healthValue);System.out.println("加血");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "32":System.out.println("法师VS射手");DeathRite deathrite4=new DeathRite();Shooter shooter6=new Shooter();for(int i=1;i<=50;i++){ int d=hitRatio();Thread.currentThread().sleep(1000 * 2);cls();           System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+deathrite4.healthValue+"  攻击力为:"+deathrite4.aggressivity+"  防御力为:"+deathrite4.defense+"\n玩家2的生命值为:"+shooter6.healthValue+"  攻击力为:"+shooter6.aggressivity+"  防御力为:"+shooter6.defense);boolean p1=fallInBattle(deathrite4.healthValue);boolean p2=fallInBattle(shooter6.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(deathrite4.healthValue,shooter6.aggressivity,deathrite4.defense);deathrite4.healthValue=deathrite4.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":shooter6.aggressivity=Shooter.criticalStrike(shooter6.aggressivity);System.out.println("攻击力增加");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(shooter6.healthValue,deathrite4.aggressivity,shooter6.defense);shooter6.healthValue=shooter6.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":deathrite4.healthValue=DeathRite.returnedBlood(deathrite4.healthValue);System.out.println("加血");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;case "33":System.out.println("法师VS法师");DeathRite deathrite5=new DeathRite();DeathRite deathrite6=new DeathRite();for(int i=1;i<=50;i++){ int d=hitRatio();Thread.currentThread().sleep(1000 * 2);cls();           System.out.println("第"+(i+1)/2+"回合:\n玩家1的生命值为:"+deathrite5.healthValue+"  攻击力为:"+deathrite5.aggressivity+"  防御力为:"+deathrite5.defense+"\n玩家2的生命值为:"+deathrite6.healthValue+"  攻击力为:"+deathrite6.aggressivity+"  防御力为:"+deathrite6.defense);boolean p1=fallInBattle(deathrite5.healthValue);boolean p2=fallInBattle(deathrite6.healthValue);if((i%2)==0){if(p1&&p2){System.out.println("请玩家2选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(deathrite5.healthValue,deathrite6.aggressivity,deathrite5.defense);deathrite5.healthValue=deathrite5.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":deathrite6.healthValue=DeathRite.returnedBlood(deathrite6.healthValue);System.out.println("加血");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}else{if(p1&&p2){System.out.println("请玩家1选择:a、普通攻击   b、释放技能   c、跳过本回合");Scanner k1=new Scanner(System.in);String k11=k1.nextLine();switch(k11){case "a":if(d==1){int damageValues= beAttacked(deathrite6.healthValue,deathrite5.aggressivity,deathrite6.defense);deathrite6.healthValue=deathrite6.healthValue - damageValues;}else{System.out.println("未命中目标");}break;case "b":deathrite5.healthValue=DeathRite.returnedBlood(deathrite5.healthValue);System.out.println("加血");break;case "c":break;}}else{if(p1){System.out.println("玩家2阵亡");break;}else{System.out.println("玩家1阵亡");break;}}}}break;}       }public static void cls() throws IOException, InterruptedException{//控制台清屏方法new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); }
}
class Combatant extends task1_2challenge{           //子类战士public Combatant(){                             //构造方法name="战士";healthValue=580;                            //赋值aggressivity=63;defense=36;}public static int shield(int defense){          //技能方法defense=defense+25;                         //防御值加25return defense;                             //返回防御值}
}
class Shooter extends task1_2challenge{             //子类射手public Shooter(){                               //构造方法name="射手";                                //healthValue=515;                            //赋值aggressivity=60;defense=23;}public static int criticalStrike(int aggressivity){ //技能方法aggressivity=aggressivity+20;                //攻击力加20return aggressivity;                         //返回攻击力}
}
class DeathRite extends task1_2challenge{            //子类法师public DeathRite(){                              //构造方法name="法师";                                  //赋值healthValue=524;aggressivity=50;defense=19;}public static int returnedBlood(int healthValue){ //技能方法healthValue=healthValue+70;                   //血量加70return healthValue;                           //返回生命值}
}

运行结果:





总结:

通过此次任务,学会如何灵活的使用循环和条件语句以及类和对象的使用,方法的调用,继承以及数据类型的转换,还有一些基础的编程思想。

基本任务1.2Java面向对象程序(挑战任务)相关推荐

  1. 电大java语言与面向对象程序设计基础_6406Java语言与面向对象程序设计基础A卷...

    6406Java语言与面向对象程序设计基础A卷 试卷编号:6406 座位号 浙江广播电视大学2006年春季学期开放教育专科期末考试 <Java语言与面向对象程序设计基础>试题 2006年7 ...

  2. C++ 面向对象程序三大特性之 继承

    目录 继承的概念 继承的定义及使用 继承方式和访问权限 基类和派生类对象的赋值转换 继承中的各成员的作用域 派生类的默认成员函数 构造函数 拷贝构造 赋值运算符重载函数 析构函数 继承与友元 继承与静 ...

  3. java面向对象程序练习_5本面向经验丰富的程序员的高级Java书籍

    java面向对象程序练习 Sometimes back I wrote an article for Best Core Java Books for beginners, today I am sh ...

  4. 面向对象程序有哪些优点呢?

    转自: 面向对象程序有哪些优点呢? 面向对象简介: 面向对象(Object Oriented)是软件开发方法,一种编程范式.面向对象的概念和应用已超越了程序设计和软件开发,扩展到如数据库系统.交互式界 ...

  5. Java面向对象程序思想

    Java第六天 面向对象程序思想 一.面向过程   分析出解决问题的步骤,然后用函数(Function )或者程序过程(Poceduere )把这些步骤步一步地实现,程序执行的过程就是按一定顺序调用函 ...

  6. 【SCL】博图SCL语言回顾和第一个面向对象程序

    西门子SCL语言回顾复习和编写第1个面向对象程序 (形参:形参指的是指令上标记该指令要使用的数据位置的标识符;简单来说就是只有数据类型,没有实际的地址,在调用时可以写入). (实参:实参指的是包含指令 ...

  7. C#面向对象程序设计课程实验四:实验名称:C#面向对象程序设计基础

    C#面向对象程序设计课程实验四:实验名称:C#面向对象程序设计基础 实验内容:C#面向对象程序设计基础 一.实验目的 二.实验环境 三.实验内容与步骤 3.1.1.实验内容 3.1.2.实验步骤 3. ...

  8. 小赵老师课堂开课了 !天道酬勤,相信自己学到就是赚到,一起来学习吧--- java面向对象程序设计基础的知识!!!!

    大家!我是下一个pony,今天我又来更新帖子了~ 今天我们讲解的是java面向对象程序设计基础的知识~我们从以下几个方面来进行简单的讲解: ============================== ...

  9. java类名可以是数字吗_在 Java 中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或顺序各不相同,传回的值也可以不相同。这种面向对象程序特性称为( )。_学小易找答案...

    [简答题]Java 支持多继承吗 ? [单选题]以下关于继承的叙述正确的是( ). [单选题]在 Java 中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数.类型或顺序各不相同,传回的值也 ...

最新文章

  1. 自学python推荐书籍2019-2019最强Python书单!
  2. JournalNode的作用
  3. linux gdb网络调试工具,Linux--gdb调试工具
  4. python历史以及基础知识
  5. Hibernate 多表关联
  6. NVIDIA的黑科技3:VXGI体素全局光照
  7. wps python 自动化_请教下 Python 高手,如何用 Python 自动化操作 Excel?
  8. PTN OAM交互接口设计
  9. web开发excel文件上传及解析(上)
  10. 使用PageOffice---如何在模板中添加数据区域
  11. 单循环比赛赛程 java
  12. php xss漏洞扫描工具,XSS漏洞扫描器工具:XSpear
  13. VC++6.0 内存泄露调试
  14. 「PHP 是最好的语言」这个梗是怎么来的?
  15. 完美解决桌面右键一直转圈,反应卡顿问题(重点是怎样删除workfolders)
  16. 烤仔TVのCCW | 智能合约间的四种调用(下)
  17. MTK平台 SIM双卡改成单卡修改
  18. 万分之二用百分之怎么表示_万分之三怎么写?
  19. 计算机组成:cpu的功能和组成
  20. html css 3D 立体相册

热门文章

  1. 微信小程序中常见的 typeof cb == “function” cb(that.globalData.userInfo)
  2. 2D游戏引擎制作:读取XML文件 1
  3. 算法:如何在100个人中找出有且仅有的一位确诊新冠的人
  4. java8 stram并行流学习
  5. stram流 Collectors.groupingBy分组后顺序错乱问题
  6. zte手机android手机怎么刷机,中兴v956怎么刷机 中兴v956刷机方法【详细步骤】
  7. Python每日一谈|No.3
  8. 电脑必备软件---绿色PDF阅读工具福昕PDF阅读器.exe
  9. 爱奇艺2015校园招聘产品笔试题
  10. Java端字节跳动接口调用SDK包