Exemplo n.º 1
0
        private void OnCellDragDrop(object sender, DragEventArgs e)
        {
            var cell = (BoardCell)sender;

            if (e.Data.GetDataPresent(_draggedShip.Source.GetType()))
            {
                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;
            }
        }
Exemplo n.º 2
0
        public static DraggableShip From(Ship ship)
        {
            var draggableShip = new DraggableShip(ship.Length)
            {
                X           = ship.X,
                Y           = ship.Y,
                Orientation = ship.Orientation,
                Source      = ship
            };

            return(draggableShip);
        }
Exemplo n.º 3
0
        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);
        }