public void PlayersMustMoveWithinTheTopLeftBoundsOfTheBoard() { var naughts = new TurnByTurnPlayerStub(); var game = new TicTacToeGame(naughts, null); naughts.Next(0, 0); Assert.Throws<InvalidMoveException>(() => game.PlayTurn()); }
public void NaughtsStartsTheGame() { var naughts = new TurnByTurnPlayerStub(); var game = new TicTacToeGame(naughts, null); naughts.Next(1, 1); game.PlayTurn(); Assert.That(game.PlayerOnSquare(1, 1), Is.EqualTo(naughts)); }
public void PlayersAlternateTurns() { var naughts = new TurnByTurnPlayerStub(); var crosses = new TurnByTurnPlayerStub(); var game = new TicTacToeGame(naughts, crosses); naughts.Next(1, 1); game.PlayTurn(); Assert.That(game.CurrentPlayer, Is.EqualTo(crosses)); }
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(" ")); }
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)); }
public void PlayersTurnIsNotOverUntilTheyMakeAValidMove() { var naughts = new TurnByTurnPlayerStub(); var crosses = new TurnByTurnPlayerStub(); var game = new TicTacToeGame(naughts, crosses); naughts.Next(1, 1); game.PlayTurn(); crosses.Next(1, 1); game.PlayTurn(); Assert.That(game.CurrentPlayer, Is.EqualTo(crosses)); }
public void OnlyOnePlayerCanClaimEachSquare() { var naughts = new TurnByTurnPlayerStub(); var crosses = new TurnByTurnPlayerStub(); var game = new TicTacToeGame(naughts, crosses); naughts.Next(1, 1); game.PlayTurn(); crosses.Next(1, 1); game.PlayTurn(); Assert.That(game.PlayerOnSquare(1, 1), Is.EqualTo(naughts)); }
public Form1() { InitializeComponent(); textBox1.ReadOnly = true; locationButtons[0].Click += (sender, e) => { Play(locationButtons[0], 0); }; locationButtons[1].Click += (sender, e) => { Play(locationButtons[1], 1); }; locationButtons[2].Click += (sender, e) => { Play(locationButtons[2], 2); }; locationButtons[3].Click += (sender, e) => { Play(locationButtons[3], 3); }; locationButtons[4].Click += (sender, e) => { Play(locationButtons[4], 4); }; locationButtons[5].Click += (sender, e) => { Play(locationButtons[5], 5); }; locationButtons[6].Click += (sender, e) => { Play(locationButtons[6], 6); }; locationButtons[7].Click += (sender, e) => { Play(locationButtons[7], 7); }; locationButtons[8].Click += (sender, e) => { Play(locationButtons[8], 8); }; resetButton.Click += (sender, e) => { Reset(); }; game = new TicTacToeGame(); Reset(); }
public TicTacToeGameTests() { TicTacToeBoard = Substitute.For<ITicTacToeBoard>(); Player1 = Substitute.For<ITicTacToePlayer>(); Player2 = Substitute.For<ITicTacToePlayer>(); GameJudge = Substitute.For<IGameJudge>(); GameRenderer = Substitute.For<IGameRenderer>(); GamePauser = Substitute.For<IGamePauser>(); Sut = new TicTacToeGame( TicTacToeBoard, Player1, Player2, GameJudge, GameRenderer, GamePauser ); }
public void ThreeInARightToLeftDiagonalWins() { var naughts = new PrepopulatedPlayerStub(new[] { new BoardPosition(1, 3), new BoardPosition(2, 2), new BoardPosition(3, 1), }); var crosses = new PrepopulatedPlayerStub(new[] { new BoardPosition(1, 2), new BoardPosition(3, 2), }); var game = new TicTacToeGame(naughts, crosses); game.Play(); Assert.That(game.IsFinished); Assert.That(game.Winner, Is.EqualTo(game.Naughts)); }
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(); }
public GameRunner() { ui = new ConsoleIO(); game = new TicTacToeGame(); }
public GameBoardPrinter(TicTacToeGame game) { _game = game; }
public void WhenBoardIsFullButNobodyHasWonPlayersDraw() { var naughts = new PrepopulatedPlayerStub(new[] { new BoardPosition(1, 1), new BoardPosition(1, 3), new BoardPosition(2, 1), new BoardPosition(3, 2), new BoardPosition(3, 3), }); var crosses = new PrepopulatedPlayerStub(new[] { new BoardPosition(1, 2), new BoardPosition(2, 2), new BoardPosition(2, 3), new BoardPosition(3, 1), }); var game = new TicTacToeGame(naughts, crosses); game.Play(); Assert.That(game.IsFinished); Assert.That(game.Winner, Is.EqualTo(null)); }