嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
网络常见的2048小游戏,用了比较基础的方法去实现它。
里面涉及到了图形的绘制,用半透明的背景色。
public static void Move(int[,] mapValue, Keys key, ref int score)
{
#region Move
switch (key)
{
case Keys.W:
case Keys.Up:
{
#region KeyUp
for (int j = 0; j < 4; j )
{
int index = 0;
for (int i = 1; i < 4; i )
{
if (mapValue[i, j] == 0) continue;
for (int temp = i - 1; temp >= index; temp--)
{
if (mapValue[i, j] == mapValue[temp, j])
{
mapValue[temp, j] = mapValue[i, j];
mapValue[i, j] = 0;
score = mapValue[temp, j];
index = temp 1 > 4 ? 3 : temp 1;
}
else if (mapValue[i, j] != mapValue[temp, j] && mapValue[temp, j] != 0)
break;
}
}
}
for (int j = 0; j < 4; j )
{
for (int i = 1; i < 4; i )
{
if (mapValue[i, j] == 0) continue;
int tempMap = i;
for (int temp = i - 1; temp >= 0; temp--)
{
if (mapValue[temp, j] == 0)
{
mapValue[temp, j] = mapValue[tempMap, j];
mapValue[tempMap, j] = 0;
tempMap = temp;
}
}
}
}
#endregion
}
break;
case Keys.A:
case Keys.Left:
{
#region KeyLeft
for (int i = 0; i < 4; i )
{
int index = 0;
for (int j = 1; j < 4; j )
{
if (mapValue[i, j] == 0) continue;
for (int temp = j - 1; temp >= index; temp--)
{
if (mapValue[i, j] == mapValue[i, temp])
{
mapValue[i, temp] = mapValue[i, j];
mapValue[i, j] = 0;
score = mapValue[i, temp];
index = temp 1 > 4 ? 3 : temp 1;
}
else if (mapValue[i, j] != mapValue[i, temp] && mapValue[i, temp] != 0)
break;
}
}
}
for (int i = 0; i < 4; i )
{
for (int j = 1; j < 4; j )
{
if (mapValue[i, j] == 0) continue;
int tempMap = j;
for (int temp = j - 1; temp >= 0; temp--)
{
if (mapValue[i, temp] == 0)
{
mapValue[i, temp] = mapValue[i, tempMap];
mapValue[i, tempMap] = 0;
tempMap = temp;
}
}
}
}
#endregion
}
break;
case Keys.S:
case Keys.Down:
{
#region KeyDown
for (int j = 0; j < 4; j )
{
int index = 4;
for (int i = 2; i >= 0; i--)
{
if (mapValue[i, j] == 0) continue;
for (int temp = i 1; temp < index; temp )
{
if (mapValue[i, j] == mapValue[temp, j])
{
mapValue[temp, j] = mapValue[i, j];
mapValue[i, j] = 0;
score = mapValue[temp, j];
index = temp - 1 <= 0 ? 0 : temp - 1;
}
else if (mapValue[i, j] != mapValue[temp, j] && mapValue[temp, j] != 0)
break;
}
}
}
for (int j = 0; j < 4; j )
{
for (int i = 2; i >= 0; i--)
{
if (mapValue[i, j] == 0) continue;
int tempMap = i;
for (int temp = i 1; temp < 4; temp )
{
if (mapValue[temp, j] == 0)
{
mapValue[temp, j] = mapValue[tempMap, j];
mapValue[tempMap, j] = 0;
tempMap = temp;
}
}
}
}
#endregion
}
break;
case Keys.D:
case Keys.Right:
{
#region KeyRight
for (int i = 0; i < 4; i )
{
int index = 4;
for (int j = 2; j >= 0; j--)
{
if (mapValue[i, j] == 0) continue;
for (int temp = j 1; temp < index; temp )
{
if (mapValue[i, j] == mapValue[i, temp])
{
mapValue[i, temp] = mapValue[i, j];
mapValue[i, j] = 0;
score = mapValue[i, temp];
index = temp - 1 <= 0 ? 0 : temp - 1;
}
else if (mapValue[i, j] != mapValue[i, temp] && mapValue[i, temp] != 0)
break;
}
}
}
for (int i = 0; i < 4; i )
{
for (int j = 2; j >= 0; j--)
{
if (mapValue[i, j] == 0) continue;
int tempMap = j;
for (int temp = j 1; temp < 4; temp )
{
if (mapValue[i, temp] == 0)
{
mapValue[i, temp] = mapValue[i, tempMap];
mapValue[i, tempMap] = 0;
tempMap = temp;
}
}
}
}
#endregion
}
break;
default: break;
}
#endregion
}