private static void Draw(Brick brick, ref Canvas canvas) { if (brick.Type == "skip") { return; } Rectangle rect = new Rectangle(); rect.Fill = BrickLoader.GetColorBrush(brick.HexColor); rect.Height = brick.Height; rect.Width = brick.Width; rect.RadiusX = 4; rect.RadiusY = 4; rect.StrokeThickness = 1; rect.Name = brick.Id; Canvas.SetTop(rect, brick.Top); Canvas.SetLeft(rect, brick.Left); canvas.Children.Add(rect); }
//Check for bricks private bool checkBreakCollapse(ref int currentDirection, Ellipse _gameBall) { double _ballBottom = Canvas.GetTop(_gameBall) + _gameBall.Width; double _ballLeft = Canvas.GetLeft(_gameBall) - (_gameBall.Width / 2); double _ballRight = Canvas.GetLeft(_gameBall) + _gameBall.Width; double _ballTop = Canvas.GetTop(_gameBall); double _ballCenterX = Canvas.GetTop(_gameBall) + (_gameBall.Width / 2); double _ballCenterY = Canvas.GetLeft(_gameBall) + (_gameBall.Width / 2); var ballCoordinate = getCircularPoints(_gameBall); var conflictedBrick = State.bricks.Where(s => ballCoordinate.Any(p => s.Type != "skip" && p.X >= s.Left && p.X <= s.Left + s.Width && p.Y <= s.Top + s.Height && p.Y >= s.Top)); if (conflictedBrick.Count() > 0) { Brick cBrick = conflictedBrick.FirstOrDefault(); Rectangle cRectangle = canvas.FindRectangleByName(cBrick.Id) as Rectangle; if (lastCollapsed == cBrick && State.skipTick > 0) { State.skipTick--; return(false); } else { State.skipTick = 5; lastCollapsed = cBrick; } var nearCoordinate1 = ballCoordinate.Where(p => p.X >= cBrick.Left && p.X <= cBrick.Left + cBrick.Width && p.Y <= cBrick.Top + cBrick.Height && p.Y >= cBrick.Top); var xmin = nearCoordinate1.Min(s => s.X); var ymin = nearCoordinate1.Min(s => s.Y); var nearCoordinate = xmin < ymin?nearCoordinate1.OrderByDescending(s => s.X).First() : nearCoordinate1.OrderByDescending(s => s.Y).First(); if (cBrick == default(Brick)) { MessageBox.Show("Somethign issue"); } if (cBrick.Top <= _ballBottom && // top cBrick.Top + cBrick.Height > _ballBottom && cBrick.Left <= _ballCenterY && cBrick.Left + cBrick.Width >= _ballCenterY) { State._isClockWise = currentDirection == 0 ? false : true; } else if (cBrick.Top + cBrick.Height >= _ballCenterX && // left cBrick.Top < _ballCenterX && cBrick.Left <= _ballRight && cBrick.Left + cBrick.Width > _ballRight) { State._isClockWise = currentDirection == 3 ? false : true; } else if (cBrick.Top + cBrick.Height >= _ballTop && // bottom cBrick.Top < _ballTop && cBrick.Left <= _ballCenterY && cBrick.Left + cBrick.Width >= _ballCenterY) { State._isClockWise = currentDirection == 3 ? true : false; } else if (cBrick.Top + cBrick.Height >= _ballCenterX && // right cBrick.Top < _ballCenterX && cBrick.Left < _ballLeft && cBrick.Left + cBrick.Width >= _ballLeft) { State._isClockWise = currentDirection == 2 ? true : false; } changeBallDirection(ref currentDirection, _gameBall, cRectangle, nearCoordinate); //Strange code //int index = State.bricks.Select(x => x.Rectangle).ToList().IndexOf(cBrick); int index = State.bricks.IndexOf(cBrick); if (index < 0) { MessageBox.Show("Incorrect brick"); throw new Exception("Incorrect Brick"); } //Lifes if (cBrick.Life > 1) { cBrick.HexColor = BrickLoader.getColor("#ffffff"); cBrick.Life--; cRectangle.Fill = BrickLoader.GetColorBrush(cBrick.HexColor); Brick b = State.bricks.Single(x => x == cBrick); } else { IncreaseScore(10); cRectangle.Visibility = System.Windows.Visibility.Collapsed; //Brick toDelete = State.bricks.Where(x => x.Rectangle == cBrick).First(); State.bricks.Remove(cBrick); //brickInfo[index] = "0"; } //canvas.UpdateLayout(); //brickInfo = brickInfo.Where(s => s.ToString() != "0").ToArray(); if (State.bricks.Where(s => s.Type != "skip").Count() <= 0) { MessageBox.Show($"You have completed Stage : {State._currentStage++}!!! "); State._currentStage++; State.bricks = BrickLoader.load(State._currentStage); return(true); } return(true); } else { return(false); } }
public bool _isClockWise = true; // true = clockwise , false = anti-clockwise public GameSystemDataState() { bricks = BrickLoader.load(_currentStage); }