C# WINFORM 打砖块游戏,可以进行两队PK 程序源码

发布时间 2023-06-01 14:18:07作者: 程序员一诺

C# WINFORM 打砖块游戏
红色 绿色 阵营,球可以自定义添加,图片可以设置为网络地址的头像,可以进行与评论和弹幕进行建设。

 

支持球增加

支持球加速

支持一键初始化游戏

支持pk

支持积分累计

程序代码还有完全开发完毕,有些小细节还需要再进行优化

程序使用纯原生代码,没有使用任何第三方库

代码简单易懂,便于更改。

  string imgUrl = "https://p3.douyinpic.com/aweme/100x100/aweme-avatar/mosaic-legacy_3791_5070639578.jpeg?from=3067671334";

            Random random = new Random();
            for (int i = 0; i < 1; i++)
            {
                PictureBox ball = new PictureBox();
                ball.SizeMode = PictureBoxSizeMode.StretchImage;
                ball.Image = Properties.Resources.bullet_image;
                // ball.Load(imgUrl);
                ball.Width = 30;
                ball.Height = 30;
                ball.BackColor = Color.Transparent;
                ball.Location = new Point(10, pictureBox1.Height - ball.Height);
                // 图片圆角
                SetRoundPictureBox(ball, 15);
                //int x = random.Next(0, this.ClientSize.Width);
                //int y = random.Next(0, this.ClientSize.Height);
                //int x = pictureBox1.Width - ball.Width - 10;
                //int y = pictureBox1.Height - ball.Height - 10;

                int x = 1;
                int y = pictureBox1.Height - ball.Height - 1;
                int dx = random.Next(1, 5);
                int dy = random.Next(1, 5);
                Ball newBall = new Ball(ball, x, y, dx, dy);
                balls.Add(newBall);
                pictureBox1.Controls.Add(ball);
            }

 

 for (int i = 0; i < brickRows; i++)
            {
                for (int j = 0; j < brickCols; j++)
                {
                    PictureBox brick = new PictureBox();
                    brick.SizeMode = PictureBoxSizeMode.StretchImage;
                    brick.Image = Properties.Resources.brick_red;
                    brick.Width = brickWidth;
                    brick.Height = brickHeight;
                    brick.Location = new Point(j * brickWidth, i * brickHeight);
                    bricks.Add(brick);
                    pictureBox1.Controls.Add(brick);
        
                }
            }