Ejemplo n.º 1
0
        private void buttonAccept_Click(object sender, System.EventArgs e)
        {
            //Button "Accept" clicked, carry out the promotion

            if (comboBoxFigures.SelectedItem == null)
            {
                MessageBox.Show(this, "You must select a figure", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                promotionRealized = true;

                //Delete the pawn

                Board.getInstance().killPiece(pawn.getPosition(), true);

                //Create the new figure

                string   fig   = comboBoxFigures.SelectedItem.ToString();
                Position pos   = pawn.getPosition();
                Color    color = pawn.getColor();
                Piece    piece = null;

                if (fig == "Bishop")
                {
                    piece = new Bishop(pos, color);
                }
                else if (fig == "Knight")
                {
                    piece = new Knight(pos, color);
                }
                else if (fig == "Queen")
                {
                    piece = new Queen(pos, color);
                }
                else if (fig == "Rook")
                {
                    piece = new Rook(pos, color);
                }

                if (color == Color.White)
                {
                    Board.getInstance().getWhitePieces().insert(piece);
                }
                else
                {
                    Board.getInstance().getBlackPieces().insert(piece);
                }

                Board.getInstance().deletePiece(pawn);
                Board.getInstance().drawPiece(piece);

                this.Close();
            }
        }