public CoordinatesTests()
 {
     this.coordinates = new Coordinates();
 }
Пример #2
0
        /// <summary>
        /// Processes the input.
        /// </summary>
        /// <param name="input">The input string to be processed.</param>
        private void ProcessInput(string input)
        {
            ICoordinates coordinates = new Coordinates();

            if (this.CommandValidator.IsValidCommand(input))
            {
                ICommand command = this.Factory.CreateCommand(this.CommandValidator.GetType(input));
                command.Execute(this.Context);
            }
            else if (coordinates.TryParse(input))
            {
                string msg = GlobalMessages.RowColMsg;

                try
                {
                    this.SaveLastStateOfGame();

                    this.GameLogic.ShootBalloonAtPosition(coordinates);
                }
                catch (ArgumentException ex)
                {
                    msg = ex.Message;
                }

                this.Printer.PrintGameBoard(this.GameLogic.Game.Field);
                this.Printer.PrintMessage(msg);
            }
            else
            {
                this.Printer.PrintGameBoard(this.GameLogic.Game.Field);
                this.Printer.PrintMessage(GlobalMessages.InvalidCommandMsg);
            }
        }
        /// <summary>
        /// Shoots same balloons in a direction.
        /// </summary>
        /// <param name="direction">The direction to shoot - left, right, up or down.</param>
        /// <param name="startingPoint">The starting coordinates.</param>
        /// <param name="balloonToShoot">The type of the balloon.</param>
        private void ShootSameBalloonsInDirection(ShootingDirection direction, ICoordinates startingPoint, char balloonToShoot)
        {
            ICoordinates nextCoordinates = new Coordinates();
            nextCoordinates.X = startingPoint.X;
            nextCoordinates.Y = startingPoint.Y;

            switch (direction)
            {
                case ShootingDirection.Left:
                    {
                        nextCoordinates.X--;
                        break;
                    }

                case ShootingDirection.Right:
                    {
                        nextCoordinates.X++;
                        break;
                    }

                case ShootingDirection.Up:
                    {
                        nextCoordinates.Y--;
                        break;
                    }

                case ShootingDirection.Down:
                    {
                        nextCoordinates.Y++;
                        break;
                    }
            }

            while (balloonToShoot == this.GetBaloonTypeFromPosition(nextCoordinates))
            {
                this.Game.Field.UpdateField(nextCoordinates, '.');
                this.Game.RemainingBalloons--;

                switch (direction)
                {
                    case ShootingDirection.Left:
                        {
                            nextCoordinates.X--;
                            break;
                        }

                    case ShootingDirection.Right:
                        {
                            nextCoordinates.X++;
                            break;
                        }

                    case ShootingDirection.Up:
                        {
                            nextCoordinates.Y--;
                            break;
                        }

                    case ShootingDirection.Down:
                        {
                            nextCoordinates.Y++;
                            break;
                        }
                }
            }
        }
        private char[,] ShootAt1x1(char[,] manualFieldBefor)
        {
            var gameFieldXLen = manualFieldBefor.GetLength(0);
            var gameFieldYLen = manualFieldBefor.GetLength(1);
            GameField gameField = new GameField(gameFieldXLen, gameFieldYLen);

            // fill the field with the manual chars
            for (int i = 0; i < gameFieldXLen; i++)
            {
                for (int j = 0; j < gameFieldYLen; j++)
                {
                    gameField[i, j] = manualFieldBefor[i, j];
                }
            }

            // Create game with custom field
            Game game = new Game(gameField);
            var logicProvider = new GameLogicProvider(game);

            // shoot 1x1
            Coordinates positionToShoot = new Coordinates(1, 1);
            logicProvider.ShootBalloonAtPosition(positionToShoot);

            return gameField.GetField();
        }
        /// <summary>
        /// Lands the flying balloons.
        /// </summary>
        private void LandFlyingBaloons()
        {
            for (int column = 0; column < this.Game.Field.FieldCols; column++)
            {
                for (int row = 0; row < this.Game.Field.FieldRows; row++)
                {
                    ICoordinates positionToCheck = new Coordinates(row, column);
                    if (this.GetBaloonTypeFromPosition(positionToCheck) == '.')
                    {
                        for (int k = row; k > 0; k--)
                        {
                            ICoordinates oldCoordinates = new Coordinates(k, column);
                            ICoordinates newCoordinates = new Coordinates(k - 1, column);

                            this.SwapBalloons(oldCoordinates, newCoordinates);
                        }
                    }
                }
            }
        }