public void PrintGameBoard() { GameBoardManager gameBoardManager = new GameBoardManager(); gameBoardManager.GenerateNewGameBoard(); StringBuilder gameBoardAsString = new StringBuilder(); StringBuilder printed = new StringBuilder(); StringBuilder current = new StringBuilder(); gameBoardAsString.AppendLine(); for (int col = 0; col < 8; col++) { for (int row = 0; row < 25; row++) { gameBoardAsString.Append(gameBoardManager.GameBoard[row, col]); } gameBoardAsString.AppendLine(); } Console.SetOut(new System.IO.StringWriter(printed)); gameBoardManager.PrintGameBoard(); Console.SetOut(new System.IO.StringWriter(current)); Console.WriteLine(gameBoardAsString); Assert.AreEqual(current.ToString(), printed.ToString()); }
public void RemainingBaloons_OneShot() { GameBoardManager gameBoardManager = new GameBoardManager(); gameBoardManager.GenerateNewGameBoard(); string input = "0 0"; Coordinates coordinates = new Coordinates(); Coordinates.TryParse(input, ref coordinates); gameBoardManager.ShootBaloons(coordinates); Assert.IsTrue(gameBoardManager.RemainingBaloons < 50); }
/// <summary> /// Main method make initialization of main classes, call engine to start the game and print welcome message. /// </summary> internal static void Main() { PrintWelcomeMessage(); GameBoardManager gameBoardManager = new GameBoardManager(); gameBoardManager.GenerateNewGameBoard(); gameBoardManager.PrintGameBoard(); Engine egine = new Engine(); egine.Run(gameBoardManager); }
/// <summary> /// Run method start and control game logic. /// </summary> /// <param name="gameBoardManager">Take instance of GameBoardManager from the main method.</param> public void Run(GameBoardManager gameBoardManager) { this.gameBoardManager = gameBoardManager; bool isCoordinates; bool isCommand; Coordinates coordinates = new Coordinates(); Command command = new Command(); //TopScore topScore = new TopScore(); TopScore.Instance.OpenTopScoreList(); while (this.gameBoardManager.RemainingBaloons > 0) { Console.Write("Enter a row and column: "); string consoleInput = Console.ReadLine(); isCoordinates = Coordinates.TryParse(consoleInput, ref coordinates); isCommand = Command.TryParse(consoleInput, ref command); if (isCoordinates) { try { this.gameBoardManager.ShootBaloons(coordinates); } catch (PopedBallonException exp) { Console.WriteLine(exp.Message); } this.gameBoardManager.PrintGameBoard(); } else if (isCommand) { switch (command.Value) { case CommandTypes.top: TopScore.Instance.PrintScoreList(); break; case CommandTypes.restart: this.gameBoardManager.GenerateNewGameBoard(); this.gameBoardManager.PrintGameBoard(); break; case CommandTypes.exit: return; } } else { Console.WriteLine("The input isn't in correct format!"); } } this.CheckTopScore(); }
public void ShootBaloons_CoordinatesTwoOne() { GameBoardManager gameBoardManager = new GameBoardManager(); gameBoardManager.GenerateNewGameBoard(); string input = "2 1"; Coordinates coordinates = new Coordinates(); Coordinates.TryParse(input, ref coordinates); gameBoardManager.ShootBaloons(coordinates); char arr = gameBoardManager.GameBoard[6, 2]; char result = '.'; Assert.AreEqual(result, arr); }
public void ShootCounter_ThreeShoots() { GameBoardManager gameBoardManager = new GameBoardManager(); gameBoardManager.GenerateNewGameBoard(); string input = "0 0"; Coordinates coordinates = new Coordinates(); Coordinates.TryParse(input, ref coordinates); gameBoardManager.ShootBaloons(coordinates); input = "1 1"; Coordinates.TryParse(input, ref coordinates); gameBoardManager.ShootBaloons(coordinates); input = "2 2"; Coordinates.TryParse(input, ref coordinates); gameBoardManager.ShootBaloons(coordinates); Assert.AreEqual(3, gameBoardManager.ShootCounter); }
public void ShootBaloons_HitPosition() { GameBoardManager gameBoardManager = new GameBoardManager(); gameBoardManager.GenerateNewGameBoard(); string input = "2 1"; Coordinates coordinates = new Coordinates(); Coordinates.TryParse(input, ref coordinates); gameBoardManager.ShootBaloons(coordinates); input = "0 1"; Coordinates.TryParse(input, ref coordinates); gameBoardManager.ShootBaloons(coordinates); }