#文字RPG Beta 2.2

Class Main

//0 备注:对象的初始化顺序,先初始化属性,再调用构造函数
//1 使用随机数实现闪避功能
//  Math.random()获得零到一之间的Double类型随机数
//2 实现自动调试

package com.company;

public class Main {

    public static void main(String[] args) {

        Man p1=new Man("勇者","菜刀");
        Monster m1=new Monster(1);
        Monster m2=new Monster(2);
        Monster m3=new Monster(3);
        Monster m4=new Monster(4);
        int i;
        for(i=0;m1.isalive;i++){
            if(!p1.isalive)
                break;
            p1.hit(m1);
        }
        for(i=0;m2.isalive;i++){
            if(!p1.isalive)
                break;
            p1.hit(m2);
        }
        for(i=0;m3.isalive;i++){
            if(!p1.isalive)
                break;
            p1.hit(m3);
        }
        for(i=0;m4.isalive;i++){
            if(!p1.isalive)
                break;
            p1.hit(m4);
        }



        }
    }

Class Man

package com.company;


public class Man{
    String name;
    String weapon;
    int maxHP;
    int culHP;
    boolean isalive;
    int attack;
    int defend;
    int exp=0;
    int maxExp=100;
    int level=1;
    //添加敏捷属性
    int agile;
    //设置敏捷上限
    int maxHid;

    public Man(String name,String weapon){
        this.name=name;
        this.weapon=weapon;
        maxHP=400;
        culHP = 400;
        isalive =true;
        attack=30;
        defend=20;
        agile=30;
        maxHid=70;
    }

    public void hit(Monster monster){
        if(!monster.isalive) {
            return;
        }
        if(!isalive) {
            return;
        }
        System.out.println(name+"挥舞着"+weapon+"无情的制裁了"+monster.type+"。");
        monster.injured(this);
    }

    public void injured(Monster monster){
        if(hid()){
            System.out.println(name+"轻巧的躲避了"+monster.type+"的攻击。");
            show();
            return;
        }
        int lostHP;
        int lostBase=5;
        lostHP=monster.attack-this.defend;
        if(lostHP<=0){
            culHP-=lostBase;
        }else{
            culHP-=lostHP+lostBase;
        }
        if(culHP<=0){
            dead();
            return;
        }
        if(!isalive) {
            return;
        }
        show();
    }

    public void dead(){
        isalive=false;
        System.out.println("###################系统提示###################:"+"\n"+name+"已经牺牲了。"+"\n");
    }

    public void show(){
        System.out.println("###################系统提示###################:"+"\n"+"伟大的"+name+"当前生命值为"+culHP+"/"+maxHP
                +"点生命值"+",攻击力为"+attack+",防御力为"+defend+",等级为"+level+",敏捷为"+agile+",闪躲几率为"+agile*maxHid/100+
                "%,经验值为"+exp+"/"+maxExp+"。"+"\n");
    }

    public void upLevel(){
        if(exp>=maxExp){
            level++;
            exp=exp-maxExp;
            maxExp+=level*50;
            attack+=10;
            defend+=5;
            maxHP+=30*level;
            culHP=maxHP;
            agile+=2;
            System.out.println("###################系统提示###################:"+"\n"+name+"升级了,当前等级为"+level+"。"+"\n");
        }
    }

    //添加闪避函数
    public boolean hid(){
        int sucRate=agile*maxHid/100;
        int Rate=randomnum(1,100);
        return sucRate>Rate;
    }

    //随机数产生器
    public int randomnum(int start,int end){
        int rannum;
        rannum=(int)(Math.random()*(end-start)+start);
        return rannum;
    }
}

Class monster

package com.company;

class Monster{
    String type;
    String way;
    int culHP;
    boolean isalive;
    int attack;
    int defend;
    int getExp;
    //添加敏捷属性
    int agile;


    public Monster(int mt){
        isalive=true;
        if(mt==1){
            type="地狱灵犬";
            way="灵巧地撕咬着";
            culHP=40;
            attack=10;
            defend=10;
            getExp=35;
            agile=50;
        }else if(mt==2){
            type="地狱法师";
            way="召唤出地狱亡灵攻击了";
            culHP=30;
            attack=25;
            defend=5;
            getExp=50;
            agile=25;
        }else  if(mt==3){
            type="地狱火";
            way="身旁的火焰灼伤了";
            culHP=60;
            attack=5;
            defend=25;
            getExp=80;
            agile=20;
        }else if(mt==4){
            type="BOSS";
            way="聚集了邪恶力量包裹着";
            culHP=350;
            attack=40;
            defend=25;
            getExp=150;
            agile=22;
        }


    }

    public void kill(Man man){
        if(!man.isalive) {
            return;
        }
        if(!isalive) {
            return;
        }
        System.out.println(type+way+man.name+"。");
        man.injured(this);
    }

    public void injured(Man man){
        if(hid()){
            System.out.println(type+"轻巧的躲避了"+man.name+"的攻击。");
            kill(man);
            show();
            return;
        }
        int lostHP;
        int lostBase=1;
        lostHP=man.attack-this.defend;
        if(lostHP<=0){
            culHP-=lostBase;
        }else{
            culHP-=lostHP+lostBase;
        }
        if(culHP<=0){
            dead(man);
            return;
        }
        if(!isalive) {
            return;
        }
        show();
        System.out.println(type+"发起了反击!");
        kill(man);
    }

    public void dead(Man man){
        isalive=false;
        man.exp+=getExp;
        System.out.println("###################系统提示###################:"+"\n"+type+"已经被干掉了。"+"\n");
        man.upLevel();
        man.show();
    }

    public void show(){
        System.out.println("###################系统提示###################:"+"\n"+type+"还剩下"+culHP+"点生命值"
                +",攻击力为"+attack+",防御力为"+defend+"。"+"\n");
    }

    //添加闪避函数
    public boolean hid(){
        int Rate=randomnum(1,100);
        return agile>Rate;
    }

    //随机数产生器
    public int randomnum(int start,int end){
        int rannum;
        rannum=(int)(Math.random()*(end-start)+start);
        return rannum;
    }

}


你可能感兴趣的:(#文字RPG Beta 2.2)