/// <summary> /// Vytvoreni cihel pro dany level. Cislo levelu je pocet radku cihel, kdy cihly zaplnuji celou sirku obrazovky. /// </summary> /// <param name="level"> /// Cislo levelu /// </param> public void Create(int level) { // smazat pripadne existujici cihly if (_bricks.Count > 0) { foreach (var brick in _bricks) { // UI se musi vyhodit taky _gameManager.GameCanvas.Children.Remove(brick.View); } _bricks.Clear(); } // zjisti pocet sloupcu var cols = (int)(_gameManager.PlayGroundWidth / (_brickPrototypeView.ActualWidth + MARGIN)); // radku je podle cisla levelu var rows = level; // offset od praveho okraje, tak aby byly cihly vycentrovane var leftOffset = _gameManager.PlayGroundLeft + (_gameManager.PlayGroundWidth - cols * (_brickPrototypeView.ActualWidth + MARGIN)) / 2 + MARGIN / 2; // odstup od horniho okraje var topOffset = _gameManager.PlayGroundTop + 10; for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { // naklonuj cihlu var brick = new Brick(Toolkit.Clone(_brickPrototypeView)); // nastav ji pozici var left = leftOffset + col * (_brickPrototypeView.ActualWidth + MARGIN); var top = topOffset + row * (_brickPrototypeView.ActualHeight + MARGIN); // barvu brick.Color = new SolidColorBrush(_colors[Toolkit.Random.Next(_colors.Length)]); // pocet bodu k ziskani brick.Value = (rows - row) * 5; brick.X = left; brick.Y = top; // pridej na UI _gameManager.GameCanvas.Children.Add(brick.View); // a do seznamu _bricks.Add(brick); } } // nastav hodnotu pro zjisteni bounding boxu celeho bloku X = _bricks[0].X; Y = _bricks[0].Y; Width = _bricks[_bricks.Count - 1].X + _bricks[_bricks.Count - 1].Width; Height = _bricks[_bricks.Count - 1].Y + _bricks[_bricks.Count - 1].Height; }