Пример #1
0
 private static void SetUpEngine(out BoardConsoleRenderer renderer, out WinnerReferee referee)
 {
     renderer = new BoardConsoleRenderer();
     referee  = new WinnerReferee();
 }
Пример #2
0
        private static string Play(Board board, string humanPlayerSymbol, string computerPlayerSymbol, ComputerPlayer computerPlayer, HumanPlayer humanPlayer, BoardConsoleRenderer renderer, WinnerReferee referee)
        {
            var winner = string.Empty;

            while (string.IsNullOrEmpty(winner))
            {
                computerPlayer.Move(board);
                Console.WriteLine(renderer.Render(board));
                winner = referee.CheckWinner(board, computerPlayerSymbol);
                referee.AnnounceWinner(winner);
                if (!string.IsNullOrEmpty(winner))
                {
                    break;
                }
                if (board.Squares.All(x => !string.IsNullOrEmpty(x)))
                {
                    break;
                }

                humanPlayer.Move(board);
                Console.WriteLine(renderer.Render(board));
                winner = referee.CheckWinner(board, humanPlayerSymbol);
                referee.AnnounceWinner(winner);
                if (!string.IsNullOrEmpty(winner))
                {
                    break;
                }
                if (board.Squares.All(x => !string.IsNullOrEmpty(x)))
                {
                    break;
                }
            }

            return(winner);
        }