示例#1
0
        private static void AddSingleBuildingType(Queue <string> args)
        {
            Building.Type type;

            switch (args.Dequeue())
            {
            case "HOUSE":
                type = Building.Type.House;
                break;

            case "MINE":
                type = Building.Type.Mine;
                break;

            case "FACTORY":
                type = Building.Type.Factory;
                break;

            default:
                throw new Exception("Incorrect BuildingType Init");
            }

            switch (type)
            {
            case Building.Type.House:
                BuildingTypes.Add(
                    HouseType.Create(args, ReadNecessaryResourses(args))
                    );
                break;

            case Building.Type.Mine:
                BuildingTypes.Add(
                    MineType.Create(args, ReadNecessaryResourses(args))
                    );
                break;

            case Building.Type.Factory:
                BuildingTypes.Add(
                    FactoryType.Create(args, ReadNecessaryResourses(args))
                    );
                break;

            default:
                throw new Exception("Incorrect BuildingType Init");
            }
        }
示例#2
0
        public static BuildingType RegisBuildingType(Type entryType, XElement element)
        {
            #region Check Argument

            if (entryType == null)
            {
                throw new ArgumentNullException(nameof(entryType));
            }

            if (!typeof(Building).GetTypeInfo( ).IsAssignableFrom(entryType.GetTypeInfo( )))
            {
                throw new ArgumentException($"{nameof(entryType)} should assignable from {nameof(Building)}",
                                            nameof(entryType));
            }

            if (entryType.GetTypeInfo( ).GetCustomAttributes(typeof(BuildingAttribute), false).FirstOrDefault( )
                == null)
            {
                throw new ArgumentException($"{nameof(entryType)} should have atribute {nameof(BuildingAttribute)}",
                                            nameof(entryType));
            }

            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            if (element.Name != nameof(BuildingType))
            {
                throw new ArgumentException($"{nameof(element)} should perform a building type", nameof(element));
            }

            if (BuildingTypes.Any(type => type.EntryType == entryType))
            {
                throw new InvalidOperationException($"{nameof(entryType)} have regised");
            }

            #endregion

            BuildingType buildingType = new BuildingType(entryType, element);

            BuildingTypes.Add(buildingType);
            RegisType(buildingType);

            return(buildingType);
        }