diff --git a/day11/src/com/inmind/reference05/Armor.java b/day11/src/com/inmind/reference05/Armor.java new file mode 100644 index 0000000..22d7e0f --- /dev/null +++ b/day11/src/com/inmind/reference05/Armor.java @@ -0,0 +1,27 @@ +package com.inmind.reference05; +//装备类 +public class Armor { + private String name;//防具名称 + private int protectNum;//防御值 + + public Armor(String name, int protectNum) { + this.name = name; + this.protectNum = protectNum; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getProtectNum() { + return protectNum; + } + + public void setProtectNum(int protectNum) { + this.protectNum = protectNum; + } +} diff --git a/day11/src/com/inmind/reference05/Demo07.java b/day11/src/com/inmind/reference05/Demo07.java new file mode 100644 index 0000000..928f02e --- /dev/null +++ b/day11/src/com/inmind/reference05/Demo07.java @@ -0,0 +1,7 @@ +package com.inmind.reference05; +/* +类作为成员变量类型(hero,weapon,armor) +案例:英雄角色,获取武器,获取防御装,闯关,施放技能 + */ +public class Demo07 { +} diff --git a/day11/src/com/inmind/reference05/Hero.java b/day11/src/com/inmind/reference05/Hero.java new file mode 100644 index 0000000..5379f97 --- /dev/null +++ b/day11/src/com/inmind/reference05/Hero.java @@ -0,0 +1,62 @@ +package com.inmind.reference05; + +import java.util.ArrayList; + +//英雄类 +public class Hero { + private String name;//名字 + private Weapon weapon;//武器属性 自定义引用数据类型作为了成员变量 + private Armor armor;//防具属性 + + private ArrayList weapons = new ArrayList<>();//武器的背包 +// private ArrayList armors;//武器的背包 + + + public Hero() { + } + + //独有的功能 + //攻击 + public void attack(){ + //哪个英雄,使用了什么武器,输出了多少伤害 + System.out.println(this.name+"使用了"+this.weapon.getName()+"武器,输出了"+this.weapon.getHurt()+"伤害"); + } + //防御 + public void protect(){ + //哪个英雄,使用了什么防具,防御了多少伤害 + System.out.println(this.name+"使用了"+this.armor.getName()+"防具,防御了"+this.armor.getProtectNum()+"伤害"); + }; + + + 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 getWeapons() { + return weapons; + } + + public void setWeapons(ArrayList weapons) { + this.weapons = weapons; + } +} diff --git a/day11/src/com/inmind/reference05/Weapon.java b/day11/src/com/inmind/reference05/Weapon.java new file mode 100644 index 0000000..d419fc7 --- /dev/null +++ b/day11/src/com/inmind/reference05/Weapon.java @@ -0,0 +1,32 @@ +package com.inmind.reference05; +//武器类 +public class Weapon { + //名称 + private String name; + //伤害值 + private int hurt; + + public Weapon() { + } + + public Weapon(String name, int hurt) { + this.name = name; + this.hurt = hurt; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getHurt() { + return hurt; + } + + public void setHurt(int hurt) { + this.hurt = hurt; + } +}