예제 #1
0
        public async Task CreateSingleMapGlobeAsync(int startMapSize)
        {
            var mapFactory = (FuncMapFactory)ServiceProvider.GetRequiredService <IMapFactory>();

            mapFactory.SetFunc(generationOptions =>
            {
                ISectorMap map = new SectorGraphMap <HexNode, HexMapNodeDistanceCalculator>();

                MapFiller.FillSquareMap(map, startMapSize);

                var mapRegion = new MapRegion(id: 1, map.Nodes.ToArray())
                {
                    IsStart   = true,
                    IsOut     = true,
                    ExitNodes = new[] { map.Nodes.Last() }
                };

                map.Regions.Add(mapRegion);

                return(Task.FromResult(map));
            });

            var globeInitialzer = ServiceProvider.GetRequiredService <IGlobeInitializer>();
            var globe           = await globeInitialzer.CreateGlobeAsync("intro").ConfigureAwait(false);

            Globe = globe;
        }
예제 #2
0
        /// <inheritdoc/>
        public Task <ISectorMap> CreateAsync(ISectorMapFactoryOptions generationOptions)
        {
            if (generationOptions is null)
            {
                throw new ArgumentNullException(nameof(generationOptions));
            }

            var factoryOptions = (ISectorSquareMapFactoryOptionsSubScheme)generationOptions.OptionsSubScheme;

            if (factoryOptions == null)
            {
                throw new ArgumentException($"Для {nameof(generationOptions)} не задано {nameof(ISectorSubScheme.MapGeneratorOptions)} равно null.");
            }

            var mapSize = factoryOptions.Size;

            ISectorMap map = new SectorGraphMap();

            MapFiller.FillSquareMap(map, mapSize);

            var mapRegion = new MapRegion(1, map.Nodes.ToArray())
            {
                IsStart   = true,
                IsOut     = true,
                ExitNodes = new[] { map.Nodes.Last() }
            };

            map.Regions.Add(mapRegion);

            return(Task.FromResult(map));
        }
예제 #3
0
        public void Run_FromSpec()
        {
            // ARRANGE

            // Шаг "Есть карта размером"

            const int MAPSIZE = 3;

            ISectorMap map = new SectorGraphMap <HexNode, HexMapNodeDistanceCalculator>();

            MapFiller.FillSquareMap(map, MAPSIZE);

            var mapRegion = new MapRegion(1, map.Nodes.ToArray())
            {
                IsStart   = true,
                IsOut     = true,
                ExitNodes = new[] { map.Nodes.Last() }
            };

            map.Regions.Add(mapRegion);

            // Шаг "Между ячейками () и () есть стена"
            AddWall(map, 0, 0, 1, 0);
            AddWall(map, 1, 0, 0, 1);

            var path = new List <IGraphNode>();

            var startNode  = map.Nodes.SelectByHexCoords(0, 0);
            var finishNode = map.Nodes.SelectByHexCoords(1, 0);

            var contextMock = new Mock <IAstarContext>();

            contextMock.Setup(x => x.GetNext(It.IsAny <IGraphNode>()))
            .Returns <IGraphNode>(x => map.GetNext(x));
            contextMock.Setup(x => x.GetDistanceBetween(It.IsAny <IGraphNode>(), It.IsAny <IGraphNode>()))
            .Returns <IGraphNode, IGraphNode>((a, b) => map.DistanceBetween(a, b));
            var context = contextMock.Object;

            // ACT

            map.FindPath(startNode, finishNode, context, path);

            // ASSERT

            path.Should().NotBeEmpty();
        }
예제 #4
0
        public async Task CreateSectorAsync(int mapSize)
        {
            var mapFactory = (FuncMapFactory)ServiceProvider.GetRequiredService <IMapFactory>();

            mapFactory.SetFunc(() =>
            {
                ISectorMap map = new SectorGraphMap <HexNode, HexMapNodeDistanceCalculator>();

                MapFiller.FillSquareMap(map, mapSize);

                var mapRegion = new MapRegion(1, map.Nodes.ToArray())
                {
                    IsStart   = true,
                    IsOut     = true,
                    ExitNodes = new[] { map.Nodes.Last() }
                };

                map.Regions.Add(mapRegion);

                return(Task.FromResult(map));
            });

            var sectorManager = ServiceProvider.GetRequiredService <ISectorManager>();
            var humanPlayer   = ServiceProvider.GetRequiredService <HumanPlayer>();

            var sectorSubScheme = new TestSectorSubScheme
            {
                RegularMonsterSids  = new[] { "rat" },
                MapGeneratorOptions = new SquareGenerationOptionsSubScheme
                {
                    Size = mapSize
                }
            };

            var sectorNodeMock = new Mock <ISectorNode>();

            sectorNodeMock.SetupGet(x => x.State).Returns(SectorNodeState.SectorMaterialized);
            sectorNodeMock.SetupGet(x => x.SectorScheme).Returns(sectorSubScheme);
            var sectorNode = sectorNodeMock.Object;

            humanPlayer.BindSectorNode(sectorNode);

            await sectorManager.CreateSectorAsync();
        }
예제 #5
0
        /// <summary>
        /// Создание карты.
        /// </summary>
        /// <param name="options">Параметры создания карты.</param>
        /// <returns>
        /// Возвращает экземпляр карты.
        /// </returns>
        public Task <ISectorMap> CreateAsync(object options)
        {
            var mapSize = (int)options;

            ISectorMap map = new SectorGraphMap();

            MapFiller.FillSquareMap(map, mapSize);

            var mapRegion = new MapRegion(1, map.Nodes.ToArray())
            {
                IsStart   = true,
                IsOut     = true,
                ExitNodes = new[] { map.Nodes.Last() }
            };

            map.Regions.Add(mapRegion);

            return(Task.FromResult(map));
        }
예제 #6
0
        public async Task CreateSectorAsync(int mapSize)
        {
            var mapFactory = (FuncMapFactory)Container.GetInstance <IMapFactory>();

            mapFactory.SetFunc(() =>
            {
                ISectorMap map = new SectorGraphMap <HexNode, HexMapNodeDistanceCalculator>();

                MapFiller.FillSquareMap(map, mapSize);

                var mapRegion = new MapRegion(1, map.Nodes.ToArray())
                {
                    IsStart   = true,
                    IsOut     = true,
                    ExitNodes = new[] { map.Nodes.Last() }
                };

                map.Regions.Add(mapRegion);

                return(Task.FromResult(map));
            });

            var sectorManager = Container.GetInstance <ISectorManager>();
            var humanPlayer   = Container.GetInstance <HumanPlayer>();

            var locationScheme = new TestLocationScheme
            {
                SectorLevels = new ISectorSubScheme[]
                {
                    new TestSectorSubScheme
                    {
                        RegularMonsterSids = new[] { "rat" },
                    }
                }
            };
            var globeNode = new GlobeRegionNode(0, 0, locationScheme);

            humanPlayer.GlobeNode = globeNode;

            await sectorManager.CreateSectorAsync();
        }