部分游戏角色代码
package com.lovo.homework;
public class Role {
//属性
private String name;
private int level;
private int attackValue;
private int defendValue;
private Weapon myWeapon;
private Armor myArmor;
//行为--方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getAttackValue() {
return attackValue;
}
public void setAttackValue(int attackValue) {
this.attackValue = attackValue;
}
public int getDefendValue() {
return defendValue;
}
public void setDefendValue(int defendValue) {
this.defendValue = defendValue;
}
public Weapon getMyWeapon() {
return myWeapon;
}
public void setMyWeapon(Weapon myWeapon) {
if(myWeapon == null){
//代表传入一把空武器
if(this.myWeapon != null){
this.attackValue -= this.myWeapon.getAttackValue();
}
}else{
//代表出入一把新武器
if(this.myWeapon != null){
//代表已经装备一把老武器
this.attackValue -= this.myWeapon.getAttackValue();
}
this.attackValue += myWeapon.getAttackValue();
}
this.myWeapon = myWeapon;
}
public Armor getMyArmor() {
return myArmor;
}
public void setMyArmor(Armor myArmor) {
if(myArmor == null){
//传入空防具
if(this.myArmor != null){
this.defendValue -= this.myArmor.getDefendValue();
}
}else{
if(this.myArmor != null){
this.defendValue -= this.myArmor.getDefendValue();
}
this.defendValue += myArmor.getDefendValue();
}
this.myArmor = myArmor;
}
//业务行为
public void attack(){
System.out.println("普通攻击!黑虎掏心!!");
if(this.myWeapon != null){
this.myWeapon.specialAttack();
}
System.out.println("输出攻击力:" + this.attackValue);
}
public void defend(){
System.out.println("普通防御!泰山举鼎!");
if(this.myArmor != null){
this.myArmor.specialDefend();
}
System.out.println("提供防御力:" + this.defendValue);
}
}