使用线程制作小游戏
private CPictureBox cpbxSeed; //创建CPictureBox控件,用来显示农作物图像 private void cpbxSeed_Click(object sender,EventArgs e) { if(this.cpbxSeed != null && this.cpbxSeed.IsInseminate == false) //判断是否开始播种
{
this.cpbxSeed.IsInseminate = true; //表示种下,即确定位置
Thread t = new Thread(GrowProcess); //创建线程实例,用来控制农作物生长过程
t.IsBackground = true; //置为后台线程
t.Start(this.cpbxSeed); //启动线程
}
}
private void GrowProcess(object obj)
{
CPictureBox cpbx = obj as CPictureBox; //创建一个CPictureBox实例
Thread.Sleep(5000); //生长耗时5秒钟
}