94 lines
2.2 KiB
Java
94 lines
2.2 KiB
Java
package com.inmind.class_interface04;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
//英雄角色,获取武器,获取防御装
|
|
public class Hero {
|
|
private String name;
|
|
private Weapon weapon;//武器
|
|
private Armor armor;//防御装
|
|
private ArrayList<Weapon> weapons = new ArrayList<>();//武器背包
|
|
//技能作为属性
|
|
private Skill skill;
|
|
|
|
|
|
public Hero() {
|
|
}
|
|
|
|
public Hero(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public Hero(String name, Weapon weapon, Armor armor) {
|
|
this.name = name;
|
|
this.weapon = weapon;
|
|
this.armor = armor;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public Weapon getWeapon() {
|
|
return weapon;
|
|
}
|
|
|
|
public void setWeapon(Weapon weapon) {
|
|
this.weapon = weapon;
|
|
}
|
|
|
|
public Armor getArmor() {
|
|
return armor;
|
|
}
|
|
|
|
public void setArmor(Armor armor) {
|
|
this.armor = armor;
|
|
}
|
|
|
|
public ArrayList<Weapon> getWeapons() {
|
|
return weapons;
|
|
}
|
|
|
|
public void setWeapons(ArrayList<Weapon> weapons) {
|
|
this.weapons = weapons;
|
|
}
|
|
|
|
public Skill getSkill() {
|
|
return skill;
|
|
}
|
|
|
|
public void setSkill(Skill skill) {
|
|
this.skill = skill;
|
|
}
|
|
|
|
//攻击和防御行为
|
|
public void attack(){
|
|
//哪个英雄,使用什么武器,输出了多少伤害
|
|
System.out.println(this.name + "使用" + this.weapon.getName() + "攻击,输出了" + this.weapon.getHurt() + "伤害");
|
|
}
|
|
|
|
public void defend(){
|
|
//哪个英雄,使用什么防御装,可以抵消多少伤害
|
|
System.out.println(this.name + "使用" + this.armor.getName() + "防御,抵消了" + this.armor.getProtectNum() + "伤害");
|
|
}
|
|
|
|
//展示武器背包
|
|
public void showWeapons(){
|
|
System.out.println(this.name + "的武器背包有:");
|
|
for (int i = 0; i < weapons.size(); i++) {
|
|
Weapon w = weapons.get(i);
|
|
System.out.println(w.getName()+", ");
|
|
}
|
|
}
|
|
|
|
//英雄释放技能
|
|
public void useSkill(){
|
|
System.out.println(this.name += "释放技能:");
|
|
this.skill.outSkill();
|
|
}
|
|
}
|