コード例 #1
0
        private void StartGame(object sender, RoutedEventArgs e)
        {
            STOP = false;
            StartButtonControlsPanel.IsEnabled = false;
            isLifesLost = false;
            MainGameTimer.Start();
            GameTimerstWatch.Restart();
            Canvas.SetLeft(Platform, 570);
            Canvas.SetLeft(Ball, 674);
            Canvas.SetTop(Ball, 533);
            dx = 0;
            dy = 6;
            Ball.Visibility     = Visibility.Visible;
            Platform.Visibility = Visibility.Visible;
            Platform.Focusable  = true;
            Platform.Focus();

            massRectangles = new Rectangles[countRowsEnemy, countColumnsEnemy];
            for (int i = 0; i < massRectangles.GetUpperBound(0) + 1; i++)
            {
                for (int j = 0; j < massRectangles.GetUpperBound(1) + 1; j++)
                {
                    SolidColorBrush randomColor = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rand.Next(0, 255)), Convert.ToByte(rand.Next(0, 245)), (byte)rand.Next(0, 250)));
                    massRectangles[i, j] = new Rectangles(heightEnemy, widthEnemy, randomColor, Colors.Black, positionEnemyLeft + j * marginLeftEnemy + j * widthEnemy, positionEnemyTop + i * marginTopEnemy + i * heightEnemy);
                    MainCanvas.Children.Add(massRectangles[i, j].rect);
                }
            }
            moveBall();
        }
