static void Main(string[] args) { TicTacToe_engine.TicTacToeEngine engine = new TicTacToeEngine(); string[] numberbox = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; while (true) { Console.WriteLine("Type a number from 1-9, new or quit"); Console.WriteLine(engine.getGameStatusStringified()); Console.WriteLine(engine.Board()); string command = Console.ReadLine(); if (command == "quit") { break; } else if (command == "new") { engine.Reset(); } else if (numberbox.Contains(command)) { int convertedCommand = Int32.Parse(command) - 1; Boolean validCell = engine.ChooseCell(convertedCommand); if (!validCell) { Console.WriteLine("Invalid choice"); } } if (engine.getGameover()) { Console.WriteLine(engine.getGameStatusStringified()); engine.Reset(); } } }
public void WhenTheApplicationIsStarted_ThenItShouldDrawTheInitialInterface() { // Arrange var screenOutput = new List <string>(); var writer = new Mock <IOutputWriter>(); var outputAdapter = new OutputAdapter(writer.Object); writer.Setup(output => output.WriteLine(It.IsAny <string>())).Callback((string s) => screenOutput.Add(s)); var ticTacToeEngine = new TicTacToeEngine(); var game = new Game(outputAdapter, ticTacToeEngine, _firstPlayer, _secondPlayer); // Act game.Start(); // Assert Assert.Equal("Deep Blue is playing X, Garry Kasparov is playing O\n", screenOutput.ElementAt(0)); Assert.Equal(" | | ", screenOutput.ElementAt(1)); Assert.Equal(" | | ", screenOutput.ElementAt(2)); Assert.Equal("_____|_____|_____ ", screenOutput.ElementAt(3)); Assert.Equal(" | | ", screenOutput.ElementAt(4)); Assert.Equal(" | | ", screenOutput.ElementAt(5)); Assert.Equal("_____|_____|_____ ", screenOutput.ElementAt(6)); Assert.Equal(" | | ", screenOutput.ElementAt(7)); Assert.Equal(" | | ", screenOutput.ElementAt(8)); Assert.Equal(" | | ", screenOutput.ElementAt(9)); Assert.Equal("\nThe atmosphere is tense, press any key to start the game...", screenOutput.ElementAt(10)); // Unusual for me to be checking view content like this, would normally use a tool like selenium in a web environment // Unusual for me to be checking multiple things with positioning, however it seems the logical choice in this instance }
static void Main(string[] args) { var player1 = new EasyPlayer(); var player2 = new PostEasterPlayer(); TicTacToeEngine.PlayGame(player1, player2); Console.ReadLine(); }
public void StartNewRound() { IsGameOver = false; foreach (PlayerData p in playerData) { p.PlayerReference.NewGameState( ); } Game = new TicTacToeEngine(gridData.GridReference, p1Data.PlayerReference, p2Data.PlayerReference); }
public async Task SendMark(int i, int j, string roomUuid, Player player) { var board = await cache.GetAsync <TicTacToeBoard>(roomUuid); board = TicTacToeEngine.AddMark(player.Uuid, i, j, board); await cache.SaveAsync(roomUuid, board); await Clients.Client(board.FirstPlayer.ConnectionId).SendAsync("board", board); await Clients.Client(board.SecondPlayer.ConnectionId).SendAsync("board", board); }
public async Task CreateRoom(Player player) { var roomUuid = player.Uuid; player.ConnectionId = Context.ConnectionId; player.ConnectedGameUuid = roomUuid; var board = TicTacToeEngine.InitializeBoard(player); await cache.SaveAsync(roomUuid, board); await cache.SaveAsync(player.ConnectionId, player); await Clients.Caller.SendAsync("board", board); }
public void WhenTheGameIsOver_ThenItShouldDisplayTheResultOfTheGame() { // Arrange var outputAdapter = new Mock <IOutputAdapter>(); var ticTacToeEngine = new TicTacToeEngine(); var game = new Game(outputAdapter.Object, ticTacToeEngine, _firstPlayer, _secondPlayer); // Act game.Start(); // Assert outputAdapter.Verify(adapter => adapter.WriteGameOver(It.IsAny <bool>(), It.IsAny <string>()), Times.Once); }
public void WhenTheGameIsOver_ThenItShouldOfferToStartAnotherGame() { // Arrange var outputAdapter = new Mock <IOutputAdapter>(); var ticTacToeEngine = new TicTacToeEngine(); var game = new Game(outputAdapter.Object, ticTacToeEngine, _firstPlayer, _secondPlayer); // Act game.Start(); // Assert outputAdapter.Verify(adapter => adapter.StartAnotherGame(), Times.Once); }
public void WhenTheApplicationIsStarted_ThenItShouldPromptTheUserToStart() { // Arrange var outputAdapter = new Mock <IOutputAdapter>(); var ticTacToeEngine = new TicTacToeEngine(); var game = new Game(outputAdapter.Object, ticTacToeEngine, _firstPlayer, _secondPlayer); // Act game.Start(); // Assert outputAdapter.Verify(adapter => adapter.StartGamePrompt(), Times.Once); }
static void Main() { //We maken een instantie van de TicTacToeEngine en we setten de status naar PlayerOPlays om het simpel te houden. TicTacToeEngine engine = new TicTacToeEngine() { Status = TicTacToeEngine.GameStatus.PlayerOPlays }; Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(engine)); }
public IGameInterface CreateGame(Player playerOne, Player playerTwo) { switch (playerOne.CurrentGameType) { case "TicTacToe": IGameInterface game = new TicTacToeEngine(playerOne, playerTwo); game.MatchId = Guid.NewGuid().ToString(); return(game); case "Othello": return(null); default: return(null); } }
public void WhenMovesAreMade_ThenItShouldWaitForOneSecond() { // Arrange var waitCount = 0; var outputAdapter = new Mock <IOutputAdapter>(); outputAdapter.Setup(adapter => adapter.Wait(It.IsAny <int>())).Callback(() => waitCount++); var ticTacToeEngine = new TicTacToeEngine(); var game = new Game(outputAdapter.Object, ticTacToeEngine, _firstPlayer, _secondPlayer, 1000); // Act game.Start(); // Assert Assert.Equal(ticTacToeEngine.Moves.Count, waitCount); }
static void Main(string[] args) { TicTacToeEngine t = new TicTacToeEngine(); while (!t.Status.Equals(GameStatus.Equal) || !t.Status.Equals(GameStatus.PlayerOWins) || !t.Status.Equals(GameStatus.PlayerXWins)) { Console.WriteLine("Type a number from 1-9, new or quit"); Console.WriteLine("Status: " + t.Status); Console.WriteLine(t.Board()); string x = Console.ReadLine(); if (!string.IsNullOrEmpty(x)) { if (x == "new") { t.Reset(); continue; } if (x == "quit") { Environment.Exit(0); } int parsedInt; if (int.TryParse(x, out parsedInt)) { if (!t.ChooseCell(parsedInt)) { Console.WriteLine("Invalid Choice"); } } else { Console.WriteLine("Invalid Choice"); } } else { Console.WriteLine("Invalid Choice"); } } }
public void WhenMovesAreMade_ThenItShouldUpdateTheBoard() { // Arrange var nonMoveRelatedBoardRefreshes = 1; var boardRefreshes = 0; var outputAdapter = new Mock <IOutputAdapter>(); outputAdapter.Setup(adapter => adapter.WriteBoard(It.IsAny <char[]>())).Callback(() => boardRefreshes++); var ticTacToeEngine = new TicTacToeEngine(); var game = new Game(outputAdapter.Object, ticTacToeEngine, _firstPlayer, _secondPlayer); // Act game.Start(); // Assert Assert.Equal(ticTacToeEngine.Moves.Count + nonMoveRelatedBoardRefreshes, boardRefreshes); }
private static void processTurn(TicTacToeEngine engine, int pos) { if (engine.board[pos - 1].Equals(pos.ToString())) { engine.setPos(pos); String status = engine.getGameStatus(); if (status.Equals("X wins!") || (status.Equals("O wins!")) || (status.Equals("Draw"))) { writeBoard(engine.board); Console.WriteLine(status, status, status); engine.reset(); } } else { Console.WriteLine("This field has already been taken"); } }
public async Task JoinRoom(Player player, string roomUuid) { var board = await cache.GetAsync <TicTacToeBoard>(roomUuid); if (board == null) { await Clients.Caller.SendAsync("error", "room not found"); } player.ConnectionId = Context.ConnectionId; player.ConnectedGameUuid = roomUuid; var newBoard = TicTacToeEngine.AddSecondPlayer(player, board); await cache.SaveAsync(player.ConnectionId, player); await cache.SaveAsync(roomUuid, newBoard); await Clients.Client(newBoard.FirstPlayer.ConnectionId).SendAsync("board", newBoard); await Clients.Client(newBoard.SecondPlayer.ConnectionId).SendAsync("board", newBoard); }
public void WhenPlayStarts_ThePlayShouldAlternateBetweenPlayers() { // Arrange var writer = new Mock <IOutputWriter>(); var outputAdapter = new OutputAdapter(writer.Object); var ticTacToeEngine = new TicTacToeEngine(); var game = new Game(outputAdapter, ticTacToeEngine, _firstPlayer, _secondPlayer); // Act game.Start(); // Assert var firstPlayerMoves = ticTacToeEngine.Moves.Where((item, index) => index % 2 == 0); Assert.True(firstPlayerMoves.SequenceEqual(_firstPlayer.Moves)); var secondPlayerMoves = ticTacToeEngine.Moves.Where((item, index) => index % 2 != 0); Assert.True(secondPlayerMoves.SequenceEqual(_secondPlayer.Moves)); }
static void Main(string[] args) { TicTacToeEngine t = new TicTacToeEngine(); Console.WriteLine(t.Board()); for (; ;) { Console.WriteLine(t.Status); Console.WriteLine("Select the cell of your choosing:"); int s = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("your input is {0}.", s); bool result = t.ChooseCell(s); if (t.Status == TicTacToeEngine.GameStatus.PlayerOWins) { Console.WriteLine("Congrats, {0}", t.Status); Console.WriteLine(t.Board()); break; } else if (t.Status == TicTacToeEngine.GameStatus.PlayerXWins) { Console.WriteLine("Congrats, {0}", t.Status); Console.WriteLine(t.Board()); break; } else if (t.Status == TicTacToeEngine.GameStatus.Equal) { Console.WriteLine("Unfortunately no one won!"); Console.WriteLine(t.Board()); break; } else { Console.WriteLine(t.Board()); continue; } } Console.WriteLine("Spel is afgelopen"); }
public Program() { t = new TicTacToeEngine(); }
static void Main(string[] args) { TicTacToeEngine t = new TicTacToeEngine(); while (true) { Console.WriteLine("Type a number from 0-8, new or quit"); Console.WriteLine(t.status); Console.WriteLine(t.Board()); string input = Console.ReadLine(); if (input == "new") { t.Reset(); Console.WriteLine(); continue; } if (input == "quit") { break; } try { int cellIndex = Int32.Parse(input); if (t.ChooseCell(cellIndex)) { switch (t.status) { case TicTacToeEngine.GameStatus.Equal: Console.WriteLine(); Console.WriteLine("It's a tie!"); Console.WriteLine(t.Board()); t.Reset(); break; case TicTacToeEngine.GameStatus.PlayerOWins: Console.WriteLine(); Console.WriteLine("Player O wins!"); Console.WriteLine(t.Board()); t.Reset(); break; case TicTacToeEngine.GameStatus.PlayerXWins: Console.WriteLine(); Console.WriteLine("Player X wins!"); Console.WriteLine(t.Board()); t.Reset(); break; } } else { Console.WriteLine("Invalid Choice."); } } catch { Console.WriteLine("Invalid Choice."); } Console.WriteLine(); } }
public Form1(TicTacToeEngine engine) { this.engine = engine; InitializeComponent(); }
public TicTacToeCli() { TicTacToeGame = new TicTacToeEngine(); }
static void Main() { //We maken een instantie van de TicTacToeEngine en we setten de status naar PlayerOPlays om het simpel te houden. TicTacToeEngine engine = new TicTacToeEngine() { Status = TicTacToeEngine.GameStatus.PlayerOPlays }; //Deze while loop zal gedurende het hele spel actief zijn. Pas als de applicatie wordt afgesloten zal hij stoppen. while (true) { //Hier vragen we om een invoer en laten we het bord zien. Console.WriteLine("Type a number from 1-9, new or quit"); Console.WriteLine("Status: " + engine.Status); Console.WriteLine(engine.Board()); string next = Console.ReadLine(); //Hier wordt de inhoud van de invoer gecontroleerd. switch (next) { //Als de invoer "new" is, zal het spel en het bord worden gereset. case "new": engine.Reset(); break; //Als de invoer "new" is, zal de applicatie worden afgesloten. case "quit": Environment.Exit(0); break; //Als de waarde iets anders is (in het goede geval een 1-9 cijfer, anders returned hij een foutmelding), zal deze worden geconverteert naar een int en wordt de cel gevuld. default: try { Int32.TryParse(next, out int cel); engine.ChooseCell(cel); } catch (FormatException) { Console.WriteLine("Invalid Choice."); } break; } //Deze switch case update de status tekst aan de hand van welke status actief is. Omdat het in de while loop draait, zal het altijd updaten indien nodig. switch (engine.Status) { case (TicTacToeEngine.GameStatus.PlayerOWins): Console.WriteLine("Congratulations to player O, you win!"); Console.WriteLine(engine.Board()); Console.WriteLine("---------------------------------------------------"); engine.Reset(); break; case (TicTacToeEngine.GameStatus.PlayerXWins): Console.WriteLine("Congratulations to player X, you win!"); Console.WriteLine(engine.Board()); Console.WriteLine("---------------------------------------------------"); engine.Reset(); break; case (TicTacToeEngine.GameStatus.Equal): Console.WriteLine("Too bad, no one wins!"); Console.WriteLine(engine.Board()); Console.WriteLine("---------------------------------------------------"); engine.Reset(); break; } } }
static void Main(string[] args) { TicTacToeEngine engine = new TicTacToeEngine(); String[] board = engine.board; bool active = true; bool isValid = true; Console.WriteLine("Type 1-9 + enter to pick a field. You can reset the game with 'reset' and you can quit the application with 'quit'"); while (active) { if (isValid) { writeBoard(board); Console.WriteLine(engine.getGameStatus()); } isValid = true; String input = Console.ReadLine(); if (String.Equals(input, "1", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 1); } else if (String.Equals(input, "2", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 2); } else if (String.Equals(input, "3", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 3); } else if (String.Equals(input, "4", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 4); } else if (String.Equals(input, "5", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 5); } else if (String.Equals(input, "6", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 6); } else if (String.Equals(input, "7", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 7); } else if (String.Equals(input, "8", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 8); } else if (String.Equals(input, "9", StringComparison.OrdinalIgnoreCase)) { processTurn(engine, 9); } else if (String.Equals(input, "reset", StringComparison.OrdinalIgnoreCase)) { engine.reset(); Console.WriteLine("Game has been reset"); } else if (String.Equals(input, "quit", StringComparison.OrdinalIgnoreCase)) { active = false; } else { Console.WriteLine("\"" + input + "\" is not a valid command. Please type a number ranging from 1 to 9, 'reset' or 'quit'"); isValid = false; } } }