public void Should_Get_Terrain_Behaviour_Return_Expected_Value()
        {
            ITerrainNode[,] terrainArray = new ITerrainNode[Rows, Cols];
            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Cols; j++)
                {
                    terrainArray[i, j] = MockRepository.GenerateMock<ITerrainNode>();
                    var terrainBehaviour = MockRepository.GenerateMock<ITerrainBehaviour>();
                    terrainBehaviour.Stub(x => x.RowIndex).Return(i);
                    terrainBehaviour.Stub(x => x.ColsIndex).Return(j);
                    terrainBehaviour.Stub(x => x.GetTerrainId()).Return(i * 100 + j);
                    terrainArray[i, j].Stub(x => x.Item).Return(terrainBehaviour);
                }
            }
            var nodeContainer = MockRepository.GenerateMock<ITerrainNodeContainer>();
            nodeContainer.Stub(x => x.TerrainNodesArray).Return(terrainArray);
            _nodesFactory.Stub(x => x.CreateNodeContainer(Arg<ITerrainBehaviour[,]>.Is.Anything)).Return(nodeContainer);

            ITerrainService testedClass = new TerrainService(_nodesFactory, _searchPathStrategy);
            var terrains = new ITerrainBehaviour[1];
            terrains[0] = MockRepository.GenerateMock<ITerrainBehaviour>();
            testedClass.NetworkTerrainFinishGeneration(terrains, 1, 1);
            var terrain = testedClass.GetTerrainBehaviour(5, 7);
            Assert.AreEqual(terrain.RowIndex, 5);
            Assert.AreEqual(terrain.ColsIndex, 7);
        }
        private void InitializeAsEvenHex(ITerrainNode[,] nodesArray)
        {
            var rowsLength = nodesArray.GetLength(X_DIMENDION);
            var columnsLength = nodesArray.GetLength(Z_DIMENSION);
            var collection = new List<ITerrainNode>();

            if (RowIndex + 1 < rowsLength && ColumnIndex + 1 < columnsLength)
            {
                collection.Add(nodesArray[RowIndex + 1, ColumnIndex + 1]);
            }
            if (RowIndex - 1 >= 0 && ColumnIndex + 1< columnsLength)
            {
                collection.Add(nodesArray[RowIndex - 1, ColumnIndex + 1]);
            }
            if (RowIndex - 2 >= 0)
            {
                collection.Add(nodesArray[RowIndex - 2, ColumnIndex]);
            }
            if (RowIndex - 1 >= 0)
            {
                collection.Add(nodesArray[RowIndex - 1, ColumnIndex]);
            }

            if (RowIndex + 1 < rowsLength)
            {
                collection.Add(nodesArray[RowIndex + 1, ColumnIndex]);
            }

            if (RowIndex + 2 < rowsLength)
            {
                collection.Add(nodesArray[RowIndex + 2, ColumnIndex]);
            }

            Nodes = collection;
        }
 private void Initialize(ITerrainNode[,] nodesArray)
 {
     if (IsEven)
     {
         InitializeAsEvenHex(nodesArray);
     }
     else
     {
         InitialzieAsOddHex(nodesArray);
     }
 }
        public void BuildTown(ITerrainNode targetTerrainNode)
        {
            if(!CanBuildTown(targetTerrainNode))
            {
                return;
            }

            targetTerrainNode.Item.SetColor();
            var nodes = targetTerrainNode.Nodes;
            foreach (var terrainNode in nodes)
            {
                terrainNode.Item.SetColor();
            }
        }
Beispiel #5
0
        private ITerrainNode[,] CreateSegment(int segmentX, int segmentY)
        {
            var matrix = new ITerrainNode[_segmentSize, _segmentSize];

            for (var i = 0; i < _segmentSize; i++)
            {
                for (var j = 0; j < _segmentSize; j++)
                {
                    matrix[i, j] = new HexNode(i + segmentX * _segmentSize, j + segmentY * _segmentSize);
                }
            }

            var key = new SegmentKey(segmentX, segmentY);

            _segmentDict[key] = matrix;
            return(matrix);
        }
        public bool CanBuildTown(ITerrainNode targetTerrainNode)
        {
            if (targetTerrainNode.Item.IsTown)
            {
                return false;
            }

            var nodes = targetTerrainNode.Nodes;

            foreach (var terrainNode in nodes)
            {
                if (!IsFreeSpace(terrainNode, MAX_DISTANCE_TO_ANOTHER_TOWN))
                {
                    return false;
                }
            }

            return true;
        }
        private bool IsFreeSpace(ITerrainNode terrainNode, int distance)
        {
            if (distance == STOP_DISTANCE_SEARCH)
            {
                return !terrainNode.Item.IsTown;
            }

            if (terrainNode.Item.IsTown)
            {
                return false;
            }

            foreach (var node in terrainNode.Nodes)
            {
                if (!IsFreeSpace(node, distance - 1))
                {
                    return false;
                }
            }

            return true;
        }
