Java dota?

据此java写一个级简版的dota =.= (轻喷)
规划类图:

第二榔头和秀芬又吵了

图片 1

因特别粗略,熬夜打dota2,没失去讲授

Dota.png

秀芬一个丁及了千篇一律上午之征

Unit.class:

便不理二槌了

package com.dota;

public abstract class Unit {

    public String name;
    private int HP = 0;
    private int ATK = 1;
    private int armor = 0;
    private boolean isLive = true;

    public void getHurt(int harm){
        this.HP -= (harm-armor);
        if(HP <= 0)
            isLive = false;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean isLive) {
        this.isLive = isLive;
    }

    abstract void attack(Unit target);

    abstract void beAttack(Unit attacker);

    public int getHP() {
        return HP;
    }

    public void setHP(int hP) {
        HP = hP;
    }

    public int getATK() {
        return ATK;
    }

    public void setATK(int aTK) {
        ATK = aTK;
    }

    public int getArmor() {
        return armor;
    }

    public void setArmor(int armor) {
        this.armor = armor;
    }

    public String getName() {
        return name;
    }

}

任凭二锤子发信息多么求饶说好话,都大

Tower.class:

亚槌在宿舍叹了口气

package com.dota;

public class Tower extends Unit {

    private boolean isDefense = false;

    Tower(String name, int HP, int ATK, int armor){
        this.name = name;
        this.setHP(HP);
        this.setATK(ATK);
        this.setArmor(armor);
    }

    void attack(Unit target) {

    }

    public boolean isDefense() {
        return isDefense;
    }

    public void setDefense(boolean isDefense) {
        this.isDefense = isDefense;
    }

    void defense(){
        isDefense = true;
        System.out.println("开启塔防");
    }

    @Override
    void beAttack(Unit attacker) {

    }

}

脚也不由自主的走下后门的网吧

Creature.class:

亲手而情不自禁的开拓了steam

package com.dota;

public abstract class Creature extends Unit {

    private int MP = 0;
    private int speed = 300;

    public int getMP() {
        return MP;
    }
    public void setMP(int mP) {
        MP = mP;
    }
    public int getSpeed() {
        return speed;
    }
    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void move(Point p){
        System.out.println("移动到"+p.toString());
    }
}

“何以解忧,唯有dota”

Hero.class

不知不觉又一个夜机

package com.dota;

import java.util.Random;

public class Hero extends Creature {

    private Skills[] skills = new Skills[4];

    public Skills[] getSkills() {
        return skills;
    }

    public void setSkills(Skills[] skills) {
        this.skills = skills;
    }

    public Hero(String name, int hp, int atk, int armor, int mp, Skills[] skills){
        this.name = name;
        this.setHP(hp);
        this.setATK(atk);
        this.setArmor(armor);
        this.setMP(mp);
        this.skills = skills;
    }


    void attack(Unit target) {
        int temp = new Random().nextInt(100);
        if(temp < 30){
            System.out.println("⊙_⊙ !!,"+ this.name +"打出了一下 Mis");
        }else{
            target.beAttack(this);
        }
    }

    @Override
    void beAttack(Unit attacker) {
        int temp = new Random().nextInt(100);
        if(temp < 30){
            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            System.out.println("致!命!一!击!"+ attacker.name +"攻击"+ this.name +",造成了"+ this.getATK()*2 +"点>>*爆炸*<<伤害 ");
            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            getHurt(this.getATK()*2);
        }else{
            System.out.println(attacker.name +"正在攻击"+ getName() +",造成了"+ attacker.getATK() +"点伤害");
            getHurt(this.getATK());
        }
    }

}

不解,这夜秀芬给他从了多少电话

Point.class

天亮了

package com.dota;

public class Point {

    public int x, y;

    public String toString(){
        return "坐标("+ x +","+ y +")"; 
    }

    public double getDistance(Point p){
        double d = Math.pow((x - p.x), 2) + Math.pow((y - p.y), 2);
        return Math.sqrt(d);
    }
}

次锤子放下手中油腻的鼠标

Skills.class

揉揉困乏的眼眸

package com.dota;

import java.util.Timer;
import java.util.TimerTask;

public class Skills{

    public String skillName;
    public int costMP = 0, spellTime = 0, harm = 0, CD = 0;


    public Skills(String skillName, int costMP, int spellTime, int harm, int cD) {
        super();
        this.skillName = skillName;
        this.costMP = costMP;
        this.spellTime = spellTime;
        this.harm = harm;
        CD = cD;
    }

    public void use(Hero h){
//      new Timer().schedule(new TimerTask() {
//          public void run() {
//              System.out.println("消耗了"+ costMP +"点魔法值,"+"对"+ h.name +"使用了"+ skillName +",造成了"+ harm +"点伤害");
//          }
//      }, spellTime * 1000);
        System.out.println("消耗了"+ costMP +"点魔法值,"+"对"+ h.name +"使用了"+ skillName +",造成了"+ harm +"点伤害");
        h.getHurt(harm);
    }

}

顺便整理了瞬间发型

写以末端:

当实现一个dota是未可能的,主要是为巩固一下java面向对象的学识,一些概念的强化理解,自己动手写确实是极端管用之门道

掉宿舍的中途

见卖豆腐脑的,想着马拉松没吃了,吃一碗热热的豆腐脑回去睡觉

“老板,一碗,多加辣椒油”

“没问题”

因为在小板凳上,二榔头感到眼前基本上矣一个人口

抬头一扣,竟然是秀芬

“你怎么在当时?”

秀芬傲娇的未遂了转发,扬起手中的饭盒

“昨晚莫搭电话我哪怕理解你失去上网了,本来想请好豆腐脑给您送去,没悟出你出去了,好了,快夸我,再哄哄我”

“宝贝~你真好”

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website