Пример #1
0
        /// <summary>
        /// 简单工厂模式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSimple_Click(object sender, EventArgs e)
        {
            ////没有使用工厂模式时
            //Henan henan = new Henan();
            //henan.City();

            //Hubei hubei = new Hubei();
            //hubei.City();

            //Hebei hebei = new Hebei();
            //hebei.City();

            //Hunan hunan = new Hunan();
            //hunan.City();


            //简单工厂模式下
            IProvince province = SimpleFactory.CreateInstance(RaceType.Henan);

            province.City();

            Henan human = (Henan)SimpleFactory.CreateInstance(RaceType.Henan);

            human.City();
            Console.WriteLine("\r\n****************************************\r\n");

            //工厂方法模式
            IProvince henan = HenanFactory.CreateInstance();

            henan.City();

            IProvince anhui = AnhuiFactory.CreateInstance();

            anhui.City();
        }
Пример #2
0
        /// <summary>
        /// Checks with a flood fill algorithm if any sea provinces are surrounded
        /// by land provinces.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="map"></param>
        /// <returns></returns>
        private static bool CheckForSurroundedSeaProvince(IProvince start, IHexMap map)
        {
            if (!start.IsWater)
            {
                return(false);
            }

            var steps               = 10;
            var provinceStack       = new Stack <IProvince>();
            var checkedSeaProvinces = new List <IProvince>();

            provinceStack.Push(start);

            while (provinceStack.Count > 0 && steps-- > 0)
            {
                var province = provinceStack.Pop();

                if (checkedSeaProvinces.Contains(province))
                {
                    continue;
                }

                checkedSeaProvinces.Add(province);

                foreach (var neighbour in province.GetNeighbours(map))
                {
                    if (neighbour.IsWater)
                    {
                        provinceStack.Push(neighbour);
                    }
                }
            }
            return(steps > 0);
        }
Пример #3
0
 public ProfesorController(ITeacher teacher, IContactType contactType,
                           IDocumentType documentType, ICountry country, ICity city,
                           IAddressType addressType, IStatus status, IEducationType educationType,
                           ITeacherEducation teacherEducation, INationality nationality, IMatirialStatus matirialStatus, IProvince province,
                           ITeacherHiringType teacherHiringType, ITeacherFileType teacherFileType, ITeacherFile teacherFile,
                           IWebHostEnvironment hostingEnv, IConfiguration config, IContactAddress contactAddress, IContactCommunication contactCommunication, IUniversity university
                           )
 {
     _teacher              = teacher;
     _contactType          = contactType;
     _documentType         = documentType;
     _country              = country;
     _city                 = city;
     _addressType          = addressType;
     _status               = status;
     _educationType        = educationType;
     _teacherEducation     = teacherEducation;
     _nationality          = nationality;
     _matirialStatus       = matirialStatus;
     _province             = province;
     _teacherHiringType    = teacherHiringType;
     _teacherFileType      = teacherFileType;
     _teacherFile          = teacherFile;
     _hostingEnv           = hostingEnv;
     _config               = config;
     _contactAddress       = contactAddress;
     _contactCommunication = contactCommunication;
     _university           = university;
 }
Пример #4
0
 //
 // GET: /Account/
 public AccountController(IUnitOfWork uow, IAccount accountService, ICountry countryService, IProvince provinceService, ICity cityService, IComment commentService)
 {
     _accountService = accountService;
     _countryService = countryService;
     _provinceService = provinceService;
     _cityService = cityService;
     _commentService = commentService;
     _uow = uow;
 }
Пример #5
0
        public void AddProvince(IProvince province)
        {
            Provinces.Add(province);
            province.IsWater = false;
            var provinceObject = (Province)province;

            provinceObject.transform.SetParent(transform);
            province.Owner = this;
        }
