Ejemplo n.º 1
0
        public IList CreateObjects()
        {
            List<IRenderable> balloons = new List<IRenderable>();

            Array colours = Enum.GetValues(typeof(Colour));

            for (int row = 0; row < Constants.MaximalYPosition; row += Constants.IterationStep)
            {
                for (int column = 0; column < Constants.MaximalXPosition; column += Constants.IterationStep)
                {
                    Position position = new Position(column + Constants.XOffset, row + Constants.YOffset);

                    int randomisedBalloonNumber = RandomNumberGenerator.Instance.Next(this.balloonVisualisations.Length);

                    char visualisation = this.balloonVisualisations[randomisedBalloonNumber];

                    Colour colour = (Colour)colours.GetValue(randomisedBalloonNumber);

                    Balloon balloon = new Balloon(position, visualisation, colour);

                    balloons.Add(balloon);
                }
            }

            return balloons;
        }
        public IList CreateObjects()
        {
            List<IRenderable> immovableObjects = new List<IRenderable>();

            for (int row = 0; row < Constants.MaximalYPosition; row += Constants.IterationStep)
            {
                Position position = new Position(XOffset, row + Constants.YOffset);

                char visualisation = this.immovableObjectVisualisations[(row >> 1)];

                ImmovableObject immovableObject = new ImmovableObject(position, visualisation);

                immovableObjects.Add(immovableObject);
            }

            for (int column = 0; column < Constants.MaximalXPosition; column += Constants.IterationStep)
            {
                Position position = new Position(column + Constants.XOffset, YOffset);

                char visualisation = this.immovableObjectVisualisations[(column >> 1)];

                ImmovableObject immovableObject = new ImmovableObject(position, visualisation);

                immovableObjects.Add(immovableObject);
            }

            return immovableObjects;
        }
Ejemplo n.º 3
0
        private void AmendObjectsAbove(GameObject originObject)
        {
            Position originPosition = originObject.Position;

            for (int index = originPosition.Y - Constants.IterationStep; index >= 0; index -= Constants.IterationStep)
            {
                Position position = new Position(originPosition.X, index);

                foreach (GameObject gameObject in this.gameObjects)
                {
                    if (gameObject.Position == position && gameObject is Balloon)
                    {
                        Balloon balloon = gameObject as Balloon;

                        Position vectorChange = new Position(0, Constants.IterationStep);

                        balloon.UpdatePosition(vectorChange);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void PopBalloon(Position popPosition)
        {
            bool balloonFound = false;
            char balloonVisualisation = '0';

            foreach (Balloon balloon in this.balloons)
            {
                if (balloon.Position == popPosition)
                {
                    balloonFound = true;
                    balloonVisualisation = balloon.Visualisation;
                    balloon.RespondToInteraction();
                    break;
                }
            }

            if (!balloonFound)
            {
                throw new InvalidOperationException("Balloon is already popped.");
            }
            else
            {
                // Left
                for (int index = popPosition.X - Constants.IterationStep; index >= Constants.XOffset; index -= Constants.IterationStep)
                {
                    Position collateralPosition = new Position(index, popPosition.Y);

                    if (!this.CanPopCollateral(collateralPosition, balloonVisualisation))
                    {
                        break;
                    }
                }

                // Right
                for (int index = popPosition.X + Constants.IterationStep; index < Constants.XOffset + Constants.MaximalXPosition; index += Constants.IterationStep)
                {
                    Position collateralPosition = new Position(index, popPosition.Y);

                    if (!this.CanPopCollateral(collateralPosition, balloonVisualisation))
                    {
                        break;
                    }
                }

                // Up
                for (int index = popPosition.Y - Constants.IterationStep; index >= Constants.YOffset; index -= Constants.IterationStep)
                {
                    Position collateralPosition = new Position(popPosition.X, index);

                    if (!this.CanPopCollateral(collateralPosition, balloonVisualisation))
                    {
                        break;
                    }
                }

                // Down
                for (int index = popPosition.Y + Constants.IterationStep; index < Constants.YOffset + Constants.MaximalYPosition; index += Constants.IterationStep)
                {
                    Position collateralPosition = new Position(popPosition.X, index);

                    if (!this.CanPopCollateral(collateralPosition, balloonVisualisation))
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private bool CanPopCollateral(Position collateralPosition, char balloonVisualisation)
        {
            bool canPopCollateral = false;

            Balloon collateralBalloon = null;

            foreach (Balloon balloon in this.balloons)
            {
                if (balloon.Position == collateralPosition)
                {
                    collateralBalloon = balloon;
                    break;
                }
            }

            if (collateralBalloon != null && collateralBalloon.Visualisation == balloonVisualisation)
            {
                canPopCollateral = true;
                collateralBalloon.RespondToInteraction();
            }

            return canPopCollateral;
        }
Ejemplo n.º 6
0
        private void AttemptPop(ICommand command)
        {
            if (command.Parameters.Length != 2)
            {
                this.InvalidCommand(command);
            }
            else
            {
                string firstParameter = command.Parameters[0];
                string secondParameter = command.Parameters[1];

                int row;
                int column;

                if (!int.TryParse(firstParameter, out row) || !int.TryParse(secondParameter, out column))
                {
                    this.InvalidCommand(command);
                }
                else if (!this.IsLegalMove(row, column))
                {
                    this.InvalidMove(row, column);
                }
                else
                {
                    row *= Constants.IterationStep;
                    column *= Constants.IterationStep;

                    Position popPosition = new Position(Constants.XOffset + column, Constants.YOffset + row);

                    try
                    {
                        this.PopBalloon(popPosition);
                        this.userMovesCount++;
                    }
                    catch (InvalidOperationException exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }
            }
        }