开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 11983|回复: 62

[源码] 【消除之星游戏】C#仿照苹果手机上的消除之星-转帖

  [复制链接]

0

精华

123

贡献

130

赞扬

版主

帖子
20
软币
557
在线时间
45 小时
注册时间
2014-3-1
发表于 2014-8-27 09:21:00 | 显示全部楼层 |阅读模式
效果图:
1.开始界面。

152818ir8f4azppc0m4mzf.png
2.第一关。
152817v16pxpj6h8kxu511.png
2.第二关。
152817c4opfuv8dqv4ssrr.png

实现思路:说一下设计思路,主要就是根据用户点击的是哪个星星判断他周围有多少个与他相同的星星


部分代码:

[C#] 纯文本查看 复制代码
/// 

/// 给list赋值,得到点击位置周围相同的星星

/// 

/// 横坐标

/// 纵坐标

/// 判断的放向

/// 

void GetAround(int x, int y, Direction dirction = Direction.Null, int flag = 1)

{

if (starsColor[x, y] == StarColor.White)

return;

if (dirction == Direction.Null)

{

list.Clear();

list.Add(new StarInfo(x, y, starsColor[x, y], 1));

starsFlag[x, y] = 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[x, y - 1] == list.Color)

{

return;

}

}

if (starsColor[x, y] == starsColor[x, y - 1])

{

list.Add(new StarInfo(x, y - 1, starsColor[x, y - 1], 1));

starsFlag[x, y - 1] = 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[x, y + 1] == list.Color)

{

return;

}

}

if (starsColor[x, y] == starsColor[x, y + 1])

{

list.Add(new StarInfo(x, y + 1, starsColor[x, y + 1], 1));

starsFlag[x, y + 1] = 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[x - 1, y] == list.Color)

{

return;

}

}

if (starsColor[x, y] == starsColor[x - 1, y])

{

list.Add(new StarInfo(x - 1, y, starsColor[x - 1, y], 1));

starsFlag[x - 1, y] = 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[x + 1, y] == list.Color)

{

return;

}

}

if (starsColor[x, y] == starsColor[x + 1, y])

{

list.Add(new StarInfo(x + 1, y, starsColor[x + 1, y], 1));



starsFlag[x + 1, y] = 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的开发。
附件下载回复可见
游客,如果您要查看本帖隐藏内容请回复

评分

参与人数 1赞扬 +1 收起 理由
maple + 1 赞一个

查看全部评分

回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
72
软币
638
在线时间
82 小时
注册时间
2014-7-18
发表于 2014-9-25 18:05:35 | 显示全部楼层
kkannnnnnnnnnnnnnnnnnnnn
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
99
软币
315
在线时间
36 小时
注册时间
2013-8-29
发表于 2014-10-20 18:06:43 | 显示全部楼层
好東西,收藏學習
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
25
软币
80
在线时间
0 小时
注册时间
2014-12-13
发表于 2014-12-13 23:10:35 | 显示全部楼层
感谢CSDN的xzh1995
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
29
软币
159
在线时间
8 小时
注册时间
2014-10-30
发表于 2014-12-21 15:11:46 | 显示全部楼层
消除之星游戏
回复

使用道具 举报

0

精华

0

贡献

250

赞扬

帖子
41
软币
598
在线时间
33 小时
注册时间
2014-12-22
发表于 2014-12-23 19:04:35 | 显示全部楼层
好東西,收藏學習
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
25
软币
110
在线时间
8 小时
注册时间
2015-2-4
发表于 2015-2-4 15:37:17 | 显示全部楼层
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
12
软币
67
在线时间
0 小时
注册时间
2015-2-6
发表于 2015-2-6 15:51:18 | 显示全部楼层
学习~~~学习~~~学习~~~
回复

使用道具 举报

0

精华

0

贡献

149

赞扬

帖子
51
软币
651
在线时间
44 小时
注册时间
2013-8-31
发表于 2015-4-29 16:37:29 | 显示全部楼层
下来学学,多谢分享。
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
74
软币
191
在线时间
17 小时
注册时间
2015-8-11
发表于 2015-8-17 09:21:57 | 显示全部楼层
看看,学习一下
回复

使用道具 举报

0

精华

2

贡献

0

赞扬

帖子
9
软币
85
在线时间
0 小时
注册时间
2015-8-18
QQ
发表于 2015-8-18 10:50:04 | 显示全部楼层
很全面,很给力,谢谢啦
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
14
软币
79
在线时间
2 小时
注册时间
2015-9-4
发表于 2015-9-4 09:59:13 | 显示全部楼层
很有意思谢谢分享
回复

使用道具 举报

0

精华

1

贡献

0

赞扬

帖子
84
软币
874
在线时间
118 小时
注册时间
2013-8-6
发表于 2015-10-4 22:46:36 | 显示全部楼层
谢谢楼主分享
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
6
软币
61
在线时间
1 小时
注册时间
2015-10-20
发表于 2015-10-20 11:02:34 | 显示全部楼层
下一个学习学习
回复

使用道具 举报

0

精华

120

贡献

73

赞扬

帖子
106
软币
266
在线时间
16 小时
注册时间
2015-10-16
发表于 2015-10-26 11:30:38 | 显示全部楼层
好东西,学习了
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
7
软币
148
在线时间
17 小时
注册时间
2015-10-23
发表于 2015-11-2 10:27:45 | 显示全部楼层

好東西,收藏學習
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
19
软币
114
在线时间
5 小时
注册时间
2015-10-20
发表于 2015-12-3 21:16:15 | 显示全部楼层
要看看,学习下
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
3
软币
83
在线时间
1 小时
注册时间
2015-12-9
发表于 2015-12-9 16:09:20 | 显示全部楼层
好東西,收藏學習
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
1
软币
76
在线时间
0 小时
注册时间
2015-12-17
发表于 2015-12-17 13:48:20 | 显示全部楼层
太好了,下来看看
回复

使用道具 举报

0

精华

-2

贡献

0

赞扬

帖子
30
软币
120
在线时间
95 小时
注册时间
2015-12-19
发表于 2015-12-19 12:27:36 | 显示全部楼层
dasfd asdf asdf
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
1
软币
86
在线时间
1 小时
注册时间
2015-12-7
发表于 2015-12-22 12:58:01 | 显示全部楼层
感谢楼主分享
回复

使用道具 举报

头像被屏蔽

0

精华

-4

贡献

0

赞扬

禁止发言

帖子
10
软币
110
在线时间
6 小时
注册时间
2015-12-22
发表于 2015-12-22 16:01:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
81
软币
341
在线时间
25 小时
注册时间
2013-11-14
发表于 2016-1-1 21:40:30 | 显示全部楼层
楼主多发这样的帖子
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
5
软币
80
在线时间
0 小时
注册时间
2016-1-5
发表于 2016-1-5 10:17:41 | 显示全部楼层
CSDN,看图片应该不错
回复

使用道具 举报

0

精华

-6

贡献

0

赞扬

帖子
13
软币
134
在线时间
7 小时
注册时间
2015-11-28
发表于 2016-1-8 16:28:56 | 显示全部楼层
这个比较有意思
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-20 02:28

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表