Example #1
0
        public bool TrySetSettlement(PlayerColor player, CornerLocation location)
        {
            var tile = this.GetTileByLocation(this.CornerLocationToBoardCoordinates(location));

            if (tile == null || !tile.IsCornerEmpty(location.Corner))
            {
                return(false);
            }

            var neighbours = tile.GetNeighbours(location.Corner);

            if (!neighbours.All(x => x.Tile.IsCornerEmpty(x.Corner)))
            {
                return(false);
            }

            tile.SetSettlement(player, location.Corner);
            neighbours.ToList().ForEach(neighbour => neighbour.Tile.SetSettlement(player, neighbour.Corner));

            return(true);
        }
Example #2
0
        /// <summary>
        /// 计算绘图路径 GraphicsPath
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="radius"></param>
        /// <param name="sPosition"></param>
        /// <returns></returns>
        private static GraphicsPath CreateRoundRectanglePath(Rectangle rect, int radius, CornerLocation cornerLocation)
        {
            GraphicsPath rectPath = new GraphicsPath();

            switch (cornerLocation)
            {
            case CornerLocation.TopLeft:
            {
                rectPath.AddArc(rect.Left, rect.Top, radius * 2, radius * 2, 180, 90);
                rectPath.AddLine(rect.Left, rect.Top, rect.Left, rect.Top + radius);
                break;
            }

            case CornerLocation.TopRight:
            {
                rectPath.AddArc(rect.Right - radius * 2, rect.Top, radius * 2, radius * 2, 270, 90);
                rectPath.AddLine(rect.Right, rect.Top, rect.Right - radius, rect.Top);
                break;
            }

            case CornerLocation.BottomLeft:
            {
                rectPath.AddArc(rect.Left, rect.Bottom - radius * 2, radius * 2, radius * 2, 90, 90);
                rectPath.AddLine(rect.Left, rect.Bottom - radius, rect.Left, rect.Bottom);
                break;
            }

            case CornerLocation.BottomRight:
            {
                rectPath.AddArc(rect.Right - radius * 2, rect.Bottom - radius * 2, radius * 2, radius * 2, 0, 90);
                rectPath.AddLine(rect.Right - radius, rect.Bottom, rect.Right, rect.Bottom);
                break;
            }
            }
            return(rectPath);
        }
Example #3
0
 private BoardCoordinates CornerLocationToBoardCoordinates(CornerLocation location) => new BoardCoordinates(location.Column, location.Row);