所以我是 C# 编程的新手,我正在创建一个带有图形的连接四游戏。我有一个带圆圈的网格。我需要做的是,当用户点击某个列时,看到芯片向下移动。我需要使用计时器或其他东西吗?还是我做一个循环,也许每次都给一个较小的 yCoordinate 向下移动圆圈?
另外,有没有办法让这个圆圈不会与网格重叠?如,我可以让它看起来好像它正在网格后面移动吗?
这是我到目前为止所做的......
private int columnPosition = 0;
private int xCoordinate;
private int yCoordinate;
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = grid.CreateGraphics();
Pen pen = new Pen(Color.White, 1);
Pen pen2 = new Pen(Color.Black, 4);
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 6; j++)
{
g.DrawEllipse(pen2, new System.Drawing.Rectangle((i * 70) + 20, (j * 60) + 10, 50, 50));
g.FillEllipse(pen.Brush, new System.Drawing.Rectangle((i *70) + 20, (j * 60) + 10, 50, 50));
}
}
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
Graphics g = panel2.CreateGraphics();
Pen pen = new Pen(Color.Red, 5);
Pen pen2 = new Pen(Color.Black, 3);
if (columnPosition != -1)
{
g.DrawEllipse(pen2, new System.Drawing.Rectangle(columnPosition * 35 - 15, 0, 50, 50));
g.FillEllipse(pen.Brush, new System.Drawing.Rectangle(columnPosition * 35 - 15, 0, 50, 50));
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
columnPosition = e.X / 35;
Console.WriteLine(e.X);
panel2.Refresh();
}
private void panel1_MouseLeave(object sender, EventArgs e)
{
columnPosition = -1;
panel2.Refresh();
}
private void panel1_MouseClick(object sender, EventArgs e)
{
///// THIS IS WHERE I AM STUCK
}
}
抱歉,我想上传网格的图像,但由于我是新用户,我不能 -.- !!
在此先感谢您的帮助:)