예제 #1
0
        /// <summary>
        /// Adds a bonus.
        /// </summary>
        /// <param name="oneBrick">The brick.</param>
        private void AddBonus(Brick oneBrick)
        {
            try
            {
                string bonusImage = "";
                Bonus.BonusesType type = Bonus.BonusesType.BallBigger;

                // Random generate an effect for the bonus.
                switch (rnd.Next(1, 11))
                {
                    case 1:
                        type = Bonus.BonusesType.BallBigger;
                        bonusImage = @"..\..\Resources\Media\Bonus\ballbigger.jpg";
                        break;
                    case 2:
                        type = Bonus.BonusesType.BallSmaller;
                        bonusImage = @"..\..\Resources\Media\Bonus\ballsmaller.jpg";
                        break;
                    case 3:
                        type = Bonus.BonusesType.HardBall;
                        bonusImage = @"..\..\Resources\Media\Bonus\hardball.jpg";
                        break;
                    case 4:
                        type = Bonus.BonusesType.LifeDown;
                        bonusImage = @"..\..\Resources\Media\Bonus\lifedown.jpg";
                        break;
                    case 5:
                        type = Bonus.BonusesType.LifeUp;
                        bonusImage = @"..\..\Resources\Media\Bonus\lifeup.jpg";
                        break;
                    case 6:
                        type = Bonus.BonusesType.NewBall;
                        bonusImage = @"..\..\Resources\Media\Bonus\newball.jpg";
                        break;
                    case 7:
                        type = Bonus.BonusesType.RacketLengthen;
                        bonusImage = @"..\..\Resources\Media\Bonus\racketlengthen.jpg";
                        break;
                    case 8:
                        type = Bonus.BonusesType.RacketShorten;
                        bonusImage = @"..\..\Resources\Media\Bonus\racketshorten.jpg";
                        break;
                    case 9:
                        type = Bonus.BonusesType.SteelBall;
                        bonusImage = @"..\..\Resources\Media\Bonus\steelball.jpg";
                        break;
                    case 10:
                        type = Bonus.BonusesType.StickyRacket;
                        bonusImage = @"..\..\Resources\Media\Bonus\stickyracket.jpg";
                        break;
                }

                // Create the bonus and set the needed properties.
                Bonus bonus = new Bonus(oneBrick.Area.X + (oneBrick.Area.Width / 2) - (bonusWidth / 2), oneBrick.Area.Y + oneBrick.Area.Height,
                    bonusHeight, bonusWidth, bonusImage, type);
                bonus.ScorePoint = 50;
                bonus.IsDeleted = false;
                canvas.Children.Add(bonus.GetRectangle());
                bonusList.Add(bonus);

                // Move the bonus down.
                if (bonus.Descend(bonusSpeed, canvasWidth, canvasHeight))
                {
                    // Delete the bonus if the top of it reached the bottom of the canvas.
                    bonus.IsDeleted = true;
                }
            }
            catch (Exception e)
            {
                errorLogViewModel.LogError(e);
            }
        }
예제 #2
0
        /// <summary>
        /// Adds a bonus.
        /// </summary>
        /// <param name="oneBrick">The brick.</param>
        private void AddBonus(Brick oneBrick)
        {
            try
            {
                string bonusImage = "";
                Bonus.BonusesType type = Bonus.BonusesType.BallBigger;

                switch (rnd.Next(1, 11))
                {
                    case 1:
                        type = Bonus.BonusesType.BallBigger;
                        bonusImage = @"..\..\Resources\Media\Bonus\ballbigger.jpg";
                        break;
                    case 2:
                        type = Bonus.BonusesType.BallSmaller;
                        bonusImage = @"..\..\Resources\Media\Bonus\ballsmaller.jpg";
                        break;
                    case 3:
                        type = Bonus.BonusesType.HardBall;
                        bonusImage = @"..\..\Resources\Media\Bonus\hardball.jpg";
                        break;
                    case 4:
                        type = Bonus.BonusesType.LifeDown;
                        bonusImage = @"..\..\Resources\Media\Bonus\lifedown.jpg";
                        break;
                    case 5:
                        type = Bonus.BonusesType.LifeUp;
                        bonusImage = @"..\..\Resources\Media\Bonus\lifeup.jpg";
                        break;
                    case 6:
                        type = Bonus.BonusesType.NewBall;
                        bonusImage = @"..\..\Resources\Media\Bonus\newball.jpg";
                        break;
                    case 7:
                        type = Bonus.BonusesType.RacketLengthen;
                        bonusImage = @"..\..\Resources\Media\Bonus\racketlengthen.jpg";
                        break;
                    case 8:
                        type = Bonus.BonusesType.RacketShorten;
                        bonusImage = @"..\..\Resources\Media\Bonus\racketshorten.jpg";
                        break;
                    case 9:
                        type = Bonus.BonusesType.SteelBall;
                        bonusImage = @"..\..\Resources\Media\Bonus\steelball.jpg";
                        break;
                    case 10:
                        type = Bonus.BonusesType.StickyRacket;
                        bonusImage = @"..\..\Resources\Media\Bonus\stickyracket.jpg";
                        break;
                }

                Bonus bonus = new Bonus(oneBrick.Area.X + (oneBrick.Area.Width / 2) - (bonusWidth / 2), oneBrick.Area.Y + oneBrick.Area.Height, bonusHeight, bonusWidth, bonusImage, type);
                bonus.ScorePoint = 5;
                bonusList.Add(bonus);
                gameObjectList.Add(bonus);

                if (bonus.Descend(bonusSpeed, canvasWidth, canvasHeight))
                {
                    bonusList.Remove(bonus);
                    gameObjectList.Remove(bonus);
                }
            }
            catch (Exception e)
            {
                errorLogViewModel.LogError(e);
            }
        }