public void TargetIsOnLine_MapWithGap_HasLine() { // ARRANGE var map = new SectorHexMap(); MapFiller.FillSquareMap(map, mapSize: 2); MapFiller.FillSquareMap(map, startX: 3, startY: 0, mapSize: 2); var startMap = map.HexNodes.SelectBy(0, 0); var targetMap = map.HexNodes.SelectBy(4, 0); // ACT var fact = map.TargetIsOnLine(startMap, targetMap); // ASSERT fact.Should().BeFalse(); }
public void TargetIsOnLine_MapWithObstacleInSide_HasNotLine() { // ARRANGE var map = new SectorHexMap(); MapFiller.FillSquareMap(map, 3, (x, y) => { return(new MapFiller.HexNodeOptions { IsObstacle = x == 1 && y == 1 // (1, 1) здесь будет препятсвие }); }); var startMap = map.HexNodes.SelectBy(0, 0); var targetMap = map.HexNodes.SelectBy(2, 1); // ACT var fact = map.TargetIsOnLine(startMap, targetMap); // ASSERT fact.Should().BeFalse(); }
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; }
/// <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)); }
public void TargetIsOnLine_EmptyMap_HasLine() { // ARRANGE var map = new SectorHexMap(); MapFiller.FillSquareMap(map, 3); var startMap = map.HexNodes.SelectBy(0, 0); var targetMap = map.HexNodes.SelectBy(2, 1); // ACT var fact = map.TargetIsOnLine(startMap, targetMap); // ASSERT fact.Should().BeTrue(); }
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(); }
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(); }
/// <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)); }
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(); }
/// <summary> /// Создание карты. /// </summary> /// <param name="options">Параметры создания карты.</param> /// <returns> /// Возвращает экземпляр карты. /// </returns> public Task <ISectorMap> CreateAsync(object options) { const int START_ROOM_SIZE = 2; var mapSize = (int)options; ISectorMap map = new SectorHexMap(); MapFiller.FillSquareMap(map, mapSize); var startRoomLeftBorder = mapSize / 2 - START_ROOM_SIZE / 2; var startRoomTopBorder = mapSize / 2 - START_ROOM_SIZE / 2; var startRoomRightBorder = startRoomLeftBorder + START_ROOM_SIZE - 1; var startRoomBottomBorder = startRoomTopBorder + START_ROOM_SIZE - 1; var startNodes = map.Nodes.OfType <HexNode>() .Where(node => (startRoomLeftBorder <= node.OffsetX && node.OffsetX <= startRoomRightBorder) && (startRoomTopBorder <= node.OffsetY && node.OffsetY <= startRoomBottomBorder)) .ToArray(); var startRegion = new MapRegion(1, startNodes) { IsStart = true, }; var outerNodes = map.Nodes.Where(x => !startNodes.Contains(x)).ToArray(); var outerRegion = new MapRegion(2, outerNodes) { IsOut = true, ExitNodes = new[] { outerNodes.Last() } }; map.Regions.Add(startRegion); map.Regions.Add(outerRegion); map.Transitions.Add(outerNodes.Last(), RoomTransition.CreateGlobalExit()); return(Task.FromResult(map)); }