C#拼图游戏代码问题 5
1、if(System.IO.File.Exists(imgPath)){for(inti=0;i<RowCnt*RowCnt;i++){arrpb[i].BorderS...
1、 if (System.IO.File.Exists(imgPath))
{
for (int i = 0; i < RowCnt * RowCnt; i++)
{
arrpb[i].BorderStyle = BorderStyle.Fixed3D;
if (count == 0)
{
arrpb[i].Click += new EventHandler(PictureBox_Click);
}
}
System.Collections.ArrayList al = new System.Collections.ArrayList();
Random rand = new Random();
int randCnt = RowCnt * RowCnt - 1;//自动生成随机数的个数
while (true)
{
int randNum = rand.Next(randCnt);
if (al.IndexOf(randNum) == -1)
{
al.Add(randNum);
}
if (al.Count >= randCnt)
{
break;
}
}
int num;
for (num = 0; num < randCnt; num++)
{
arrpb[num].Location = InitializePoint[(int)al[num]];
}
arrpb[randCnt].Visible = false;
arrpb[randCnt].Location = new Point((ColCnt - 1) * piWidth, (RowCnt - 1) * piHeight);
this.Text = arrpb[randCnt].Location.X.ToString() + " " + arrpb[randCnt].Location.Y.ToString();
}
2、 void PictureBox_Click(object sender, EventArgs e)
{
Point tempPoint = ((PictureBox)sender).Location;
int x = Math.Abs(arrpb[RowCnt * RowCnt - 1].Location.X - tempPoint.X);
int y = Math.Abs(arrpb[RowCnt * RowCnt - 1].Location.Y - tempPoint.Y);
if ((x == 0 && y == piHeight) || (x == piWidth && y == 0))
{
((PictureBox)sender).Location = arrpb[RowCnt * RowCnt - 1].Location;
arrpb[RowCnt * RowCnt - 1].Location = tempPoint;
IsWin();
}
}
帮我看一下这2个代码是什么意思,主要是实现什么功能,详细一点! 展开
{
for (int i = 0; i < RowCnt * RowCnt; i++)
{
arrpb[i].BorderStyle = BorderStyle.Fixed3D;
if (count == 0)
{
arrpb[i].Click += new EventHandler(PictureBox_Click);
}
}
System.Collections.ArrayList al = new System.Collections.ArrayList();
Random rand = new Random();
int randCnt = RowCnt * RowCnt - 1;//自动生成随机数的个数
while (true)
{
int randNum = rand.Next(randCnt);
if (al.IndexOf(randNum) == -1)
{
al.Add(randNum);
}
if (al.Count >= randCnt)
{
break;
}
}
int num;
for (num = 0; num < randCnt; num++)
{
arrpb[num].Location = InitializePoint[(int)al[num]];
}
arrpb[randCnt].Visible = false;
arrpb[randCnt].Location = new Point((ColCnt - 1) * piWidth, (RowCnt - 1) * piHeight);
this.Text = arrpb[randCnt].Location.X.ToString() + " " + arrpb[randCnt].Location.Y.ToString();
}
2、 void PictureBox_Click(object sender, EventArgs e)
{
Point tempPoint = ((PictureBox)sender).Location;
int x = Math.Abs(arrpb[RowCnt * RowCnt - 1].Location.X - tempPoint.X);
int y = Math.Abs(arrpb[RowCnt * RowCnt - 1].Location.Y - tempPoint.Y);
if ((x == 0 && y == piHeight) || (x == piWidth && y == 0))
{
((PictureBox)sender).Location = arrpb[RowCnt * RowCnt - 1].Location;
arrpb[RowCnt * RowCnt - 1].Location = tempPoint;
IsWin();
}
}
帮我看一下这2个代码是什么意思,主要是实现什么功能,详细一点! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询