コード例 #1
0
        public void NearbyDirectionsAreCorrect(HexDirection direction, HexDirection expectedDirection1, HexDirection expectedDirection2)
        {
            HexDirection[] directions         = direction.NearbyDirections();
            HexDirection[] expectedDirections = { expectedDirection1, expectedDirection2 };

            Assert.Equal(expectedDirections, directions);
        }
コード例 #2
0
        public List <HexCell> GetArea(HexDirection direction, int height, int width)
        {
            if (height < 1 || width < 1 || width % 2 == 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            List <HexCell> areaCells = new List <HexCell>();

            HexDirection[] nearbyDirections = direction.NearbyDirections();
            List <HexCell> firstCells       = new List <HexCell>();

            firstCells.Add(GetNeighbor(direction));
            foreach (HexDirection d in nearbyDirections)
            {
                HexCell lastCell = this;
                for (int i = width; i > 1; i -= 2)
                {
                    lastCell = lastCell.GetNeighbor(d);
                    if (lastCell == null)
                    {
                        break;
                    }
                    firstCells.Add(lastCell);
                }
            }
            areaCells.AddRange(firstCells);
            firstCells.ForEach(c => areaCells.AddRange(c.GetLine(direction, height - 1)));

            return(areaCells);
        }