随机函数调用时间间隔太短了,所以得到的是同一个值,把你程序改了一下.
int StochasticX()
{
System.Threading.Thread.Sleep(1);
Random rand = new Random();
return rand.Next(0, this.Size.Width - pictureBox1.Width);
}
int StochasticY()
{
System.Threading.Thread.Sleep(1);
Random rand = new Random();
return rand.Next(0, this.Size.Height - pictureBox1.Height);
}
private void Form1_Load(object sender, EventArgs e)
{
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
t.Interval = 100;
t.Tick += new EventHandler(t_Tick);
t.Enabled = true;
}
void t_Tick(object sender, EventArgs e)
{
pictureBox1.Location = new Point(StochasticX(), StochasticY());
}
要做 打地鼠吗?
怎么感觉差不多~
我写在timer 里了 先把picturebox 隐藏 获取新的随即数(坐标)
在新坐标显示 地鼠随即出现;
锤子打中后:
点击后图片变换 就用两个picturebox 就行了
点中的时候,让剑的那个picturebox 显示在 原图片的位置(location(x,y))