Java實戰之王者榮耀的英雄是怎麼產生的?

一、前期準備

我們要在IDEA上創建一個新的項目,創建好一個項目後,我們需要創建4個包,分別是英雄包,裝備包,銘文包,野怪包,皮膚包
然後我們就可以一個一個的實現這些功能瞭。

在這裡插入圖片描述

二、實現我的英雄夢!

2.1 英雄基本屬性實現

package Hero;

//英雄的基本屬性
public class Hero {
    public String  name; //英雄的名字
    public String type; //英雄的職業
    public int blood; //英雄的基本血量
    public int phyattack; //英雄的基本物理攻擊
    public int Magicattavk; //英雄的基本法術攻擊
    public int phyfangyu; //英雄的基礎防禦
    public int attavknum; //普通傷害的值
    public int move; //移動速度
    public int money; //經濟


    public Hero(String name, String type, int blood, int phyattack, int magicattavk, int phyfangyu,int attavknum,int move,int money) {
        this.name = name;
        this.type = type;
        this.blood = blood;
        this.phyattack = phyattack;
        this.Magicattavk = magicattavk;
        this.phyfangyu = phyfangyu;
        this.attavknum= attavknum;
        this.move= move;
        this.money= money;
    }

    public String  getName() {
        return name;
    }

    public String getType() {
        return type;
    }

    public int getBlood() {
        return blood;
    }

    public int getPhyattack() {
        return phyattack;
    }

    public int getMagicattavk() {
        return Magicattavk;
    }

    public int getPhyfangyu() {
        return phyfangyu;
    }

    public int getAttavknum() {
        return attavknum;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public void setPhyattack(int phyattack) {
        this.phyattack = phyattack;
    }

    public void setMagicattavk(int magicattavk) {
        Magicattavk = magicattavk;
    }

    public void setPhyfangyu(int phyfangyu) {
        this.phyfangyu = phyfangyu;
    }

    public void setAttavknum(int attavknum) {
        this.attavknum = attavknum;
    }

    //受到普通攻擊
    public  int  bnormalAttack(int attavknum){
        if(this.phyfangyu-this.attavknum<=0){
            int res = this.phyfangyu-this.attavknum;
            return  this.blood+res;
        }
        return blood-this.attavknum;
    }
    //普通攻擊
    public  int  znormalAttack(){
        if(this.type=="射手"||this.type=="戰士"||this.type=="刺客"){
            this.attavknum+=phyattack;
        }
        if(this.type=="法師"){
            this.attavknum+=Magicattavk;
        }
       return attavknum;
    }
}

2.2 裝備包

裝備太多瞭,我主要寫一些我平時比較喜歡的幾個裝備,有興趣的盆友可以自己練習多寫幾個
鞋子

package zhuangbei;
//抵抗之靴
/**
 * 效果:減低敵方的攻擊,也就是增加自己的物防
 */

public class Shoe {
    public  String name = "抵抗之靴";
    public  int phyattack=200;
    public  int mckattack=0;
    public  int move = 200;//英雄移動速度+200;

    public Shoe() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPhyattack() {
        return phyattack;
    }

    public void setPhyattack(int phyattack) {
        this.phyattack = phyattack;
    }

    public int getMckattack() {
        return mckattack;
    }

    public void setMckattack(int mckattack) {
        this.mckattack = mckattack;
    }

    public int getMove() {
        return move;
    }

    public void setMove(int move) {
        this.move = move;
    }
}

反甲

package zhuangbei;
//反甲
public class Fajia {
    public  String name = "反甲";
    public  int phyattack = 40;
    public  int phyfanyu = 420;
    public  double fashang = 0.2; //冷卻時間

    public int getPhyattack() {
        return phyattack;
    }

    public void setPhyattack(int phyattack) {
        this.phyattack = phyattack;
    }

    public int getPhyfanyu() {
        return phyfanyu;
    }

    public void setPhyfanyu(int phyfanyu) {
        this.phyfanyu = phyfanyu;
    }

    public double getFashang() {
        return fashang;
    }

