Exemplo n.º 1
0
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            if (currentButton == 0)
            {
                FirstClick?.Invoke(this, e);
            }
            else if (currentButton == 1)
            {
                SecondClick?.Invoke(this, e);
            }
        }
Exemplo n.º 2
0
        private void Square_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (u.firstClick)
                {
                    var x = this;

                    if (x.Piece == null)
                    {
                        return;
                    }

                    if (u.WhosPlaying == x.Piece.Color || u.DisableTurn)
                    {
                        x.BackColor  = Color.LightGreen;
                        u.lastSquare = x;
                        u.light.FindAllMoves(x);
                        u.light.HighLightMoveStyle();
                        FirstClick?.Invoke(this, e);
                        u.firstClick = !u.firstClick;
                    }
                }
                else
                {
                    var x = this;

                    // If click again on same piece do nothing
                    if (u.lastSquare == x)
                    {
                        return;
                    }

                    u.lastSquare.BackColor = u.lastSquare.DefaultColor;

                    if (!x.IsEmpty)
                    {
                        if (x.Piece != null)
                        {
                            if (x.Piece.Color == u.lastSquare.Piece.Color)
                            {
                                u.light.Clear();
                                x.BackColor = Color.LightGreen;

                                u.lastSquare = x;
                                u.light.FindAllMoves(x);
                                u.light.HighLightMoveStyle();
                                FirstClick?.Invoke(this, e);
                                return;
                            }
                        }
                    }

                    SecondClick?.Invoke(this, e);
                    u.firstClick = !u.firstClick;
                    u.light.Clear();
                }
            }

            if (e.Button == MouseButtons.Right)
            {
                MessageBox.Show($"{Piece?.Name}\r\n{File}-{Rank}\r\n{Name}");
            }
        }