public void TryParse_InvalidCommand_ParseFailed() { string input = "alabala"; Command command = new Command(); bool result = Command.TryParse(input, ref command); Assert.IsFalse(result); }
private static bool ReadInput(out bool IsCoordinates, ref Coordinates coordinates, ref Command command) { Console.Write("Enter a row and column: "); string consoleInput = Console.ReadLine(); coordinates = new Coordinates(); command = new Command(); if (Command.TryParse(consoleInput, ref command)) { IsCoordinates = false; return true; } else if (Coordinates.TryParse(consoleInput, ref coordinates)) { IsCoordinates = true; return true; } else { IsCoordinates = false; return false; } }
public void TryParse_CommandTop_SetValue() { string input = "top"; Command command = new Command(); bool result = Command.TryParse(input, ref command); Assert.AreEqual(input,command.Value); }
public void TryParse_CommandTop_Parsed() { string input = "top"; Command command=new Command(); bool result = Command.TryParse(input, ref command); Assert.IsTrue(result); }
public void TryParse_CommandRestart_SetValue() { string input = "restart"; Command command = new Command(); Command.TryParse(input, ref command); Assert.AreEqual(input, command.Value.ToString()); }
/// <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(); }
/// <summary> /// Tries to parse the input. /// </summary> /// <param name="input">String that should be parsed.</param> /// <param name="command">Command that should be set a value.</param> /// <returns>Boolean value that shows is the parse successful.</returns> public static bool TryParse(string input, ref Command command) { bool parseResult = false; if (input == CommandTypes.top.ToString()) { command.Value = CommandTypes.top; parseResult = true; } else if (input == CommandTypes.restart.ToString()) { command.Value = CommandTypes.restart; parseResult = true; } else if (input == CommandTypes.exit.ToString()) { command.Value = CommandTypes.exit; parseResult = true; } return parseResult; }
public static bool TryParse(string input, ref Command result) { bool parseResult = false; if (input == "top") { result.Value = input; parseResult = true; } else if (input == "restart") { result.Value = input; parseResult = true; } else if (input == "exit") { result.Value = input; parseResult = true; } return parseResult; }
static void Main() { Console.WriteLine("Welcome to “Balloons Pops” game. Please try to pop the balloons. Use 'top' to view the top scoreboard, 'restart' to start a new game and 'exit' to quit the game."); GameBoard gameBoard = new GameBoard(); gameBoard.GenerateNewGameBoard(); Console.WriteLine(gameBoard.ToString()); TopScore.OpenTopScoreList(); bool isCoordinates; Coordinates coordinates = new Coordinates(); Command command = new Command(); while (gameBoard.RemainingBaloons > 0) { if (ReadInput(out isCoordinates, ref coordinates, ref command)) { if (isCoordinates) { try { gameBoard.ShootBaloons(coordinates); } catch (PopedBallonException exp) { Console.WriteLine(exp.Message); } Console.WriteLine(gameBoard.ToString()); } else { switch (command.Value) { case "top": { TopScore.PrintScoreList(); } break; case "restart": { gameBoard.GenerateNewGameBoard(); Console.WriteLine(gameBoard.ToString()); } break; case "exit": { return; } } } } else { Console.WriteLine("Wrong Input!"); } } Player player = new Player(); player.Score = gameBoard.ShootCounter; if (TopScore.IsTopScore(player)) { Console.WriteLine("Please enter your name for the top scoreboard: "); player.Name = Console.ReadLine(); TopScore.AddToTopScoreList(player); } TopScore.SaveTopScoreList(); TopScore.PrintScoreList(); }