예제 #1
0
        public void TestDisplayBoard()
        {
            string expected = string.Format("---{0}---{0}---{0}", Environment.NewLine);

            GenericGameState state = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.AreEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is different to actual");
        }
예제 #2
0
        public void TestGameHasStarted()
        {
            GenericGameState state = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);
            Space s = game.SpaceAt(2, 0);

            Assert.IsFalse(game.HasStarted());
            s.State = SpaceState.O;
            Assert.IsTrue(game.HasStarted());
        }
예제 #3
0
        public void TestGameHasFinished()
        {
            GenericGameState state = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.IsFalse(game.HasFinished());
            foreach(Space s in game.Spaces) {
                s.State = SpaceState.X;
            }

            Assert.IsTrue(game.HasFinished());
        }
예제 #4
0
        public void TestBoardUpdates()
        {
            string expected = string.Format("--X{0}-O-{0}X--{0}", Environment.NewLine);

            GenericGameState state = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.AreNotEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is the same as actual, shouldn't be");
            game.SpaceAt(2, 0).State = SpaceState.X;
            game.SpaceAt(1, 1).State = SpaceState.O;
            game.SpaceAt(0, 2).State = SpaceState.X;
            Assert.AreEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is different to actual");
        }
예제 #5
0
        public void TestWinDetection()
        {
            string expected = string.Format("--X{0}-OX{0}O-X{0}", Environment.NewLine);

            GenericGameState state = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();

            Game3x3 game = new Game3x3(state, drawer, null, null);

            Assert.AreNotEqual(expected, game.GameDrawer.DrawBoardToString(game), "Expected board is the same as actual, shouldn't be");
            game.SpaceAt(2, 0).State = SpaceState.X;
            game.SpaceAt(1, 1).State = SpaceState.O;
            game.SpaceAt(0, 2).State = SpaceState.O;
            game.SpaceAt(2, 1).State = SpaceState.X;
            Assert.IsFalse(game.WinDetected(), "Should have not detected a winning row");
            game.SpaceAt(2, 2).State = SpaceState.X;
            Assert.IsTrue(game.WinDetected(), "Should have detected the winning row");
        }
예제 #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Super-Awesome TicTacToe!!");
            Console.WriteLine();
            Console.Write("Any key to start");
            Console.ReadKey();

            // Create these objects and inject them into the game object, such
            // that the game has no idea about where it's drawing to, or what kind of players
            // are playing (Human / Computer etc)
            GenericGameState gameState = new GenericGameState();
            ConsoleGameDrawer drawer = new ConsoleGameDrawer();
            ComputerPlayer player1 = new ComputerPlayer("Jim", SpaceState.X);
            ComputerPlayer player2 = new ComputerPlayer("Susan", SpaceState.O);

            Game3x3 game = new Game3x3(gameState, drawer, player1, player2);

            RunGame(game);
        }