public void TestNextMoveGameFinished() { GenericGameState state = new GenericGameState(); ComputerPlayer player1 = new ComputerPlayer("Jim", SpaceState.X); ComputerPlayer player2 = new ComputerPlayer("Denise", SpaceState.X); Game3x3 game = new Game3x3(state, null, player1, player2); finishGame(game); Assert.IsNull(player1.NextMove(game), "Should return null as there are no spaces"); }
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"); }
public void TestGetNextMove() { GenericGameState state = new GenericGameState(); ComputerPlayer player1 = new ComputerPlayer("Jim", SpaceState.X); ComputerPlayer player2 = new ComputerPlayer("Denise", SpaceState.X); Game3x3 game = new Game3x3(state, null, player1, player2); Space s = player1.NextMove(game); Assert.IsNotNull(s, "Should have returned an actual space"); }
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()); }
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()); }
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"); }
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"); }
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); }