示例#1
0
 public void TryParse_CommandTop_Parsed()
 {
     string input = "top";
     Command command = new Command();
     bool result = Command.TryParse(input, ref command);
     Assert.IsTrue(result);
 }
示例#2
0
 public void TryParse_CommandExit_SetValue()
 {
     string input = "exit";
     Command command = new Command();
     Command.TryParse(input, ref command);
     Assert.AreEqual(input, command.Value.ToString());
 }
示例#3
0
 public void TryParse_InvalidCommand_ParseFailed()
 {
     string input = "alabala";
     Command command = new Command();
     bool result = Command.TryParse(input, ref command);
     Assert.IsFalse(result);
 }
示例#4
0
        /// <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();
        }