Ejemplo n.º 1
0
        public void MessageIfPlayersDraw()
        {
            var game = new GameBuilder().PlayersDraw().Build();

            game.Play();

            var printer = new GameBoardPrinter(game);
            Assert.That(printer.WinnerMessage(), Is.EqualTo("No winner, players have drawn."));
        }
Ejemplo n.º 2
0
        public void MessageIfPlayerHasWon()
        {
            var game = new GameBuilder().NaughtsWins().Build();

            game.Play();

            var printer = new GameBoardPrinter(game);
            Assert.That(printer.WinnerMessage(), Is.EqualTo("The winner is Naughts."));
        }
Ejemplo n.º 3
0
        public void PrintSymbolForPlayers()
        {
            var naughts = new RandomPlayer();
            var crosses = new RandomPlayer();
            var game = new TicTacToeGame(naughts, crosses);

            var printer = new GameBoardPrinter(game);
            Assert.That(printer.SymbolForPlayer(naughts), Is.EqualTo("O"));
            Assert.That(printer.SymbolForPlayer(crosses), Is.EqualTo("X"));
            Assert.That(printer.SymbolForPlayer(null), Is.EqualTo(" "));
        }
Ejemplo n.º 4
0
        public void PrintNameForPlayers()
        {
            var naughts = new RandomPlayer();
            var crosses = new RandomPlayer();
            var game = new TicTacToeGame(naughts, crosses);

            var printer = new GameBoardPrinter(game);
            Assert.That(printer.NameForPlayer(naughts), Is.EqualTo("Naughts"));
            Assert.That(printer.NameForPlayer(crosses), Is.EqualTo("Crosses"));
            Assert.That(printer.NameForPlayer(null), Is.EqualTo(null));
        }
Ejemplo n.º 5
0
        public void PrintGameBoard()
        {
            var game = new GameBuilder().NaughtsWins().Build();
            var printer = new GameBoardPrinter(game);

            game.Play();

            // I think this might be a bit over-specified..
            Assert.That(printer.Board(), Is.EqualTo(" | O | O | O | " + Environment.NewLine +
                                                    " | X | X |   | " + Environment.NewLine +
                                                    " |   |   |   | " + Environment.NewLine));
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            var naughts = new ConsolePlayer(new ConsoleInput());
            var crosses = new MiniMaxPlayer(naughts);
            var game = new TicTacToeGame(naughts, crosses);

            var printer = new GameBoardPrinter(game);
            Console.WriteLine("Welcome to Helen's TicTacToe game!");
            Console.WriteLine(printer.Board());

            while (!game.IsFinished)
            {
                Console.WriteLine("It's " + printer.NameForPlayer(game.CurrentPlayer) + "'s turn!");
                game.PlayTurn();

                Console.WriteLine(printer.Board());
            }

            Console.WriteLine("Game over!");
            Console.WriteLine(printer.WinnerMessage());
            Console.ReadLine();
        }