Esempio n. 1
0
        void SetShip(Point point)
        {
            currentShip.AddPoint(point);
            SetEnabledPoints(currentShip);

            if (currentShip.Initialized)
            {
                if (currentShip.IsVertical)
                {
                    var top    = Buttons.First(n => n.Coordinates() == currentShip.Top);
                    var bottom = Buttons.First(n => n.Coordinates() == currentShip.Bottom);
                    top.Text    = "⎯";
                    bottom.Text = "⎯";
                }
                else
                {
                    var left  = Buttons.First(n => n.Coordinates() == currentShip.Left);
                    var right = Buttons.First(n => n.Coordinates() == currentShip.Right);
                    left.Text  = "|";
                    right.Text = "|";
                }

                currentShip = ships.FirstOrDefault(n => !n.Initialized);
                if (currentShip == null)
                {
                    Buttons.ForEach(n =>
                    {
                        n.IsEnabled       = true;
                        n.Clicked        -= SetShip;
                        n.Clicked        += Hit;
                        n.BackgroundColor = Color.White;
                    });
                    NotifyOfPropertyChange(() => Initialized);
                    StartGameAction?.Invoke();
                }
                else
                {
                    EnableEmpty();
                }
            }
        }