    public void setFashang(double fashang) {
        this.fashang = fashang;
    }
}

暗影戰斧

package zhuangbei;
//暗影戰斧
/*
*
* */
public class Anyinzhanfu {
    public  String name = "暗影戰斧";
    public int phyattack = 85; //加物理攻擊85
    public int blood = 500;   //生命值加500
    public int cool = 15;    //冷卻縮減15

    public int getPhyattack() {
        return phyattack;
    }

    public void setPhyattack(int phyattack) {
        this.phyattack = phyattack;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public int getCool() {
        return cool;
    }

    public void setCool(int cool) {
        this.cool = cool;
    }
}

三、野怪實現

我主要寫瞭野豬,小鳥,河蟹,小兵的類

野豬

package yeguai;

public class Pig {
    public int num = 80;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}

小鳥

package yeguai;

public class Bird {
    public int num = 100;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}

河蟹

package yeguai;

public class Heixie {
    public  int num = 150;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}

小兵

package yeguai;

public class Xiaobing {
    public  int num = 150;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}

四、開始遊戲

import Hero.Hero;
import yeguai.Bird;
import yeguai.Heixie;
import yeguai.Pig;
import yeguai.Xiaobing;
import zhuangbei.Anyinzhanfu;
import zhuangbei.Fajia;
import zhuangbei.Shoe;

public class Deom {
    public static void main(String[] args) {
         Hero yase = new Hero("亞瑟","戰士",1000,200,0,500,200,50,0);

         System.out.println(yase.name);
        System.out.println(yase.money);
        //開始發育(先產生野怪,小兵,河蟹的實例化對象)
        Pig pig1 = new Pig();
        Bird Bird = new Bird();
        Xiaobing xiaobing = new Xiaobing();
        Heixie heixie = new Heixie();
        for(int i =0;i<=10;i++){  //打瞭10輪
            yase.money+=pig1.getNum()+Bird.getNum()+xiaobing.getNum()+heixie.getNum();
        }
        System.out.println(yase.name+"的經濟現在是"+yase.money);

        //開始創建裝備類
        System.out.println("購買裝備前:");
        System.out.println(yase.name+"當前的屬性"+"生命值:"+yase.blood+"物理攻擊:"+yase.phyattack+"法術攻擊:"+yase.Magicattavk+
                " 物理防禦:"+yase.phyfangyu+"移動速度:"+yase.move);

        if(yase.money>=200){
            Shoe shoe = new Shoe();
            System.out.println(yase.name+"購買瞭"+shoe.name);
            yase.phyfangyu+=shoe.getPhyattack();
            yase.move+=shoe.getMove();
            yase.money=yase.money-200;
        }
        if(yase.money>=1200){
            Fajia fajia = new Fajia();
            System.out.println(yase.name+"購買瞭"+fajia .name);
            yase.phyattack+=fajia.getPhyattack(); //攻擊力+
            yase.phyfangyu+=fajia.getPhyfanyu();  //防禦力+
            yase.money=yase.money-1200;
        }
        if(yase.money>=2000){
            Anyinzhanfu anyinzhanfu = new Anyinzhanfu();
            System.out.println(yase.name+"購買瞭"+anyinzhanfu.name);
            yase.phyattack+=anyinzhanfu.getPhyattack(); //攻擊力+
            yase.blood+=anyinzhanfu.getBlood();  //生命力+
            yase.money=yase.money-2000;
        }
        System.out.println("購買裝備後:");
        System.out.println(yase.name+"當前的屬性"+"生命值:"+yase.blood+"物理攻擊:"+yase.phyattack+"法術攻擊:"+yase.Magicattavk+
                " 物理防禦:"+yase.phyfangyu+"移動速度:"+yase.move);
    }
}

在這裡插入圖片描述

我基本可以實現簡單的創建一個英雄,實現刷野怪,購買裝備的簡單操作,後序我將實現英雄的三個技能和銘文的實現。

到此這篇關於python實戰之王者榮耀的英雄是怎麼產生的?的文章就介紹到這瞭,更多相關Python王者榮耀內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: