Exemplo n.º 1
0
        public void CheckForSquareClicked(MouseButtonEventArgs buttonEventArgs)
        {
            for (int y = 0; y < _boardUI.SquareUI.GetLength(0); ++y)
            {
                for (int x = 0; x < _boardUI.SquareUI.GetLength(1); ++x)
                {
                    if (_boardUI.SquareUI[x, y].IsClicked(buttonEventArgs))
                    {
                        // Clicked Square Is Current Player's
                        if (_game.Board.GetPieceAt(x, y) != null && _game.Board.GetPieceAt(x, y).Color == _game.CurrentPlayer)
                        {
                            // No Selected Piece
                            if (!_boardUI.SquareIsSelected)
                            {
                                _boardUI.SelectSquare(new Position(x, y));
                            }

                            // Reclicked Selected Piece
                            else if (_boardUI.Selection.X == x && _boardUI.Selection.Y == y)
                            {
                                _boardUI.UnselectSquare();
                            }

                            // Clicked On New Piece
                            else
                            {
                                _boardUI.SelectSquare(new Position(x, y));
                            }

                            _boardUI.HighlightSquares(_game.Board);
                        }
                        else if (_boardUI.SquareIsSelected)
                        {
                            // Check If Clicked Square Is Valid Move For Selected Piece
                            if (_game.Board.GetPieceAt(_boardUI.Selection.X, _boardUI.Selection.Y).HasMove(new Position(x, y)))
                            {
                                _boardUI.UnselectSquare();
                                _game.ExecuteMove(_game.Board.GetPieceAt(_boardUI.Selection.X, _boardUI.Selection.Y).GetMove(new Position(x, y)));
                            }
                        }
                    }
                }
            }
        }