【文件属性】:
文件名称:C#拱猪游戏源码
文件大小:362KB
文件格式:ZIP
更新时间:2017-04-08 09:49:12
C# 游戏 源码
C#拱猪游戏源码,,源码,可运行.部分源码:
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;
}
private string[] getDetailsLocation(int index)
{
return locations[index].Split(',');
}
private void Cell_Click(object sender, EventArgs e)
{
Label lab = (Label)sender;
string lableNumber = lab.Tag.ToString();
int getClickLableNumber = int.Parse(lableNumber);
//判断是否可以移动
bool bCanMove = JudgeCanMove(SelectLocationNumber(getClickLableNumber).ToString());
if (bCanMove)
{
int getLocationNumber=SelectLocationNumber(getClickLableNumber);
if (getClickLableNumber != 0)
{
string[] getLocationsSpace = getDetailsLocation(spaceLocation);
Label labWillMove = (Label)this.Controls["label" + lableNumber];
labWillMove.Location = new Point(int.Parse(getLocationsSpace[0]), int.Parse(getLocationsSpace[1]));
UpdateClList(getClickLableNumber, spaceLocation);
spaceLocation = getLocationNumber;
}
else
{
MessageBox.Show("没有找到对应位置为0的!");
}
}
}