Пример #1
0
 public void Row_PropertieGet()
 {
     string input = "3 0";
     Coordinates coordinates = new Coordinates();
     Coordinates.TryParse(input, ref coordinates);
     Assert.AreEqual(3, coordinates.Row);
 }
Пример #2
0
 public void TryParse_InvalidCol_ParsedFailed()
 {
     string input = "3 10";
     Coordinates coordinates = new Coordinates();
     bool result = Coordinates.TryParse(input, ref coordinates);
     Assert.IsFalse(result);
 }
Пример #3
0
 public void TryParse_InvalidCol_NotNumber()
 {
     string input = "4 z";
     Coordinates coordinates = new Coordinates();
     bool result = Coordinates.TryParse(input, ref coordinates);
     Assert.IsFalse(result);
 }
Пример #4
0
 public void TryParse_InputCountIsDifferentFromTwo_ParsedFailed()
 {
     string input = "3    4";
     Coordinates coordinates = new Coordinates();
     bool result = Coordinates.TryParse(input, ref coordinates);
     Assert.IsFalse(result);
 }
Пример #5
0
 public void TryParse_InputCountIsTwo_Parsed()
 {
     string input = "3 4";
     Coordinates coordinates = new Coordinates();
     bool result = Coordinates.TryParse(input, ref coordinates);
     Assert.IsTrue(result);
 }
Пример #6
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();
        }
Пример #7
0
 public void ShootBaloons_CoordinatesFourFour()
 {
     GameBoardManager gameBoardManager = new GameBoardManager();
     gameBoardManager.GenerateNewGameBoard();
     string input = "4 4";
     Coordinates coordinates = new Coordinates();
     Coordinates.TryParse(input, ref coordinates);
     gameBoardManager.ShootBaloons(coordinates);
     char arr = gameBoardManager.GameBoard[12, 2];
     char result = '.';
     Assert.AreEqual(result, arr);
 }
Пример #8
0
        /// <summary>
        /// Tries to parse the input.
        /// </summary>
        /// <param name="input">String that should be parsed.</param>
        /// <param name="result">Coordinates that should be set a value.</param>
        /// <returns>Boolean value that shows is the parse successful.</returns>
        public static bool TryParse(string input, ref Coordinates result)
        {
            char[] separators = { ' ', ',' };
            string[] substrings = input.Split(separators);

            if (substrings.Count<string>() != 2)
            {
                return false;
            }

            string coordinateRow = substrings[0].Trim();
            int row;
            if (int.TryParse(coordinateRow, out row))
            {
                if (row >= 0 && row <= MaxRows)
                {
                    result.Row = row;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }

            string coordinateCol = substrings[1].Trim();
            int col;
            if (int.TryParse(coordinateCol, out col))
            {
                if (col >= 0 && col <= MaxCols)
                {
                    result.Col = col;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }

            return true;
        }
Пример #9
0
        /// <summary>
        /// Method for creating new game board
        /// </summary>
        public void GenerateNewGameBoard()
        {
            this.FillBlankGameBoard();

            Random randomGenerator = new Random();
            Coordinates coordinates = new Coordinates();
            for (int col = 0; col < 10; col++)
            {
                for (int row = 0; row < 5; row++)
                {
                    coordinates.Col = col;
                    coordinates.Row = row;
                    char ballonColor = (char)(randomGenerator.Next(1, 5) + (int)'0');
                    this.AddNewBaloonToGameBoard(coordinates, ballonColor);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Method for count and mark hit vertical balloons 
        /// </summary>
        /// <param name="currentCoordinates">Position of the user hit.</param>
        /// <param name="currentBaloon">Balloon color of user hit.</param>
        private void PopLeftAndRightNeighbor(Coordinates currentCoordinates, char currentBaloon)
        {
            Coordinates neighborCoordinates = new Coordinates();

            neighborCoordinates.Col = currentCoordinates.Col - 1;
            neighborCoordinates.Row = currentCoordinates.Row;
            while (currentBaloon == this.GetBaloonColor(neighborCoordinates))
            {
                this.AddNewBaloonToGameBoard(neighborCoordinates, '.');
                this.baloonCounter--;
                neighborCoordinates.Col--;
            }

            neighborCoordinates.Col = currentCoordinates.Col + 1;
            neighborCoordinates.Row = currentCoordinates.Row;
            while (currentBaloon == this.GetBaloonColor(neighborCoordinates))
            {
                this.AddNewBaloonToGameBoard(neighborCoordinates, '.');
                this.baloonCounter--;
                neighborCoordinates.Col++;
            }
        }
Пример #11
0
 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);
 }
Пример #12
0
 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);
 }
Пример #13
0
 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);
 }
