Files
javaSE-0419/day11/src/com/inmind/class_member_var09/Demo07.java

47 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.class_member_var09;
/*
类作为成员变量类型(hero,weapon,armor)
案例:英雄角色,获取武器,获取防御装,闯关
*/
public class Demo07 {
public static void main(String[] args) {
//创建英雄角色对象
Hero hero = new Hero();
hero.setName("德玛西亚");
//打怪,掉落武器
Weapon weapon = new Weapon("屠龙刀", 999);
hero.setWeapon(weapon);
//打怪,掉落防具
Armor armor = new Armor("复活甲", 888);
hero.setArmor(armor);
//打boss
hero.attack();
//boss回击
hero.protect();
System.out.println("BOSS掉落了一本技能书");
Skill skill = new Skill() {
@Override
public void outSkill() {
System.out.println("施放野火燎原技能团队伤害9999");
}
@Override
public String getName() {
return "野火燎原";
}
};
//装备技能
hero.setSkill(skill);
//英雄获取自己的技能,并施放
hero.getSkill().outSkill();
System.out.println("游戏结束");
}
}