namespace Breakout
{
public partial class Form1 : Form
{
//declaring variables
private int x, y;
private int xChange, yChange;
private Graphics canvas;
private SolidBrush brush;
private Random randNum;
public Form1()
{
InitializeComponent();
//creating variables
canvas = picBoxCanvas.CreateGraphics();
brush = new SolidBrush(Color.Red);
randNum = new Random();
picBoxCanvas.BackColor = Color.Black;
}
private void picBoxCanvas_Click(object sender, EventArgs e)
{
}
private void btnPlay_Click(object sender, EventArgs e)
{
timer1.Interval = 50;
timer1.Enabled = true;
x = randNum.Next(1, picBoxCanvas.Height);
y = randNum.Next(1, picBoxCanvas.Width);
xChange = randNum.Next(1, 10); yChange = randNum.Next(1, 10);
}
private void timer1_Tick(object sender, EventArgs e)
{
int brushSize;
x = x + xChange;
y = y + yChange;
if (x >= picBoxCanvas.Width)
xChange = -xChange;
if (y >= picBoxCanvas.Height)
yChange = -yChange;
if (x <= 0)
xChange = -xChange;
if (y <= 0)
yChange = -yChange;
canvas.Clear(Color.Black);
brushSize = 15;
canvas.FillEllipse(brush, x, y, brushSize, brushSize);
}
private void btnCoin_Click(object sender, EventArgs e)
{
int CoinClick;
CoinClick = btnPlay_Click(object sender, EventArgs e)
for (int count = 0; count <= 5; count++)
{
}
}
}
}
我需要程序运行,所以当按下 coinClick 按钮时开始计数播放按钮,该按钮在 5 次将产生错误(不太在意那个位),努力委派按钮播放任何帮助将不胜感激谢谢你