Beispiel #8
0
        public IEnumerable <ITerrainNode> GetNeighborNodes(ITerrainNode node)
        {
            var offsetCoords = node.Offset;
            var segmentX     = offsetCoords.X / _segmentSize;

            if (offsetCoords.X < 0)
            {
                segmentX--;
            }

            var segmentY = offsetCoords.Y / _segmentSize;

            if (offsetCoords.Y < 0)
            {
                segmentY--;
            }

            var localOffsetX = NormalizeNeighborCoord(offsetCoords.X % _segmentSize);
            var localOffsetY = NormalizeNeighborCoord(offsetCoords.Y % _segmentSize);

            var segmentKey = new SegmentKey(segmentX, segmentY);
            var matrix     = _segmentDict[segmentKey];

            var directions        = HexHelper.GetOffsetClockwise();
            var currentCubeCoords = HexHelper.ConvertToCube(localOffsetX, localOffsetY);

            for (var i = 0; i < 6; i++)
            {
                var dir = directions[i];
                var neighborLocalCube = new CubeCoords(dir.X + currentCubeCoords.X,
                                                       dir.Y + currentCubeCoords.Y,
                                                       dir.Z + currentCubeCoords.Z);

                var neighborLocalOffset = HexHelper.ConvertToOffset(neighborLocalCube);

                var neighborSegmentX = segmentX;
                var neighborSegmentY = segmentY;

                if (neighborLocalOffset.X < 0)
                {
                    neighborSegmentX--;
                }
                else if (neighborLocalOffset.X >= _segmentSize)
                {
                    neighborSegmentX++;
                }

                if (neighborLocalOffset.Y < 0)
                {
                    neighborSegmentY--;
                }
                else if (neighborLocalOffset.Y >= _segmentSize)
                {
                    neighborSegmentY++;
                }

                if (neighborSegmentX == segmentX &&
                    neighborSegmentY == segmentY)
                {
                    yield return(matrix[neighborLocalOffset.X, neighborLocalOffset.Y]);
                }
                else
                {
                    var segmentMatrix = CreateSegment(neighborSegmentX, neighborSegmentY);
                    var neighborX     = NormalizeNeighborCoord(neighborLocalOffset.X);
                    var neighborY     = NormalizeNeighborCoord(neighborLocalOffset.Y);

                    yield return(segmentMatrix[neighborX, neighborY]);
                }
            }
        }
 public TerrainNodeContainer(ITerrainNode[,] terrainNodesArray)
 {
     TerrainNodesArray = terrainNodesArray;
     RowsLength = terrainNodesArray.GetLength(X_DIMENDION);
     ColumnsLength = terrainNodesArray.GetLength(Z_DIMENSION);
 }
Beispiel #10
0
 public void Init(ITerrainNode node)
 {
     Node = node;
 }
Beispiel #11
0
 public void MoveTo(ITerrainNode targetNode)
 {
     Node = targetNode;
 }
Beispiel #12
0
 public Army(ITerrainNode node)
 {
     Node = node ?? throw new ArgumentNullException(nameof(node));
 }
Beispiel #13
0
 public CombatSquad(ITerrainNode node, [NotNull] ICombatPerson[] persons, Player player)
 {
     Node    = node ?? throw new ArgumentNullException(nameof(node));
     Persons = persons ?? throw new ArgumentNullException(nameof(persons));
     Player  = player;
 }
Beispiel #14
0
 public void InitializeNode(ITerrainBehaviour item, ITerrainNode[,] nodesArray)
 {
     Item = item;
     Initialize(nodesArray);
 }
Beispiel #15
0
 public IEnumerable <ITerrainNode> GetNeighborNodes(ITerrainNode node)
 {
     throw new NotImplementedException();
 }