#文字RPG Beta 2.0

Class Main

//Beta 2.0
//1 重寫了各個類
//2 運用構(gòu)造函數(shù)
//3 實現(xiàn)角色的攻擊力和防御力
//show方法增加攻擊力防御力提示
//4 增加了Monster的反擊

package com.company;

public class Main {

    public static void main(String[] args) {

        Man p1=new Man("勇者","菜刀");
        Monster m1=new Monster(4);
        p1.hit(m1);
        m1.kill(p1);

        }
    }

Class Man

package com.company;

public class Man{
    String name;
    String weapon;
    int HP;
    boolean isalive;
    //攻擊力防御力
    int attack;
    int defend;

    //構(gòu)造函數(shù)確定name,weapon
    public Man(String name,String weapon){
        this.name=name;
        this.weapon=weapon;
        HP = 100;
        isalive =true;
        attack=25;
        defend=15;
    }

    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){
        //實現(xiàn)基礎(chǔ)傷害防止被攻擊回血
        int lostHP;
        int lostBase=5;
        lostHP=monster.attack-this.defend;
        if(lostHP<=0){
            HP-=lostBase;
        }else{
            HP-=lostHP+lostBase;
        }
        System.out.println(name+":好疼!"+monster.type+"攻擊了我!");
        if(HP<=0){
            dead();
            return;
        }
        if(!isalive) {
            return;
        }
        show();
    }

    public void dead(){
        isalive=false;
        System.out.println("系統(tǒng)提示:"+name+"已經(jīng)犧牲了");
    }

    public void show(){
        System.out.println("系統(tǒng)提示:偉大的"+name+"還剩下"+HP+"點生命值"+",攻擊力為"+attack+",防御力為"+defend+"。");
    }

}

Class monster

package com.company;

class Monster{
    String type;
    int HP;
    boolean isalive;
    //攻擊力防御力
    int attack;
    int defend;


    //通過構(gòu)造函數(shù)實現(xiàn)怪獸的分級設(shè)置
    public Monster(int mt){
        isalive=true;
        if(mt==1){
            type="地獄小犬";
            HP=30;
            attack=15;
            defend=10;
        }else if(mt==2){
            type="地獄法師";
            HP=20;
            attack=25;
            defend=5;
        }else  if(mt==3){
            type="地獄火";
            HP=60;
            attack=5;
            defend=25;
        }else if(mt==4){
            type="BOSS";
            HP=50;
            attack=20;
            defend=20;
        }


    }

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

    public void injured(Man man){
        //實現(xiàn)基礎(chǔ)傷害防止被攻擊回血
        int lostHP;
        int lostBase=1;
        lostHP=man.attack-this.defend;
        if(lostHP<=0){
            HP-=lostBase;
        }else{
            HP-=lostHP+lostBase;
        }
        System.out.println(type+":Aaaa~");
        if(HP<=0){
            dead();
            return;
        }
        if(!isalive) {
            return;
        }
        //實現(xiàn)反擊
        show();
        System.out.println("系統(tǒng)提示:"+type+"發(fā)起了反擊!");
        kill(man);
    }

    public void dead(){
        isalive=false;
        System.out.println("系統(tǒng)提示:"+type+"已經(jīng)被干掉了");
    }

    public void show(){
        System.out.println("系統(tǒng)提示:"+type+"還剩下"+HP+"點生命值"+",攻擊力為"+attack+",防御力為"+defend+"。");
    }

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容