示例#1
0
        public void PlayGame()
        {
            bool lightsTurn = true;

            while (true)
            {
                if (lightsTurn)
                {
                    Console.WriteLine("It is Light's Turn.");
                    string move = Console.ReadLine();
                    string message;
                    if (Parser.ParseLine(move, out message))
                    {
                        if (Board.GetBoardSpace(move[1] - '0' - 1, move[0] - 'a').GetPiece().GetColor().Equals("Light"))
                        {
                            if (chessBoard.Move(move))
                            {
                                if (!chessBoard.DetermainCheck("Light"))
                                {
                                    lightsTurn = false;
                                    Parser.PrintInfo(move, message);
                                    if (chessBoard.DetermainCheck("Dark"))
                                    {
                                        Console.WriteLine("The Dark king is in Check.");
                                    }
                                }
                                else
                                {
                                    string undoMove = move[3].ToString() + move[4].ToString() + move[2].ToString() + move[0].ToString() + move[1].ToString();
                                    chessBoard.Move(undoMove);
                                    message = "That places you in check.";
                                }
                            }
                            Parser.PrintBoard();
                        }
                        else
                        {
                            Console.WriteLine("That was not your piece.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("It is Dark's Turn.");
                    string move = Console.ReadLine();
                    string message;
                    if (Parser.ParseLine(move, out message))
                    {
                        if (Board.GetBoardSpace(move[1] - '0' - 1, move[0] - 'a').GetPiece().GetColor().Equals("Dark"))
                        {
                            if (chessBoard.Move(move))
                            {
                                if (!chessBoard.DetermainCheck("Light"))
                                {
                                    lightsTurn = true;
                                    Parser.PrintInfo(move, message);
                                    if (chessBoard.DetermainCheck("Light"))
                                    {
                                        Console.WriteLine("The Light king is in Check.");
                                    }
                                }
                                else
                                {
                                    string undoMove = move[3].ToString() + move[4].ToString() + move[2].ToString() + move[0].ToString() + move[1].ToString();
                                    chessBoard.Move(undoMove);
                                    message = "That places you in check.";
                                }
                                Parser.PrintBoard();
                            }
                            else
                            {
                                Console.WriteLine("That was not your piece.");
                            }
                        }
                    }
                }
            }
        }