因为我最近在学抽象工厂,自己写了一个,不知道算不算是抽象工厂模式,麻烦大家看一下,谢谢using System;
using System.Collections.Generic;
using System.Text;namespace GameRole
{
   public enum RoleType
    {
        knight,//武士
        robber,//盗贼
        rabbi,//法师
        Taoist//道士
    };   public enum WeaponType
    {
        sword ,//剑
        bayonet,//刺刀
         wand,//法杖
        symbol//符   
    };    public abstract class Weapon
    {
        
        protected int execution;
        protected int witchcraft = 0;
        public abstract void SetExecution(int execution);
        public int Execution
        {
            get { return execution; }
        }
        private WeaponType weapontype;        public WeaponType Weapontype
        {
            get { return weapontype; }
            set { weapontype = value; }
        }
    }    public abstract class Role
    {
        protected string _name = null;
        protected RoleType _roleType;
        protected WeaponType _weaponType;
        protected Weapon _weapon;
        protected int _execution;        public abstract void setWeapon(Weapon weapon);        public abstract string GetInfromation();
          }    #region 各种角色    public class kinght:Role
    {
        public kinght(string name,int excution)
        {
            this._name = name;
            this._execution = excution;
            this._roleType = RoleType.knight;
        }
        public override void setWeapon(Weapon weapon)
        {
            this._execution = this._execution + weapon.Execution;
            this._weaponType = weapon.Weapontype;
            
        }        public override string GetInfromation()
        {
            return "名字:"+this._name+"  角色类型:"+this._roleType.ToString()+"  用的是:"+this._weaponType.ToString()+"  杀伤力为:"+this._execution.ToString();
        }
    }    public class robber:Role
    {        public robber(string name,int excution)
        {
            this._name = name;
            this._execution = excution;
            this._roleType = RoleType.robber;
        }
        public override void setWeapon(Weapon weapon)
        {
            this._execution = this._execution + weapon.Execution;
        }        public override string GetInfromation()
        {
            return "名字:" + this._name + "  角色类型:" + this._roleType.ToString() + "  用的是:" + this._weaponType.ToString() + "  杀伤力为:" + this._execution.ToString();
        }
    }    public class rabbi : Role
    {
        public rabbi(string name, int excution)
        {
            this._name = name;
            this._execution = excution;
            this._roleType = RoleType.rabbi;
        }
        public override void setWeapon(Weapon weapon)
        {
            this._execution = this._execution + weapon.Execution;
        }
        public override string GetInfromation()
        {
            return "名字:" + this._name + "  角色类型:" + this._roleType.ToString() + "  用的是:" + this._weaponType.ToString() + "  杀伤力为:" + this._execution.ToString();
        }
    }    public class Taoist : Role
    {
        public Taoist(string name, int excution)
        {
            this._name = name;
            this._execution = excution;
            this._roleType = RoleType.Taoist;
        }
        public override void setWeapon(Weapon weapon)
        {
            this._execution = this._execution + weapon.Execution;
        }
        public override string GetInfromation()
        {
            return "名字:" + this._name + "  角色类型:" + this._roleType.ToString() + "  用的是:" + this._weaponType.ToString() + "  杀伤力为:" + this._execution.ToString();
        }
    }    #endregion    #region 各种武器
    public class Sword:Weapon
    {
        public Sword()
        {
            this.execution = 10+this.witchcraft;
            this.Weapontype = WeaponType.sword;
        }
        public override void SetExecution(int execution)
        {
            this.execution = execution;
        }
    }    public class Bayonet:Weapon
    {
       
        public Bayonet()
        {
            this.execution = 7+this.witchcraft;
            this.Weapontype = WeaponType.bayonet;
        }
        public override void SetExecution(int execution)
        {
            this.execution = execution;
        }
    }    public class Wand:Weapon
    {
        public Wand()
        {
            this.witchcraft = 3;
            this.execution = 5 + this.witchcraft;
            this.Weapontype = WeaponType.wand;
        }
        public override void SetExecution(int execution)
        {
            this.execution = execution;
        }
    }    public class Symbol:Weapon
    {
        public Symbol()
        {
            this.witchcraft = 2;
            this.execution = 6 + this.witchcraft;
            this.Weapontype = WeaponType.symbol;
        }
        public override void SetExecution(int execution)
        {
            this.execution = execution;
        }
    }    #endregion    public abstract class GameRoleFactory
    {
       
        public abstract Role CreateGameRole(string name,int excution);
        public abstract Weapon CreateWeapon();
    }    public class KinghtFactory : GameRoleFactory
    {
        
        public override Role CreateGameRole(string name,int excution)
        {
            return new kinght(name, excution);
        }
        public override Weapon CreateWeapon()
        {
            return new Sword();
        }
    }
    public class RobberFactory : GameRoleFactory
    {
        
        public override Role CreateGameRole(string name, int excution)
        {
            return new robber(name, excution);
        }        public override Weapon CreateWeapon()
        {
            return new Bayonet();
        }
    }
    public class TaoistFactory:GameRoleFactory
    {
        
        public override Role CreateGameRole(string name, int excution)
        {
            return new Taoist(name, excution);
        }        public override Weapon CreateWeapon()
        {
            return new Symbol();
        }
    }
    public class RabbiFactory:GameRoleFactory
    {
       
        public override Role CreateGameRole(string name, int excution)
        {
            return new rabbi(name, excution);
        }        public override Weapon CreateWeapon()
        {
            return new Wand();
        }
    }    public class BeginMakeGameRole
    {
        Role _role;
        Weapon _weapon;
        public BeginMakeGameRole(GameRoleFactory factory,string name,int excution)
        {
            this._role = factory.CreateGameRole(name,excution);
            this._weapon = factory.CreateWeapon();
            SetUp();
        }
        public void SetUp()
        {
            this._role.setWeapon(this._weapon);
        }
        public string GetNewRoleInformation()
        {
            return this._role.GetInfromation();
        }
    }    }