java类的混搭,

装备名称: 格林达族之辉
装备类型: 头盔
+32 每秒生命恢复
+35% 爆击伤害
+12.5% 爆击率
+61% 生命球恢复
未激活任何四件套效果时,每个非套装装备提高30%造成的伤害

package game;

public enum EEquip {
    头盔,
    项链,
    胸甲,
    护肩,
    护腿,
    靯,
    手套,
    戒指,
    武器,
    副手;
}
package game;


import java.util.Map;
import java.util.TreeMap;
public class Equip{
    TreeMap<String,String> atts = new TreeMap<>();
    EEquip type;
    String name;
    Gain gain;

    public Equip(EEquip type,String name) {
        this.type=type;
        this.name=name;
    }

    public Equip(EEquip type,String name,Gain gain) {
        this(type,name);
        this.gain=gain;
    }

    public EEquip getType(){
        return type;
    }
    public void setAtts(String key,String val){
        atts.put(key,val);
    }
    public String getAttrs(String key){
        return atts.get(key);
    }

    @Override
    public String toString() {
        String str = "装备名称: "+name+ "\n";
        if(type==EEquip.头盔)
            str+="装备类型: 头盔\n";
        for(Map.Entry<String,String> entry:atts.entrySet()){
            str+=entry.getValue()+" "+entry.getKey()+"\n";
        }
        str+=gain.toString();
        str+="\n";
        return str;
    }
}
package game;

public class Gain {
    String describe;
    public Gain(String describe){
        this.describe=describe;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    @Override
    public String toString() {
        return describe;
    }
}
package game;

public class Main {
    public static void main(String[] args) {
        Gain gain= new Gain("未激活任何四件套效果时,每个非套装装备提高30%造成的伤害");
        Equip equip= new Equip(EEquip.头盔,"格林达族之辉",gain);
        equip.setAtts("爆击率","+12.5%");
        equip.setAtts("爆击伤害","+35%");
        equip.setAtts("每秒生命恢复","+32");
        equip.setAtts("生命球恢复","+61%");
        System.out.println(equip);

    }
}

上一篇:【MPU6050】姿态传感器 工作原理


下一篇:高效开发Maven架构设计图解/掌握项目工程自动化技巧(精通篇二)