/// <summary> /// Handles <see cref="BoardCell"/>'s DragDrop event /// </summary> private void OnCellDragDrop(object sender, DragEventArgs e) { var cell = (BoardCell)sender; if (e.Data.GetDataPresent(typeof(Ship))) { if (!CanPlaceShip(_draggedShip, cell.X, cell.Y)) { return; } var ship = _draggedShip.Source; _ships.Remove(ship); var rect = ship.GetShipRegion(); RedrawRegion(rect); ship.Orientation = _draggedShip.Orientation; AddShip(ship, cell.X, cell.Y); _draggedShip = null; } else { e.Effect = DragDropEffects.None; } }
/// <summary> /// Handles <see cref="BoardCell"/>'s MouseDown event and initiates ship drag'n'drop /// </summary> private void OnCellMouseDown(object sender, MouseEventArgs e) { if (Mode == BoardMode.Game || !_drawShips) { return; } var cell = (BoardCell)sender; var ship = GetShipAt(cell.X, cell.Y); if (ship == null) { return; } _draggedShip = DraggableShip.From(ship); cell.DoDragDrop(ship, DragDropEffects.Copy | DragDropEffects.Move); }