public void CheckForDestroy(Ball ball) { if (IsActive) { if (ball.Bounds.Intersects(this.Bounds)) { IsActive = false; ball.motion.Y *= -1; } } }
/// <summary> /// Move slider left on keyboard left. Also handles explicit collision detection because of a bug with slider moving /// </summary> /// <param name="x">The value by which slider will move left in a single frame</param> /// <param name="ball">To detect collision with ball</param> /// <param name="brickManager">To detect collision with brick</param> /// <param name="gameFrame">Detect collision with screen edges</param> /// <param name="lifelost">Boolean variable to store if ball went below slider and a life was lost</param> /// <param name="hit">Sound when collision occurs</param> public void MoveLeft(int x, ref Ball ball, ref BricksManager brickManager, ref Rectangle gameFrame, ref bool lifelost, SoundEffectInstance hit) { //for every unit movement of the slider to the left for (int i = 0; i < x; i++) { boundingBox.X--; ball.UpdatePosition(brickManager, gameFrame, this, ref lifelost, hit, x); //note slow down factor, since UpdatePosition is called 'x' times //this was an explicit bug fix. Slider used to cross over the ball if (checkCollision(ball.getBoundingBox())) { boundingBox.X+=3; } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); bricks = new Brick[bricksWidth, bricksHeight]; for (int i = 0; i < bricksHeight; i++) { for (int j = 0; j < bricksWidth; j++) { bricks[j, i] = new Brick(Content, j * (105), i * 25); } } ball = new Ball(Content, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); paddle = new Paddle(Content, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); // TODO: use this.Content to load your game content here }
// Initializor============================================= public override void Initialize() { // Initialize the Camera camera = new ShakedCamera(this); camera.Position = new Vector3(0, 13, 17); camera.Target = new Vector3(0, 0, 3); if (!Engine.Services.ContainsService(typeof(Camera))) Engine.Services.AddService(typeof(Camera), (ShakedCamera)camera); // Initialize the keyboard keyboard = Engine.Services.GetService<KeyboardDevice>(); // Initialize the sounds music = Engine.Content.Load<Song>("Content\\Sounds\\music1"); MediaPlayer.Play(music); MediaPlayer.Volume = 0.2f; MediaPlayer.IsRepeating = true; // Inistialize tha black Texture black = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\black"), Vector2.Zero, this); // Initialize tha Radar radar = new Radar(Engine.Content.Load<Model>("Content\\Models\\Radar"), Vector3.One, this); radar.Visible = false; // Initialize the Ball ball = new Ball(Engine.Content.Load<Model>("Content\\Models\\GameBall"), new Vector3(0f,0f,5f), this); ball.defaultLightingEnabled = true; // Initialize the Bricks List brickLenghtLine = 3; brickLenghtColumn = 10; totalOfBricks = brickLenghtLine * brickLenghtColumn; totalOfBricksLeft = totalOfBricks; brickMapArray=new int[brickLenghtLine, brickLenghtColumn]; brickObjectArray = new Brick[brickLenghtLine, brickLenghtColumn]; for (int i = 0; i < brickLenghtLine; i++) { for (int j = 0; j < brickLenghtColumn; j++) { brickMapArray[i, j] = Util.random.Next(0, 3); } } // Initialize the Released Object array ReleasedObjectArray = new ReleasedObject[totalOfBricks]; for (int i = 0; i < totalOfBricks; i++) ReleasedObjectArray[i] = null; ReleasedObjectArrayIndex = 0; // initialize the ObjectArray of bricks for (int i = 0; i < brickLenghtLine; i++) { for (int j = 0; j < brickLenghtColumn; j++) { Brick brick; Model model; // Type of Brick Vector3 brikPos = new Vector3(-7f + j * 1.5f, 0f, -4f + i*1.5f); switch (brickMapArray[i,j]) { case 0: // Type Normal model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1"); brick = new Brick(model, brikPos, this); brick.BrickReleaseType = BrickReleaseType.Normal; brickObjectArray[i, j] = brick; model = Engine.Content.Load<Model>("Content\\Models\\ReleasedNormObject"); ReleasedObjectArray[brickLenghtColumn * i + j] = new NormalObject(model, brikPos, this); break; case 1: // Type Score model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1"); brick = new Brick(model, brikPos, this); brick.BrickReleaseType = BrickReleaseType.Money; brickObjectArray[i, j] = brick; model = Engine.Content.Load<Model>("Content\\Models\\ReleasedMoneyObject"); ReleasedObjectArray[brickLenghtColumn * i + j] = new MoneyObject(model, brikPos, this); break; case 2: // Type Life model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1"); brick = new Brick(model, brikPos, this); brick.BrickReleaseType = BrickReleaseType.Danger; brickObjectArray[i, j] = brick; model = Engine.Content.Load<Model>("Content\\Models\\ReleasedDangerObject"); ReleasedObjectArray[brickLenghtColumn * i + j] = new DangerObject(model, brikPos, this); break; default: // Type Normal model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1"); brick = new Brick(model, brikPos, this); brick.BrickReleaseType = BrickReleaseType.Normal; brickObjectArray[i, j] = brick; model = Engine.Content.Load<Model>("Content\\Models\\ReleasedNormObject"); ReleasedObjectArray[brickLenghtColumn * i + j] = new NormalObject(model, brikPos, this); break; } // Update the ReleasedObjectArrayIndex if (ReleasedObjectArrayIndex >= totalOfBricks) ReleasedObjectArrayIndex = 0; else ReleasedObjectArrayIndex++; } } // Initialize the Paddle paddle = new Paddle(Engine.Content.Load<Model>("Content\\Models\\GamePaddle"), Vector3.Zero, this); paddle.defaultLightingEnabled = true; // Iniotialize the spiralRod paddleSupport = new PaddleSupport(Engine.Content.Load<Model>("Content\\Models\\SpiralRod"), new Vector3(0f, 0.6f, 9f), this); //paddleSupport.Rotation = Matrix.CreateRotationZ(MathHelper.ToRadians(90f)); paddleSupport.defaultLightingEnabled = true; // Initialize the Blur blur = new GaussianBlur(Engine.Viewport.Width, Engine.Viewport.Height, this); blur.Visible = false; // Initialize HUD hud = new Hud(this); // Initialize the gameMap gameMap = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\GameMap"), Vector3.Zero, this); gameMap.defaultLightingEnabled = true; base.Initialize(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { gameState = GameState.TitleScreen; lives = 3; lifelost = false; font = Content.Load<SpriteFont>("SpriteFont"); //sounds/music fantomenk = Content.Load<SoundEffect>("FantomenK"); backgroundMusic = fantomenk.CreateInstance(); hit = Content.Load<SoundEffect>("hit"); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //boundingBox for collision detection with screen edges gameFrame = new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height); //bricks brickTexture = Content.Load<Texture2D>("brick"); brickManager = new BricksManager(ref spriteBatch,ref brickTexture,ref graphics); brickManager.generateBricks(); //ball ballTexture = Content.Load<Texture2D>("ball"); ballPos = new Vector2( ( graphics.GraphicsDevice.Viewport.Width - ballTexture.Width) / 2, //centre of the screen graphics.GraphicsDevice.Viewport.Height * 3 / 4 - (ballTexture.Height + 10) ); ball = new Ball(ref spriteBatch, ref ballTexture, ballPos, new Vector2(0, 0), //velocity vector timeDivideFactor); //slider sliderTexture = Content.Load<Texture2D>("slider"); sliderPos = new Vector2( ( graphics.GraphicsDevice.Viewport.Width - sliderTexture.Width) / 2, //centre of the screen graphics.GraphicsDevice.Viewport.Height*3 / 4 ); slider = new Slider(ref sliderTexture,ref spriteBatch, sliderPos); }
/// <summary> /// Checks if the racket is in contact with a bonus. /// </summary> private void RacketAtContactWithBonus() { if (racketList.Count > 0) { foreach (var oneRacket in racketList) { if (bonusList.Count > 0) { for (int i = 0; i < bonusList.Count; i++) { if (oneRacket.PositionX < bonusList[i].PositionX + bonusList[i].Width && /* bonus rigth side */ oneRacket.PositionX + oneRacket.Width > bonusList[i].PositionX && /* bonus left side */ oneRacket.PositionY < bonusList[i].PositionY + bonusList[i].Height) /* bonus bottom */ { scoreValue += bonusList[i].ScorePoint; ScoreLabel.Content = "Score: " + scoreValue; #region AddBonusEffect switch (bonusList[i].TypeOfBonus) { case Bonus.bonusType.LifeUp: lifePoint++; break; case Bonus.bonusType.LifeDown: lifePoint--; break; case Bonus.bonusType.NewBall: Ball ball = new Ball(oneRacket.PositionX + (oneRacket.Width / 2) - ballRadius, oneRacket.PositionY - (ballRadius * 2), ballRadius, Ball.ballType.Normal, @"..\..\Resources\media\ball\normalball.jpg"); ball.VerticalMovement = ballVerticalMovement > 0 ? ballVerticalMovement : -ballVerticalMovement; ball.HorizontalMovement = ballHorizontalMovement < 0 ? ballHorizontalMovement : -ballHorizontalMovement; ball.BallInMove = false; ballList.Add(ball); canvasLayer.Children.Add(ball.GetEllipse()); break; case Bonus.bonusType.RacketLengthen: oneRacket.Width += (oneRacket.Width < racketMaxSize ? racketDifference : 0); break; case Bonus.bonusType.RacketShorten: oneRacket.Width -= (oneRacket.Width > racketMinSize ? racketDifference : 0); break; case Bonus.bonusType.BallBigger: if (ballList.Count > 0) { foreach (var oneBall in ballList) { if (oneBall.PositionX + (bigBall * 2) > canvasLayer.Width) { oneBall.PositionX -= ((bigBall - ballRadius) * 2); } else if (oneBall.PositionY + (bigBall * 2) + racketHeight > canvasLayer.Height) { oneBall.PositionY -= ((bigBall - ballRadius) * 2); } // Reposition the ball, so that it will not trigger an error when obtaining bonus effect. oneBall.Radius = bigBall; } } break; case Bonus.bonusType.BallSmaller: if (ballList.Count > 0) { foreach (var oneBall in ballList) { oneBall.Radius = smallBall; } } break; case Bonus.bonusType.StickyRacket: if (!oneRacket.StickyRacket) { oneRacket.StickyRacket = true; oneRacket.RacketImage = @"..\..\Resources\media\racket\stickyracket.jpg"; } break; case Bonus.bonusType.HardBall: if (ballList.Count > 0) { foreach (var oneBall in ballList) { oneBall.TypeOfBall = Ball.ballType.Hard; oneBall.BallImage = @"..\..\Resources\media\ball\hardball.jpg"; } } break; case Bonus.bonusType.SteelBall: if (ballList.Count > 0) { foreach (var oneBall in ballList) { oneBall.TypeOfBall = Ball.ballType.Steel; oneBall.BallImage = @"..\..\Resources\media\ball\steelball.jpg"; } } break; } // Add the bonus effect. LifeLabel.Content = "Life: " + lifePoint; if (lifePoint <= 0) { gameOverStatus = "fail"; gameOver = true; } #endregion AddBonusEffect bonusList.Remove(bonusList[i]); } } } } } RefreshCanvas(); }
/// <summary> /// Loads the values from the xml file. /// </summary> private void LoadValuesFromFile() { #region PresetValues lifePoint = 3; scoreValue = 0; gameInSession = false; gameIsPaused = false; gameOver = false; gameOverStatus = ""; mapName = "notfound"; bonusSpeed = 1; mapMaxNumber = 5; timeSpan = 3; ballHorizontalMovement = 5; ballVerticalMovement = 5; racketHorizontalMovement = 10; ballSpeed = 1; speedScale = 1; brickWidth = 27.7; brickHeight = 8; racketWidth = 80; racketHeight = 8; bonusWidth = 24; bonusHeigth = 24; ballRadius = 5; smallBall = 3; bigBall = 15; ballExaminationProximity = 4; horizontalScaleNumber = 1; verticalScaleNumber = 1; racketMaxSize = 160; racketMinSize = 40; racketDifference = 16; if (bonusList.Count != 0) { bonusList.Clear(); } if (racketList.Count != 0) { racketList.Clear(); } if (ballList.Count != 0) { ballList.Clear(); } if (brickList.Count != 0) { brickList.Clear(); } optionsSettings = new OptionsSettings("", "", "", "", "", 0, false, false, 0, false); timeOfGame = new DateTime(); movingTimer = new DispatcherTimer(); mPlayer = new MediaPlayer(); rnd = new Random(); #endregion PresetValues #region OptionsHandler try { if (!File.Exists(@"..\..\Resources\OptionsSettings.xml")) { if (MessageBox.Show("Couldn't find the xml file for the settings. \n Would you like to create a new with default settings?", "Error", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { XElement mouseElement = new XElement("mouse", "true"); XElement keyboardElement = new XElement("keyboard", "true"); XElement soundElement = new XElement("sound", "true"); XElement resolutionElement = new XElement("resolution", "1024x768"); XElement leftkeyElement = new XElement("leftkey", "Left"); XElement rightkeyElement = new XElement("rightkey", "Right"); XElement firekeyElement = new XElement("firekey", "Space"); XElement pausekeyElement = new XElement("pausekey", "P"); XElement difficultyElement = new XElement("difficulty", "1"); XElement mapElement = new XElement("map", "1"); XAttribute newAttribute = new XAttribute("id", 1); XElement newElements = new XElement("option", newAttribute, mouseElement, keyboardElement, soundElement, resolutionElement, leftkeyElement, rightkeyElement, firekeyElement, pausekeyElement, difficultyElement, mapElement); XElement newOptions = new XElement("Options", newElements); XDocument newDocument = new XDocument(newOptions); newDocument.Save(@"..\..\Resources\OptionsSettings.xml"); } // If the OptionsSettings xml doesn't exist, then send message. } if (File.Exists(@"..\..\Resources\OptionsSettings.xml")) { XDocument settingsFromXml = XDocument.Load(@"..\..\Resources\OptionsSettings.xml"); var readDataFromXml = settingsFromXml.Descendants("option"); var fromXml = from x in readDataFromXml select x; // Load the values stored in the xml. foreach (var oneElement in fromXml) { optionsSettings.GraphicsResolution = (string)oneElement.Element("resolution"); optionsSettings.LeftKey = (string)oneElement.Element("leftkey"); optionsSettings.RightKey = (string)oneElement.Element("rightkey"); optionsSettings.PauseKey = (string)oneElement.Element("pausekey"); optionsSettings.FireKey = (string)oneElement.Element("firekey"); optionsSettings.DifficultyLevel = (int)oneElement.Element("difficulty"); optionsSettings.MouseIsOn = (bool)oneElement.Element("mouse"); optionsSettings.KeyboardIsOn = (bool)oneElement.Element("keyboard"); optionsSettings.MapNumber = (int)oneElement.Element("map"); optionsSettings.SoundIsOn = (bool)oneElement.Element("sound"); } // Gives the values from the xml to the OptionSettings object, thus sets the object with the default values. } } catch { } #endregion OptionsHandler #region SetScaling switch (optionsSettings.GraphicsResolution) { case "640x480": horizontalScaleNumber = 1; verticalScaleNumber = 1; break; case "800x600": horizontalScaleNumber = 1.25; verticalScaleNumber = 1.25; break; case "1024x768": horizontalScaleNumber = 1.6; verticalScaleNumber = 1.6; break; } switch (optionsSettings.DifficultyLevel) { case 1: speedScale = 1; break; case 2: speedScale = 1.2; break; case 3: speedScale = 1.4; break; } bonusWidth *= horizontalScaleNumber; bonusHeigth *= verticalScaleNumber; racketWidth *= horizontalScaleNumber; racketHeight *= verticalScaleNumber; brickWidth *= horizontalScaleNumber; brickHeight *= verticalScaleNumber; ballHorizontalMovement *= speedScale; ballVerticalMovement *= speedScale; ballRadius *= horizontalScaleNumber; smallBall *= horizontalScaleNumber; bigBall *= horizontalScaleNumber; bonusSpeed *= speedScale; ballSpeed *= speedScale; racketHorizontalMovement *= speedScale; ballExaminationProximity *= horizontalScaleNumber; racketMaxSize *= horizontalScaleNumber; racketMinSize *= horizontalScaleNumber; racketDifference *= horizontalScaleNumber; // Set the scaling. #endregion SetScaling #region MapSelection try { if (optionsSettings.MapNumber > 0 && optionsSettings.MapNumber < 6) { switch (optionsSettings.MapNumber) { case 1: if (!File.Exists(@"..\..\Resources\maps\FirstMap.txt")) { mapName = "notfound"; } else { mapName = @"..\..\Resources\maps\FirstMap.txt"; } break; case 2: if (!File.Exists(@"..\..\Resources\maps\SecondMap.txt")) { mapName = "notfound"; } else { mapName = @"..\..\Resources\maps\SecondMap.txt"; } break; case 3: if (!File.Exists(@"..\..\Resources\maps\ThirdMap.txt")) { mapName = "notfound"; } else { mapName = @"..\..\Resources\maps\ThirdMap.txt"; } break; case 4: if (!File.Exists(@"..\..\Resources\maps\FourthMap.txt")) { mapName = "notfound"; } else { mapName = @"..\..\Resources\maps\FourthMap.txt"; } break; case 5: if (!File.Exists(@"..\..\Resources\maps\FifthMap.txt")) { mapName = "notfound"; } else { mapName = @"..\..\Resources\maps\FifthMap.txt"; } break; } // Based on the selected map sets the name of the map that will open if it exists. } // Only switch if the number is correct. } catch { } #endregion MapSelection #region BrickListFill try { if (!String.IsNullOrEmpty(mapName) && mapName != "notfound") { double X = 0; double Y = 0; FileStream fs = new FileStream(mapName, FileMode.Open, FileAccess.Read, FileShare.None); BinaryReader rd = new BinaryReader(fs); while (rd.BaseStream.Position != rd.BaseStream.Length) { char[] oneLine = rd.ReadChars(24); for (int i = 0; i < oneLine.Length; i++) { switch (oneLine[i]) { case '.': break; case '1': Brick brick1 = new Brick(X, Y, brickHeight, brickWidth, Brick.brickType.Easy, @"..\..\Resources\media\brick\easybrick.jpg"); brick1.ScorePoint = 10; brick1.BreakNumber = 1; brickList.Add(brick1); canvasLayer.Children.Add(brick1.GetRectangle()); break; case '2': Brick brick2 = new Brick(X, Y, brickHeight, brickWidth, Brick.brickType.Medium, @"..\..\Resources\media\brick\mediumbrick.jpg"); brick2.ScorePoint = 20; brick2.BreakNumber = 2; brickList.Add(brick2); canvasLayer.Children.Add(brick2.GetRectangle()); break; case '3': Brick brick3 = new Brick(X, Y, brickHeight, brickWidth, Brick.brickType.Hard, @"..\..\Resources\media\brick\hardbrick.jpg"); brick3.ScorePoint = 30; brick3.BreakNumber = 5; brickList.Add(brick3); canvasLayer.Children.Add(brick3.GetRectangle()); break; case '4': Brick brick4 = new Brick(X, Y, brickHeight, brickWidth, Brick.brickType.Steel, @"..\..\Resources\media\brick\steelbrick.jpg"); brick4.ScorePoint = 40; brick4.BreakNumber = 1; brickList.Add(brick4); canvasLayer.Children.Add(brick4.GetRectangle()); break; } X += brickWidth; } X = 0; Y += brickHeight; } rd.Close(); fs.Close(); // Adds the bricks as they are stored in the map file. } // If the map name is valid, then load map. } catch { } #endregion BrickListFill #region SetValues mPlayer.Open(new Uri(@"..\..\Resources\media\sounds\play_this.mp3", UriKind.Relative)); Width = int.Parse(optionsSettings.GraphicsResolution.Split('x')[0]); Height = int.Parse(optionsSettings.GraphicsResolution.Split('x')[1]); canvasLayer.Width = int.Parse(optionsSettings.GraphicsResolution.Split('x')[0]) - 30; canvasLayer.Height = int.Parse(optionsSettings.GraphicsResolution.Split('x')[1]) - 50; // Set resolution. Racket racket = new Racket((canvasLayer.Width / 2) - (racketWidth / 2), canvasLayer.Height - racketHeight, racketHeight, racketWidth, @"..\..\Resources\media\racket\normalracket.jpg"); racketList.Add(racket); canvasLayer.Children.Add(racket.GetRectangle()); // First racket. Ball ball = new Ball((canvasLayer.Width / 2) - ballRadius, canvasLayer.Height - racketHeight - (ballRadius * 2), ballRadius, Ball.ballType.Normal, @"..\..\Resources\media\ball\normalball.jpg"); ball.VerticalMovement = ballVerticalMovement > 0 ? ballVerticalMovement : -ballVerticalMovement; ball.HorizontalMovement = ballHorizontalMovement < 0 ? ballHorizontalMovement : -ballHorizontalMovement; ball.BallInMove = false; ballList.Add(ball); canvasLayer.Children.Add(ball.GetEllipse()); // First ball. #endregion SetValues }
/// <summary> /// Handles the event when the ball falls down. /// </summary> private void DisposeOfBall() { canvasLayer.Children.Clear(); racketList.Clear(); ballList.Clear(); bonusList.Clear(); // Dispose balls, rackets, bonuses. Racket racket = new Racket((canvasLayer.Width / 2) - (racketWidth / 2), canvasLayer.Height - racketHeight, racketHeight, racketWidth, @"..\..\Resources\media\racket\normalracket.jpg"); racketList.Add(racket); canvasLayer.Children.Add(racket.GetRectangle()); // Add new racket. Ball ball = new Ball((canvasLayer.Width / 2) - ballRadius, canvasLayer.Height - racketHeight - (ballRadius * 2), ballRadius, Ball.ballType.Normal, @"..\..\Resources\media\ball\normalball.jpg"); ball.VerticalMovement = ballVerticalMovement > 0 ? ballVerticalMovement : -ballVerticalMovement; ball.HorizontalMovement = ballHorizontalMovement < 0 ? ballHorizontalMovement : -ballHorizontalMovement; // TODO: bug at new ball movement ball.BallInMove = false; ballList.Add(ball); canvasLayer.Children.Add(ball.GetEllipse()); // Add new ball. RefreshCanvas(); }
/// <summary> /// Brick is at contact with ball. /// </summary> /// <param name="oneBall">One ball.</param> /// <param name="oneBrick">One brick.</param> private void BrickContact(Ball oneBall, Brick oneBrick) { if (oneBall.TypeOfBall != Ball.ballType.Steel) { if (oneBrick.TypeOfBrick != Brick.brickType.Steel) { if (oneBall.TypeOfBall != Ball.ballType.Hard) { if (oneBrick.BreakNumber == 1) { // If the brick is at breaking point. scoreValue += oneBrick.ScorePoint; // Add points to the score. ScoreLabel.Content = "Score: " + scoreValue; // Show the scorepints. if (oneBrick.CalculateBonusChance()) { // If the brick is lucky, then add bonus. AddBonus(oneBrick); } brickList.Remove(oneBrick); } else { // If brick is not at breaking point, then decrement the breaking number. oneBrick.BreakNumber -= 1; if (oneBrick.TypeOfBrick == Brick.brickType.Hard) { oneBrick.BrickImage = @"..\..\Resources\media\brick\brokenhardbrick.jpg"; } else if (oneBrick.TypeOfBrick == Brick.brickType.Medium) { oneBrick.BrickImage = @"..\..\Resources\media\brick\brokenmediumbrick.jpg"; } } } else { scoreValue += oneBrick.ScorePoint; // Add points to the score. ScoreLabel.Content = "Score: " + scoreValue; // Show the scorepints. if (oneBrick.CalculateBonusChance()) { // If the brick is lucky, then add bonus. AddBonus(oneBrick); } brickList.Remove(oneBrick); } } } else { // If the ball is steel then no breaknumber scan's needed, every brick breaks at first contact. scoreValue += oneBrick.ScorePoint; ScoreLabel.Content = "Score: " + scoreValue; if (oneBrick.CalculateBonusChance()) { // If the brick is lucky, then add bonus. AddBonus(oneBrick); } brickList.Remove(oneBrick); } if (optionsSettings.SoundIsOn) { mPlayer.Position = new TimeSpan(0); mPlayer.Play(); } }