Ejemplo n.º 1
0
        private void MyField_DragLeave(object sender, DragEventArgs e)
        {
            Cell       cell = (Cell)sender;
            ShipVisual ship = (ShipVisual)e.Data.GetData("Ship");

            if (ship.Orientation == Orientation.Horizontal)
            {
                for (int j = cell.J; j < cell.J + ship.Length; j++)
                {
                    if (j >= 0 && j < 10)
                    {
                        cellField[cell.I, j].Background = Brushes.Transparent;
                    }
                }
            }
            else
            {
                for (int i = cell.I; i < cell.I + ship.Length; i++)
                {
                    if (i >= 0 && i < 10)
                    {
                        cellField[i, cell.J].Background = Brushes.Transparent;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void MyField_DragEnter(object sender, DragEventArgs e)
        {
            Cell       cell = (Cell)sender;
            ShipVisual ship = (ShipVisual)e.Data.GetData("Ship");

            ship.I = cell.I;
            ship.J = cell.J;
            bool buff = CanSetShip(ship);

            if (ship.Orientation == Orientation.Horizontal)
            {
                for (int j = cell.J; j < cell.J + ship.Length; j++)
                {
                    if (j >= 0 && j < 10)
                    {
                        cellField[cell.I, j].Background = (buff) ? Brushes.GreenYellow : Brushes.IndianRed;
                    }
                }
            }
            else
            {
                for (int i = cell.I; i < cell.I + ship.Length; i++)
                {
                    if (i >= 0 && i < 10)
                    {
                        cellField[i, cell.J].Background = (buff) ? Brushes.GreenYellow : Brushes.IndianRed;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void MyField_Drop(object sender, DragEventArgs e)
        {
            Cell       cell = (Cell)sender;
            ShipVisual ship = (ShipVisual)e.Data.GetData("Ship");

            TrySetShip(ship, cell.I, cell.J);

            MyField_DragLeave(sender, e);
        }