Пример #6
0
        private bool TrySetNextProvince(ICountry country, IList <IProvince> regions, IHexMap map, IProvince region, out IProvince nextRegion)
        {
            var found = false;
            var tries = 20;

            nextRegion = null;
            do
            {
                var neighbours = region.GetNeighbours(map);
                _trace.Add($"Neighbours of {region}: {string.Join(", ", neighbours.Select(r => r.Name).OrderBy(n => n))}");

                if (!neighbours.Any())
                {
                    foreach (var log in _trace)
                    {
                        Debug.Log(log);
                    }
                    throw new InvalidOperationException("No neighbour found!");
                }

                var freeNeighbours    = neighbours.Where(n => regions.Contains(n)).ToList();
                var countryNeighbours = neighbours.Where(n => country.Provinces.Contains(n)).ToList();

                _trace.Add($"Remaining free provinces of {region}: {string.Join(", ", freeNeighbours.Select(r => r.Name).OrderBy(n => n))}");
                _trace.Add($"Remaining country neighbours {region}: {string.Join(", ", countryNeighbours.Select(r => r.Name).OrderBy(n => n))}");

                if (freeNeighbours.Any())
                {
                    var lastRegion     = region;
                    var neighbourIndex = _random(0, freeNeighbours.Count);
                    region         = freeNeighbours[neighbourIndex];
                    found          = true;
                    region.IsWater = false;
                    _trace.Add($"Random neighbour index: {neighbourIndex}: Free neighbour province: {region.Name} with index {neighbourIndex} and {nameof(region.IsWater)} {region.IsWater}");
                    if (region.GetNeighbours(map).Any(n => CheckForSurroundedSeaProvince(n, map)))
                    {
                        _trace.Add($"Surrounded sea province found for {region.Name}");
                        found          = false;
                        region.IsWater = true;
                        region         = lastRegion;
                    }
                }
                else
                {
                    var neighbourIndex = _random(0, countryNeighbours.Count);
                    region = countryNeighbours[neighbourIndex];
                    _trace.Add($"Random neighbour index: {neighbourIndex}: Neighbour of another province: {region.Name} with index {neighbourIndex}");
                }
                if (found)
                {
                    nextRegion = region;
                    return(true);
                }
            } while (--tries > 0);
            return(false);
        }
Пример #7
0
 public RepresentanteController(IAgent agent, IContactType contactType, IDocumentType documentType,
                                IAgentType agentType, IAddressType addressType, ICountry country, IProvince province, ICity city)
 {
     _agent        = agent;
     _contactType  = contactType;
     _documentType = documentType;
     _agentType    = agentType;
     _addressType  = addressType;
     _country      = country;
     _province     = province;
     _city         = city;
 }
 public InstitucionFomadoraController(IUniversity university,
                                      IStatus status,
                                      IAddressType addressType,
                                      ICountry country,
                                      IProvince province,
                                      ICity city)
 {
     _university  = university;
     _status      = status;
     _addressType = addressType;
     _country     = country;
     _province    = province;
     _city        = city;
 }
Пример #9
0
        public Province() : base()
        {
            if (isMultiDatabase)
            {
                base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, dicmultiDatabase[this.GetType().Name].ToString());
            }
            else
            {
                base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
            }

            baseDal.OnOperationLog += new OperationLogEventHandler(OperationLog.OnOperationLog);//如果需要记录操作日志,则实现这个事件

            dal = baseDal as IProvince;
        }
Пример #10
0
        public virtual bool Equals(IProvince obj)
        {
            if (obj == null)
            {
                return(false);
            }

            //if (Equals(ProvEname, obj.ProvEname) == false) return false;
            if (Equals(Id, obj.Id) == false)
            {
                return(false);
            }
            //if (Equals(ProvSign, obj.ProvSign) == false) return false;
            //if (Equals(ProvTname, obj.ProvTname) == false) return false;
            //if (Equals(RegId, obj.RegId) == false) return false;
            return(true);
        }
Пример #11
0
 public ProfesorController(ITeacher teacher, IContactType contactType,
                           IDocumentType documentType, ICountry country, ICity city,
                           IAddressType addressType, IStatus status, IEducationType educationType,
                           ITeacherEducation teacherEducation, INationality nationality, IMatirialStatus matirialStatus, IProvince province
                           )
 {
     _teacher          = teacher;
     _contactType      = contactType;
     _documentType     = documentType;
     _country          = country;
     _city             = city;
     _addressType      = addressType;
     _status           = status;
     _educationType    = educationType;
     _teacherEducation = teacherEducation;
     _nationality      = nationality;
     _matirialStatus   = matirialStatus;
     _province         = province;
 }
