___once。 发表于 2014-8-27 09:21:00

【消除之星游戏】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 *****

wright 发表于 2014-9-25 18:05:35

kkannnnnnnnnnnnnnnnnnnnn

roy0109 发表于 2014-10-20 18:06:43

好東西,收藏學習

Eisai 发表于 2014-12-13 23:10:35

感谢CSDN的xzh1995

214207639 发表于 2014-12-20 16:26:26

谢谢分享!

bbspcs 发表于 2014-12-21 15:11:46

消除之星游戏

眯眼笑 发表于 2014-12-23 15:49:54

谢谢分享~~~~~~~~~~~~~

zhzhk1989 发表于 2014-12-23 19:04:35

好東西,收藏學習

wingswings 发表于 2015-2-4 15:37:17

WWW.DXPER.NETWWW.DXPER.NET

goober520 发表于 2015-2-6 15:51:18

学习~~~学习~~~学习~~~

jiliangstc2012 发表于 2015-2-9 09:22:41

赞一个先

freelandy 发表于 2015-4-29 16:37:29

下来学学,多谢分享。

jimina 发表于 2015-8-17 09:21:57

看看,学习一下

xfly_t 发表于 2015-8-17 11:35:45

谢谢分享

kirsten 发表于 2015-8-18 10:50:04

很全面,很给力,谢谢啦

icemangd 发表于 2015-9-4 09:59:13

很有意思谢谢分享

becklee 发表于 2015-10-4 22:46:36

谢谢楼主分享

emojinglingapm0 发表于 2015-10-20 11:02:34

下一个学习学习

chanlei001 发表于 2015-10-26 11:30:38

好东西,学习了

yangdada 发表于 2015-11-2 10:27:45


好東西,收藏學習

肥猪爱吃鱼 发表于 2015-12-3 21:16:15

要看看,学习下

chehongyu 发表于 2015-12-9 16:09:20

好東西,收藏學習

gjq1101 发表于 2015-12-17 13:48:20

太好了,下来看看

qiaohongdian 发表于 2015-12-19 12:27:36

dasfd asdf asdf

quink 发表于 2015-12-22 12:58:01

感谢楼主分享

AASA 发表于 2015-12-22 16:01:00

liuweisheng 发表于 2015-12-25 11:11:48

源码呢?

sailor1109 发表于 2016-1-1 21:40:30

楼主多发这样的帖子

xdfanfan 发表于 2016-1-5 10:17:41

CSDN,看图片应该不错

zjm521 发表于 2016-1-8 16:28:56

这个比较有意思
页: [1] 2 3
查看完整版本: 【消除之星游戏】C#仿照苹果手机上的消除之星-转帖