Esempio n. 1
0
        internal void Select(ChessBoard board, SquareCoordinates coord)
        {
            ChessPiece selectedPiece = board.GetPiece(coord);
            if (moves == null)
            {
                if (selectedPiece != null && selectedPiece.White == white)
                {
                    firstSelection = coord;
                    moves = GameLogic.MoveSet(board, coord, this);
                    board.HighlightSquare(coord, Color.Yellow);
                    FirstSquareSelected(board, coord, moves);
                }
            }
            else
            {
                if (coord == firstSelection)
                {
                    MoveSet prevMoves = moves;
                    ResetSelected();
                    board.UnhighlightSquare(coord);
                    Unselected(board, coord, prevMoves);
                }
                else
                {
                    Move m = GetMove(moves, coord);
                    if (m != null)
                    {
                        ChessPiece movedPiece, takenPiece = null;
                        MoveSet prevMoves = moves;
                        ResetSelected();
                        board.UnhighlightSquare(firstSelection);
                        if (m.Overtaken)
                            takenPiece = board.ClearSquare(m.TakenPiece);

                        movedPiece = board.ClearSquare(firstSelection);
                        movedPiece.LastSquare = firstSelection;
                        movedPiece.LastMove = board.CurrentMove;
                        board.DrawPiece(coord, movedPiece);
                        material.MovePiece(movedPiece.Type, firstSelection, coord);

                        MadeMove(board, movedPiece, firstSelection, coord, prevMoves);
                        board.UpdateLastMove(firstSelection, m, movedPiece, takenPiece);
                        board.NextTurn();
                    }
                    else if (moves.CheckableMoves.Contains(coord) && !board.ShowCheckedMoves)
                    {
                        MessageBox.Show(board, "You may not place the selected piece there\nsince it will either place your king in check\nor will leave your king in check.", "Illegal Move", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }