拼图游戏源码,部分代码:
private void InitializeLocations()
{
List allLocations = new List();
allLocations.Clear();
int getRandNumber = rand.Next(1, 17);
allLocations.Add(getRandNumber);
spaceLocation = getRandNumber;//设置空白位置
for (int i = 1; i < 16; i++)
{
while (true)
{
getRandNumber = rand.Next(1, 17);
if ((getRandNumber != spaceLocation) && !(allLocations.Contains(getRandNumber)))
{
break;
}
}
ControlLocation cl = new ControlLocation();
cl.LableNum = i;
cl.LocationNum = getRandNumber;//5~1|a|s|p|x
clList.Add(cl);
allLocations.Add(getRandNumber);
}
//循环设置每一个lable位置
foreach (ControlLocation cl in clList)
{
int lableNumber = cl.LableNum;
int locationNumber = cl.LocationNum;
string getLocation = locations[locationNumber];
string[] locationArray = getLocation.Split(',');
Label lable = (Label)this.Controls["label" + lableNumber.ToString()];
lable.Location = new System.Drawing.Point(int.Parse(locationArray[0]), int.Parse(locationArray[1]));
}
Invalidate();
}
private int SelectLocationNumber(int lableNumber)
{
int result = 0;
foreach (ControlLocation cl in clList)
{
if (cl.LableNum == lableNumber)
{
result=cl.LocationNum;
}
}
return result;
}
2022-06-25 14:07:40
2.05MB
c#
游戏
源码
1