Пример #12
0
 public ProvinceController(IProvince province)
 {
     _province = province;
 }
Пример #13
0
        private void AddProvince(ICountry country, IList <IProvince> regions, IHexMap map, IProvince region, List <IProvince> redoCache)
        {
            if (region == null || (country.Provinces.Any() && !region.GetNeighbours(map).Intersect(country.Provinces).Any()))
            {
                foreach (var log in _trace)
                {
                    Debug.Log(log);
                }
                throw new InvalidOperationException($"{region} is not next to {country.Name}");
            }
            country.AddProvince(region);
            region.IsWater = false;

            _trace.Add($"Add Province: {region.Name}");
            Debug.Log($"Add Province: {region.Name}");

            foreach (var tile in region.HexTiles)
            {
                tile.TileTerrainType = TileTerrainType.Plain;
            }
            region.SetCapital(map);
            regions.Remove(region);
            redoCache.Add(region);
        }
Пример #14
0
 /// <summary>
 /// The cache region.
 /// </summary>
 /// <param name="code">
 /// The code.
 /// </param>
 /// <param name="provinces">
 /// The provinces.
 /// </param>
 private static void CacheRegion(string code, IProvince[] provinces)
 {
     RegionProvinceCache.AddOrUpdate(code, provinces, (x, y) => provinces);
 }
Пример #15
0
 public void RemoveProvince(IProvince province)
 {
     Provinces.Remove(province);
     province.Owner = null;
 }
Пример #16
0
        private void FillRegion(IProvince province, TileBase start, List <Position> sites)
        {
            if (province.Name == "Region 57" || province.Name == "Region 60")
            {
                Debug.Log(start);
            }
            var lowerBorderDirections = new[] { Direction.Northeast, Direction.West, Direction.Northwest };

            var tileStack = new Stack <TileBase>();

            tileStack.Push(start);

            while (tileStack.Count > 0)
            {
                var tile = tileStack.Pop();
                if (province.HexTiles.Contains(tile))
                {
                    continue;
                }

                if (tile == null)
                {
                    Debug.LogError($"Tile is null, tileStack.Count is {tileStack.Count}, province is {province.Name}");
                }

                if (tile.Position != start.Position && sites.Contains(tile.Position))
                {
                    continue;
                }

                province.AddHexTile(tile);

                // Edge cases
                if (_lines.Contains(tile.Position))
                {
                    // If start tile is on border
                    if (tile.Position.Equals(start.Position))
                    {
                        var ownedNeighbours = _map.GetNeighboursWithDirection(tile).Where(n => n.Neighbour.Province != null).ToList();
                        var freeNeighbours  = _map.GetNeighboursWithDirection(tile).Where(n => n.Neighbour.Province == null).ToList();

                        if (ownedNeighbours.Any())
                        {
                            foreach (var neighbour in freeNeighbours)
                            {
                                tileStack.Push(neighbour.Neighbour);
                            }
                            continue;
                        }

                        foreach (var neighbour in freeNeighbours.Where(n => lowerBorderDirections.Contains(n.Direction)))
                        {
                            tileStack.Push(neighbour.Neighbour);
                        }
                        continue;
                    }
                    continue;
                }

                foreach (var neighbour in _map.GetNeighboursWithDirection(tile))
                {
                    if (neighbour.Neighbour == null)
                    {
                        Debug.LogError($"Neighbour is null, tile is {tile}, tileStack.Count is {tileStack.Count}, province is {province.Name}");
                    }

                    if (neighbour.Neighbour.Province == null)
                    {
                        tileStack.Push(neighbour.Neighbour);
                    }
                }
            }
        }
Пример #17
0
 public ProvinceController()
 {
     repo = new ProvinceRepo();
 }
Пример #18
0
 public TileBuilder WithProvince(IProvince province)
 {
     _province = province;
     return(this);
 }
Пример #19
0
 public Province()
 {
     dal = DataAccess.CreateProvince();
 }
Пример #20
0
 public ProvinceController(IProvince prov)
 {
     _prov = prov;
 }
Пример #21
0
 internal static ProvinceDisplay ToProvinceDisplay(this IProvince province)
 {
     return(AutoMapper.Mapper.Map <ProvinceDisplay>(province));
 }