Example #1
0
        public void OnLeftClick()
        {
            if (IsMouseOver())
            {
                bool hasSelectedRoot = ((ChessGameScene)ChessGame.Instance.CurrentScene).HasSelectedRootNode;
                if (!hasSelectedRoot)
                {
                    if (PieceInThisPosition != null && PieceInThisPosition.IsCorrectTurn())
                    {
                        if (PieceInThisPosition.GetPossibleMoves().Count > 0)
                        {
                            NotationBuilder = new StringBuilder();
                            IsSelected      = true;
                            ((ChessGameScene)ChessGame.Instance.CurrentScene).HasSelectedRootNode = true;
                            ((ChessGameScene)ChessGame.Instance.CurrentScene).RootNode            = this;
                            List <Vector2D>         possibleMoves        = PieceInThisPosition.GetPossibleMoves();
                            List <ChessBoardSprite> possibleMovesSprites = new List <ChessBoardSprite>();
                            foreach (Vector2D move in possibleMoves)
                            {
                                if (PieceInThisPosition.IsValidMove(move) &&
                                    MovementValidation.IsPathNotObstructed(PieceInThisPosition.BoardPosition, move))
                                {
                                    possibleMovesSprites.Add(GetBoardPieceByCoord(move.ToCoordinate()));
                                }
                            }
                            //possibleMoves.ForEach(m => possibleMovesSprites.Add(GetBoardPieceByCoord(m.ToCoordinate())));
                            possibleMovesSprites.ForEach(m => m.MarkAsValidPosition());
                            NotationBuilder.Append(BoardPosition.ToCoordinate() + " ");
                        }
                        else
                        {
                            Notifications.Notify("That piece has no possible moves.");
                        }
                    }
                }
                else
                {
                    List <ChessBoardSprite> allChessBoardPieces = GetAllChessBoardPieces();
                    ChessBoardSprite        movingPosition      = ((ChessGameScene)ChessGame.Instance.CurrentScene).RootNode;
                    ChessPiece movingPiece = movingPosition.PieceInThisPosition;

                    if (movingPiece.IsValidMove(BoardPosition))
                    {
                        NotationBuilder.Append(BoardPosition.ToCoordinate());

                        if (PieceInThisPosition != null)
                        {
                            NotationBuilder.Append("*");
                        }

                        Console.WriteLine("Command: [" + NotationBuilder.ToString() + "]");

                        NotationParser.ParseString(NotationBuilder.ToString());
                        UpdateChessPieceTexture();
                        movingPosition.UpdateChessPieceTexture();
                        OnRightClick();
                    }
                }
            }
        }