コード例 #2
0
        private void GenerationBlocks()
        {
            switch (MainLvl)
            {
            case 1:
            {
                Ball.BeginAnimation(Canvas.LeftProperty, null);
                Ball.BeginAnimation(Canvas.TopProperty, null);

                positionEnemyLeft = 220;        //позиция в канвасе первого блока слева
                positionEnemyTop  = 50;         //позиция в канвасе первого блока сверху
                widthEnemy        = 180;        //ширина блоков
                heightEnemy       = 55;         //высота блоков
                marginLeftEnemy   = 10;         //отступ слева блоков
                marginTopEnemy    = 10;         //отступ сверху блоков
                countRowsEnemy    = 4;          //количество строк
                countColumnsEnemy = 5;          //количество столбцов

                Canvas.SetLeft(Platform, 570);
                Canvas.SetLeft(Ball, 674);
                Canvas.SetTop(Ball, 533);
                dx             = 0;
                dy             = 6;
                massRectangles = new Rectangles[countRowsEnemy, countColumnsEnemy];
                for (int i = 0; i < massRectangles.GetUpperBound(0) + 1; i++)
                {
                    for (int j = 0; j < massRectangles.GetUpperBound(1) + 1; j++)
                    {
                        SolidColorBrush randomColor = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rand.Next(0, 255)), Convert.ToByte(rand.Next(0, 245)), (byte)rand.Next(0, 250)));
                        massRectangles[i, j] = new Rectangles(heightEnemy, widthEnemy, randomColor, Colors.Black, positionEnemyLeft + j * marginLeftEnemy + j * widthEnemy, positionEnemyTop + i * marginTopEnemy + i * heightEnemy);
                        MainCanvas.Children.Add(massRectangles[i, j].rect);
                    }
                }
                break;
            }

            case 2:
            {
                Ball.BeginAnimation(Canvas.LeftProperty, null);
                Ball.BeginAnimation(Canvas.TopProperty, null);

                positionEnemyLeft = 65;         //позиция в канвасе первого блока слева
                positionEnemyTop  = 40;         //позиция в канвасе первого блока сверху
                widthEnemy        = 200;        //ширина блоков
                heightEnemy       = 55;         //высота блоков
                marginLeftEnemy   = 10;         //отступ слева блоков
                marginTopEnemy    = 10;         //отступ сверху блоков
                countRowsEnemy    = 5;          //количество строк
                countColumnsEnemy = 6;          //количество столбцов

                Canvas.SetLeft(Platform, 570);
                Canvas.SetLeft(Ball, 674);
                Canvas.SetTop(Ball, 533);
                dx             = 0;
                dy             = 6;
                massRectangles = new Rectangles[countRowsEnemy, countColumnsEnemy];
                for (int i = 0; i < massRectangles.GetUpperBound(0) + 1; i++)
                {
                    for (int j = 0; j < massRectangles.GetUpperBound(1) + 1; j++)
                    {
                        SolidColorBrush randomColor = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rand.Next(0, 255)), Convert.ToByte(rand.Next(0, 245)), (byte)rand.Next(0, 250)));
                        massRectangles[i, j] = new Rectangles(heightEnemy, widthEnemy, randomColor, Colors.Black, positionEnemyLeft + j * marginLeftEnemy + j * widthEnemy, positionEnemyTop + i * marginTopEnemy + i * heightEnemy);
                        MainCanvas.Children.Add(massRectangles[i, j].rect);
                    }
                }
                break;
            }

            case 3:
            {
                Ball.BeginAnimation(Canvas.LeftProperty, null);
                Ball.BeginAnimation(Canvas.TopProperty, null);

                positionEnemyLeft = 40;         //позиция в канвасе первого блока слева
                positionEnemyTop  = 40;         //позиция в канвасе первого блока сверху
                widthEnemy        = 200;        //ширина блоков
                heightEnemy       = 55;         //высота блоков
                marginLeftEnemy   = 10;         //отступ слева блоков
                marginTopEnemy    = 10;         //отступ сверху блоков
                countRowsEnemy    = 6;          //количество строк
                countColumnsEnemy = 6;          //количество столбцов

                Canvas.SetLeft(Platform, 570);
                Canvas.SetLeft(Ball, 674);
                Canvas.SetTop(Ball, 533);
                dx             = 0;
                dy             = 6;
                massRectangles = new Rectangles[countRowsEnemy, countColumnsEnemy];
                for (int i = 0; i < massRectangles.GetUpperBound(0) + 1; i++)
                {
                    for (int j = 0; j < massRectangles.GetUpperBound(1) + 1; j++)
                    {
                        SolidColorBrush randomColor = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rand.Next(0, 255)), Convert.ToByte(rand.Next(0, 245)), (byte)rand.Next(0, 250)));
                        massRectangles[i, j] = new Rectangles(heightEnemy, widthEnemy, randomColor, Colors.Black, positionEnemyLeft + j * marginLeftEnemy + j * widthEnemy, positionEnemyTop + i * marginTopEnemy + i * heightEnemy);
                        MainCanvas.Children.Add(massRectangles[i, j].rect);
                    }
                }
                break;
            }
            }

            if (MainLvl > 3)
            {
                Ball.BeginAnimation(Canvas.LeftProperty, null);
                Ball.BeginAnimation(Canvas.TopProperty, null);

                positionEnemyLeft = 10;  //позиция в канвасе первого блока слева
                positionEnemyTop  = 10;  //позиция в канвасе первого блока сверху
                widthEnemy        = 190; //ширина блоков
                heightEnemy       = 55;  //высота блоков
                marginLeftEnemy   = 9;   //отступ слева блоков
                marginTopEnemy    = 8;   //отступ сверху блоков
                countRowsEnemy    = 8;   //количество строк
                countColumnsEnemy = 7;   //количество столбцов

                Canvas.SetLeft(Platform, 570);
                Canvas.SetLeft(Ball, 674);
                Canvas.SetTop(Ball, 533);
                dx             = 0;
                dy             = 6;
                massRectangles = new Rectangles[countRowsEnemy, countColumnsEnemy];
                for (int i = 0; i < massRectangles.GetUpperBound(0) + 1; i++)
                {
                    for (int j = 0; j < massRectangles.GetUpperBound(1) + 1; j++)
                    {
                        SolidColorBrush randomColor = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rand.Next(0, 255)), Convert.ToByte(rand.Next(0, 245)), (byte)rand.Next(0, 250)));
                        massRectangles[i, j] = new Rectangles(heightEnemy, widthEnemy, randomColor, Colors.Black, positionEnemyLeft + j * marginLeftEnemy + j * widthEnemy, positionEnemyTop + i * marginTopEnemy + i * heightEnemy);
                        MainCanvas.Children.Add(massRectangles[i, j].rect);
                    }
                }
            }
        }