玩家角色Actor在玩游戏时通常会选用不同的装备Equip获得能力,现在有以下装备:
所有装备具有以下属性:
//装备名称
//装备类型<头盔、铠甲>等
//速度增效
//攻击增效
//防御增效
1.战靴
布靴、皮靴
2.铠甲
铜甲、银甲、黄金甲
3.头盔
青铜盔、黄金盔
4.坐骑
良驹、赤兔
在spring中完成Equip装备->Actor的注入
//Equip类
package com.slin.pojo;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Equip implements Serializable,IEquip {
//装备名称
//装备类型<头盔、铠甲>等
//速度增效
//攻击增效
//防御增效
private String ename;
private String type;
private int espeed;
private int ekit;
private int edefense;
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public int getEspeed() {
return espeed;
}
public void setEspeed(int espeed) {
this.espeed = espeed;
}
public int getEkit() {
return ekit;
}
public void setEkit(int ekit) {
this.ekit = ekit;
}
public int getEdefense() {
return edefense;
}
public void setEdefense(int edefense) {
this.edefense = edefense;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
//Actor类
package com.slin.pojo;
import java.io.Serializable;
public class Actor implements Serializable {
private Equip ZhanXue;
private Equip KaiJia;
private Equip TouHui;
private Equip ZuoQi;
public Equip getZhanXue() {
return ZhanXue;
}
public void setZhanXue(Equip zhanXue) {
ZhanXue = zhanXue;
}
public Equip getKaiJia() {
return KaiJia;
}
public void setKaiJia(Equip kaiJia) {
KaiJia = kaiJia;
}
public Equip getTouHui() {
return TouHui;
}
public void setTouHui(Equip touHui) {
TouHui = touHui;
}
public Equip getZuoQi() {
return ZuoQi;
}
public void setZuoQi(Equip zuoQi) {
ZuoQi = zuoQi;
}
}
//applicationContext.xml///
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="actor1" class="com.slin.pojo.Actor">
<property name="kaiJia" ref="kj3"/>
<property name="touHui" ref="th1"/>
<property name="zhanXue" ref="zx2"/>
<property name="zuoQi" ref="zq1"/>
</bean>
<bean id="actor2" class="com.slin.pojo.Actor">
<property name="kaiJia" ref="kj2"/>
<property name="touHui" ref="th2"/>
<property name="zhanXue" ref="zx1"/>
<property name="zuoQi" ref="zq1"/>
</bean>
<!-- 战靴 -->
<bean id="zx1" class="com.slin.pojo.Equip">
<property name="ename" value="布靴" />
<property name="type" value="战靴" />
<property name="espeed" value="1000" />
<property name="ekit" value="2000" />
<property name="edefense" value="3000" />
</bean>
<bean id="zx2" class="com.slin.pojo.Equip">
<property name="ename" value="皮靴" />
<property name="type" value="战靴" />
<property name="espeed" value="2000" />
<property name="ekit" value="1000" />
<property name="edefense" value="2500" />
</bean>
<!-- 铠甲 -->
<bean id="kj1" class="com.slin.pojo.Equip">
<property name="ename" value="铜甲" />
<property name="type" value="铠甲" />
<property name="espeed" value="4000" />
<property name="ekit" value="4000" />
<property name="edefense" value="3000" />
</bean>
<bean id="kj2" class="com.slin.pojo.Equip">
<property name="ename" value="银甲" />
<property name="type" value="铠甲" />
<property name="espeed" value="2000" />
<property name="ekit" value="5000" />
<property name="edefense" value="1000" />
</bean>
<bean id="kj3" class="com.slin.pojo.Equip">
<property name="ename" value="黄金甲" />
<property name="type" value="铠甲" />
<property name="espeed" value="7000" />
<property name="ekit" value="1000" />
<property name="edefense" value="1000" />
</bean>
<!-- 头盔 -->
<bean id="th1" class="com.slin.pojo.Equip">
<property name="ename" value="青铜盔" />
<property name="type" value="头盔" />
<property name="espeed" value="2000" />
<property name="ekit" value="2000" />
<property name="edefense" value="2000" />
</bean>
<bean id="th2" class="com.slin.pojo.Equip">
<property name="ename" value="黄金盔" />
<property name="type" value="头盔" />
<property name="espeed" value="6000" />
<property name="ekit" value="2000" />
<property name="edefense" value="1500" />
</bean>
<!-- 坐骑 -->
<bean id="zq1" class="com.slin.pojo.Equip">
<property name="ename" value="良驹" />
<property name="type" value="坐骑" />
<property name="espeed" value="11000" />
<property name="ekit" value="5000" />
<property name="edefense" value="3000" />
</bean>
<bean id="zq2" class="com.slin.pojo.Equip">
<property name="ename" value="赤兔" />
<property name="type" value="坐骑" />
<property name="espeed" value="3000" />
<property name="ekit" value="4000" />
<property name="edefense" value="2000" />
</bean>
</beans>
//测试类///
package com.slin.pojo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class T {
static ApplicationContext cxt = new ClassPathXmlApplicationContext(
"applicationContext.xml");
public static void main(String[] args) {
Actor actor1 = (Actor) cxt.getBean("actor1");
System.out.println("名字:" + actor1.getZhanXue().getEname() + " 类型:"
+ actor1.getZhanXue().getType() + " 攻击:"
+ actor1.getZhanXue().getEkit() + " 速度:"
+ actor1.getZhanXue().getEspeed() + " 防御:"
+ actor1.getZhanXue().getEdefense());
}
}
//结果///
名字:皮靴 类型:战靴 攻击:1000 速度:2000 防御:2500