예제 #1
0
        /// <summary>
        ///     Creates a board layout
        /// </summary>
        private void CreateBoard()
        {
            SuspendLayout();

            var boardSize = new Size(CellSize * BoardRegion.Width + CellSize, CellSize * BoardRegion.Height + CellSize);

            base.MinimumSize = boardSize;
            base.MaximumSize = boardSize;

            CreateHeaders();

            var points = BoardRegion.GetPoints();

            foreach (var point in points)
            {
                var cell = new BoardCell(point.X, point.Y)
                {
                    Top    = point.X * CellSize + CellSize,
                    Left   = point.Y * CellSize + CellSize,
                    Width  = CellSize,
                    Height = CellSize,
                    State  = BoardCellState.Normal
                };
                _cells[point.X, point.Y] = cell;
                cell.MouseDown          += OnCellMouseDown;
                cell.DragEnter          += OnCellDragEnter;
                cell.DragLeave          += OnCellDragLeave;
                cell.DragDrop           += OnCellDragDrop;
                cell.QueryContinueDrag  += OnCellQueryContinueDrag;
                cell.Click += OnCellClick;
                Controls.Add(cell);
            }

            ResumeLayout();
        }
예제 #2
0
        /// <summary>
        ///     Redraws a given region on a board
        /// </summary>
        /// <param name="region">A region to redraw</param>
        private void RedrawRegion(Rect region)
        {
            SuspendLayout();

            var points = region.GetPoints();

            foreach (var point in points)
            {
                if (!BoardRegion.Contains(point))
                {
                    continue;
                }

                var ship = GetShipAt(point.X, point.Y);
                _cells[point.X, point.Y].State = ship == null ? BoardCellState.Normal : BoardCellState.Ship;
            }

            ResumeLayout();
        }