【消除之星游戏】C#仿照苹果手机上的消除之星-转帖
效果图:1.开始界面。
2.第一关。
2.第二关。
实现思路:说一下设计思路,主要就是根据用户点击的是哪个星星判断他周围有多少个与他相同的星星
部分代码:
///
/// 给list赋值,得到点击位置周围相同的星星
///
/// 横坐标
/// 纵坐标
/// 判断的放向
///
void GetAround(int x, int y, Direction dirction = Direction.Null, int flag = 1)
{
if (starsColor == StarColor.White)
return;
if (dirction == Direction.Null)
{
list.Clear();
list.Add(new StarInfo(x, y, starsColor, 1));
starsFlag = 1;
if (x == 0 && y == 0)
{
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Up);
}
else if (x == 9 && y == 0)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Down);
}
else if (x == 9 && y == 9)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Up);
}
else if (x == 0)
{
GetAround(x, y, Direction.Up);
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Down);
}
else if (x == 9)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Down);
GetAround(x, y, Direction.Up);
}
else if (y == 0)
{
GetAround(x, y, Direction.Right);
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Down);
}
else if (y == 9)
{
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Up);
GetAround(x, y, Direction.Right);
}
else
{
GetAround(x, y, Direction.Up);
GetAround(x, y, Direction.Down);
GetAround(x, y, Direction.Left);
GetAround(x, y, Direction.Right);
}
}
else if (dirction == Direction.Up)
{
for (int i = 0; i < list.Count; i++)
{
if (x == list.X && y - 1 == list.Y && starsColor == list.Color)
{
return;
}
}
if (starsColor == starsColor)
{
list.Add(new StarInfo(x, y - 1, starsColor, 1));
starsFlag = 1;
if (x == 0 && y == 0)
{
GetAround(x, y - 1, Direction.Right);
}
else if (x == 9 && y == 0)
{
GetAround(x, y - 1, Direction.Left);
}
else if (x == 0 && y == 9)
{
GetAround(x, y - 1, Direction.Right);
GetAround(x, y - 1, Direction.Up);
}
else if (x == 9 && y == 9)
{
GetAround(x, y - 1, Direction.Up);
GetAround(x, y - 1, Direction.Left);
}
else if (x == 0)
{
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
GetAround(x, y - 1, Direction.Right);
}
else if (x == 9)
{
GetAround(x, y - 1, Direction.Left);
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
}
else if (y == 0)
{
GetAround(x, y - 1, Direction.Left);
GetAround(x, y - 1, Direction.Right);
}
else if (y == 9)
{
GetAround(x, y - 1, Direction.Left);
GetAround(x, y - 1, Direction.Right);
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
}
else
{
GetAround(x, y - 1, Direction.Left);
GetAround(x, y - 1, Direction.Right);
if (y - 1 > 0)
{
GetAround(x, y - 1, Direction.Up);
}
}
return;
}
else return;
}
else if (dirction == Direction.Down)
{
for (int i = 0; i < list.Count; i++)
{
if (x == list.X && y + 1 == list.Y && starsColor == list.Color)
{
return;
}
}
if (starsColor == starsColor)
{
list.Add(new StarInfo(x, y + 1, starsColor, 1));
starsFlag = 1;
if (x == 0 && y == 0)
{
GetAround(x, y + 1, Direction.Right);
GetAround(x, y + 1, Direction.Down);
}
else if (x == 9 && y == 0)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x, y + 1, Direction.Right);
}
else if (x == 9 && y == 9)
{
GetAround(x, y + 1, Direction.Left);
}
else if (x == 0)
{
GetAround(x, y + 1, Direction.Right);
if (y + 1 < 9)
{
GetAround(x, y + 1, Direction.Down);
}
}
else if (x == 9)
{
GetAround(x, y + 1, Direction.Left);
if (y + 1 < 9)
{
GetAround(x, y + 1, Direction.Down);
}
}
else if (y == 0)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Right);
GetAround(x, y + 1, Direction.Down);
}
else if (y == 9)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Right);
}
else
{
if (y + 1 <= 9)
{
GetAround(x, y + 1, Direction.Left);
GetAround(x, y + 1, Direction.Right);
}
if (y + 1 < 9)
{
GetAround(x, y + 1, Direction.Down);
}
} return;
}
else return;
}
else if (dirction == Direction.Left)
{
for (int i = 0; i < list.Count; i++)
{
if (x - 1 == list.X && y == list.Y && starsColor == list.Color)
{
return;
}
}
if (starsColor == starsColor)
{
list.Add(new StarInfo(x - 1, y, starsColor, 1));
starsFlag = 1;
if (x == 0 && y == 0)
{
GetAround(x - 1, y, Direction.Down);
}
else if (x == 9 && y == 0)
{
GetAround(x - 1, y, Direction.Left);
GetAround(x - 1, y, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x - 1, y, Direction.Up);
}
else if (x == 9 && y == 9)
{
GetAround(x - 1, y, Direction.Up);
GetAround(x - 1, y, Direction.Left);
}
else if (x == 0)
{
GetAround(x - 1, y, Direction.Up);
GetAround(x - 1, y, Direction.Down);
}
else if (x == 9)
{
GetAround(x - 1, y, Direction.Left);
GetAround(x - 1, y, Direction.Down);
GetAround(x - 1, y, Direction.Up);
}
else if (y == 0)
{
if (x - 1 > 0)
{
GetAround(x - 1, y, Direction.Left);
}
GetAround(x - 1, y, Direction.Down);
}
else if (y == 9)
{
if (x - 1 > 0)
{
GetAround(x - 1, y, Direction.Left);
}
GetAround(x - 1, y, Direction.Up);
}
else
{
if (x - 1 > 0)
{
GetAround(x - 1, y, Direction.Left);
}
GetAround(x - 1, y, Direction.Up);
GetAround(x - 1, y, Direction.Down);
} return;
}
else return;
}
else if (dirction == Direction.Right)
{
for (int i = 0; i < list.Count; i++)
{
if (x + 1 == list.X && y == list.Y && starsColor == list.Color)
{
return;
}
}
if (starsColor == starsColor)
{
list.Add(new StarInfo(x + 1, y, starsColor, 1));
starsFlag = 1;
if (x == 0 && y == 0)
{
GetAround(x + 1, y, Direction.Right);
GetAround(x + 1, y, Direction.Down);
}
else if (x == 9 && y == 0)
{
GetAround(x + 1, y, Direction.Down);
}
else if (x == 0 && y == 9)
{
GetAround(x + 1, y, Direction.Right);
GetAround(x + 1, y, Direction.Up);
}
else if (x == 9 && y == 9)
{
GetAround(x + 1, y, Direction.Up);
}
else if (x == 0)
{
GetAround(x + 1, y, Direction.Up);
GetAround(x + 1, y, Direction.Right);
GetAround(x + 1, y, Direction.Down);
}
else if (x == 9)
{
GetAround(x + 1, y, Direction.Down);
GetAround(x + 1, y, Direction.Up);
}
else if (y == 0)
{
if (x + 1 < 9)
{
GetAround(x + 1, y, Direction.Right);
}
GetAround(x + 1, y, Direction.Down);
}
else if (y == 9)
{
if (x + 1 < 9)
{
GetAround(x + 1, y, Direction.Right);
}
GetAround(x + 1, y, Direction.Up);
}
else
{
GetAround(x + 1, y, Direction.Down);
GetAround(x + 1, y, Direction.Up);
if (x + 1 < 9)
{
GetAround(x + 1, y, Direction.Right);
}
} return;
}
else return;
}
if (flag == 1)
{
DrawBox(list);
}
}
- 本文出自CSkin论坛 我只是小小搬运工。感谢CSDN的xzh1995的开发。附件下载回复可见
**** Hidden Message *****
kkannnnnnnnnnnnnnnnnnnnn 好東西,收藏學習 感谢CSDN的xzh1995 谢谢分享! 消除之星游戏 谢谢分享~~~~~~~~~~~~~ 好東西,收藏學習 WWW.DXPER.NETWWW.DXPER.NET 学习~~~学习~~~学习~~~ 赞一个先 下来学学,多谢分享。 看看,学习一下 谢谢分享 很全面,很给力,谢谢啦 很有意思谢谢分享 谢谢楼主分享 下一个学习学习 好东西,学习了
好東西,收藏學習 要看看,学习下 好東西,收藏學習 太好了,下来看看 dasfd asdf asdf 感谢楼主分享 源码呢? 楼主多发这样的帖子 CSDN,看图片应该不错 这个比较有意思