Пример #14
0
        /// <summary>
        /// Method for count and mark hit balloons
        /// </summary>
        /// <param name="currentCoordinates">Position of the user hit.</param>
        public void ShootBaloons(Coordinates currentCoordinates)
        {
            char currentBaloon;
            currentBaloon = this.GetBaloonColor(currentCoordinates);

            if (currentBaloon < '1' || currentBaloon > '4')
            {
                throw new BaloonsPop.Exceptions.PopedBallonException("Cannot pop missing ballon!");
            }

            this.AddNewBaloonToGameBoard(currentCoordinates, '.');
            this.baloonCounter--;

            this.PopLeftAndRightNeighbor(currentCoordinates, currentBaloon);

            this.PopUpAndDownNeighbors(currentCoordinates, currentBaloon);

            this.shootCounter++;
            this.LandFlyingBaloons();
        }
Пример #15
0
 /// <summary>
 /// Method for moving down on free spaces balloons
 /// </summary>
 private void LandFlyingBaloons()
 {
     Coordinates currentCoordinates = new Coordinates();
     for (int col = 0; col < 10; col++)
     {
         for (int row = 0; row <= 4; row++)
         {
             currentCoordinates.Col = col;
             currentCoordinates.Row = row;
             if (this.GetBaloonColor(currentCoordinates) == '.')
             {
                 for (int rowIndex = row; rowIndex > 0; rowIndex--)
                 {
                     Coordinates oldCoordinates = new Coordinates();
                     Coordinates newCoordinates = new Coordinates();
                     oldCoordinates.Col = col;
                     oldCoordinates.Row = rowIndex;
                     newCoordinates.Col = col;
                     newCoordinates.Row = rowIndex - 1;
                     this.SwapBaloonsPosition(oldCoordinates, newCoordinates);
                 }
             }
         }
     }
 }
Пример #16
0
 /// <summary>
 /// Method for swap balloons position.
 /// </summary>
 /// <param name="currentCoordinates">Current coordinate</param>
 /// <param name="newCoordinates">New coordinate for swap</param>
 private void SwapBaloonsPosition(Coordinates currentCoordinates, Coordinates newCoordinates)
 {
     char currentBallon = this.GetBaloonColor(currentCoordinates);
     this.AddNewBaloonToGameBoard(currentCoordinates, this.GetBaloonColor(newCoordinates));
     this.AddNewBaloonToGameBoard(newCoordinates, currentBallon);
 }
Пример #17
0
 /// <summary>
 /// Method for adding balloon on exact coordinates
 /// </summary>
 /// <param name="coordinates">Exact coordinates for adding balloon on game board</param>
 /// <param name="ballonColor">Balloon color</param>
 private void AddNewBaloonToGameBoard(Coordinates coordinates, char ballonColor)
 {
     int xPosition, yPosition;
     xPosition = 4 + (coordinates.Col * 2);
     yPosition = 2 + coordinates.Row;
     this.gameBoard[xPosition, yPosition] = ballonColor;
 }
Пример #18
0
        /// <summary>
        /// Method for count and mark hit horizontal balloons 
        /// </summary>
        /// <param name="currentCoordinates">Position of the user hit.</param>
        /// <param name="currentBaloon">Balloon color of user hit.</param>
        private void PopUpAndDownNeighbors(Coordinates currentCoordinates, char currentBaloon)
        {
            Coordinates neighborCoordinates = new Coordinates();

            neighborCoordinates.Col = currentCoordinates.Col;
            neighborCoordinates.Row = currentCoordinates.Row - 1;
            while (currentBaloon == this.GetBaloonColor(neighborCoordinates))
            {
                this.AddNewBaloonToGameBoard(neighborCoordinates, '.');
                this.baloonCounter--;
                neighborCoordinates.Row--;
            }

            neighborCoordinates.Col = currentCoordinates.Col;
            neighborCoordinates.Row = currentCoordinates.Row + 1;
            while (currentBaloon == this.GetBaloonColor(neighborCoordinates))
            {
                this.AddNewBaloonToGameBoard(neighborCoordinates, '.');
                this.baloonCounter--;
                neighborCoordinates.Row++;
            }
        }
Пример #19
0
        /// <summary>
        /// Get color of balloon on exact coordinates
        /// </summary>
        /// <param name="coordinates">Coordinates on game board</param>
        /// <returns>Balloon color assign to asked coordinates</returns>
        private char GetBaloonColor(Coordinates coordinates)
        {
            int xPosition = 4 + (coordinates.Col * 2);
            int yPosition = 2 + coordinates.Row;

            char ballonColor = this.gameBoard[xPosition, yPosition];
            return ballonColor;
        }