玩家角色Actor在玩游戏时通常会选用不同的装备Equip获得能力,在spring中完成Equip装备->Actor的注入
2012-08-15 21:52
260 查看
玩家角色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
所有装备具有以下属性:
//装备名称
//装备类型<头盔、铠甲>等
//速度增效
//攻击增效
//防御增效
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
相关文章推荐
- Spring零配置通过注解实现Bean依赖注入总结<转>
- spring注解注入:<context:component-scan>详解
- spring property标签中的 ref属性和ref 标签有什么不同? 如下:<property name="a" ref="b" />
- Struts+Spring+Hibernate处理Lob(Blob,Clob)-->sessionFactory中注入 org.springframework.jdbc.support.lob.Def
- spring容器DI依赖注入对象<三>
- spring注解注入:&lt;context:component-scan&gt;详解
- Spring类的自动注入<context:component-scan base-package="com.**.dao" />
- spring注解或依赖注入模拟MVC结构案例<五>
- Spring的配置文件applicationContext.xml中的 <context:component-scan base-package="com.orm" />
- Spring配置项<context:annotation-config/>解释说明
- 从头认识Spring-1.16 SpEl对集合的操作(1)-建立集合以及訪问集合的元素,以<util:list/>为例
- AfxGetApp->GetMainWnd()与AfxGetMainWnd的不同
- 获得<S:select>中的listValue
- Spring中<ref local=""/>与<ref bean=""/>区别
- vector<char*>和vector<string>的不同
- [ --> C Language<-- ] 不同的C编译器差别够大的
- Spring中<mvc:annotation-driven />的作用
- db_owner角色注入直接获得系统权限
- Spring---->Bean的作用域
- Spring配置项<context:annotation-config/>解释说明