Ejemplo n.º 1
0
        public Chess CreateChess(ChessType type, GameColor color, PointF position = new PointF())
        {
            Chess chess;

            switch (type)
            {
            case ChessType.Bishop:  chess = new ChessBishop(this, color); break;

            case ChessType.King:    chess = new ChessKing(this, color); break;

            case ChessType.Knight:  chess = new ChessKnight(this, color); break;

            case ChessType.Pawn:    chess = new ChessPawn(this, color); break;

            case ChessType.Queen:   chess = new ChessQueen(this, color); break;

            case ChessType.Rook:    chess = new ChessRook(this, color); break;

            default:
                return(null);
            }
            ActiveChess.Add(chess);
            chess.Sprite.Size     = chessSize;
            chess.Sprite.Position = position;
            return(chess);
        }
Ejemplo n.º 2
0
        private void buttonMove_Click(object sender, EventArgs e)
        {
            ChessFigure figureToMove = GetFigure();

            if (figureToMove == null)
            {
                if (comboFrom.Text.Contains("Give In"))
                {
                    MessageBox.Show("You lose!");
                    GameBegins();
                    return;
                }
                if (comboFrom.Text.Contains("Draw"))
                {
                    DialogResult result = MessageBox.Show("Other player, do you want to draw?", "Draw proposal",
                                                          MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        MessageBox.Show("Draw!");
                        GameBegins();
                    }
                    return;
                }

                ChessKing        king  = Game.CurrentPlayer.Figures.OfType <ChessKing>().First();
                List <ChessRook> rooks = Game.CurrentPlayer.Figures.OfType <ChessRook>().ToList();
                ChessRook        rook  = null;
                if (comboFrom.Text == "Long Roque")
                {
                    rook = rooks.First(r => r.CurrentField.Column == 'A');
                }
                if (comboFrom.Text == "Short Roque")
                {
                    rook = rooks.First(r => r.CurrentField.Column == 'H');
                }
                if (rook == null)
                {
                    return;
                }
                rook.MakeRoque(Game.Board, king, Game.CurrentMoveNumber);
            }
            else
            {
                char[]      columnAndRow = comboTo.Text.ToCharArray();
                ChessField  field        = Game.Board.GetField(int.Parse(columnAndRow[1].ToString()), columnAndRow[0]);
                ChessPlayer enemy        = Game.CurrentPlayer.Color == ChessColor.WHITE ? Game.BlackPlayer : Game.WhitePlayer;
                figureToMove.Move(field, enemy, Game.Board, Game.CurrentMoveNumber, Game.CurrentPlayer.Figures);
            }

            bool check = Check();
            bool mate  = CheckMate();

            Game.ChangePlayer();
            DrawFigures();
            PrepareFigures();
            if (mate)
            {
                MessageBox.Show("MATE!");
                GameBegins();
            }
            else if (check)
            {
                MessageBox.Show("CHECK!");
            }
        }