作者: 乔克斯
查看: 9258|回复: 14

主题标签Tag

打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
楼主
乔克斯 发表于 2014-8-19 15:30:56 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
查看: 9258|回复: 14
效果图:
1.开始界面。

2.第一关。

2.第二关。


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

部分代码:
[C#] 纯文本查看 复制代码
/// <summary>
        /// 给list赋值,得到点击位置周围相同的星星
        /// </summary>
        /// <param name="x">横坐标</param>
        /// <param name="y">纵坐标</param>
        /// <param name="dirction">判断的放向</param>
        /// <param name="flag"></param>
        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[i].X && y - 1 == list[i].Y && starsColor[x, y - 1] == list[i].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[i].X && y + 1 == list[i].Y && starsColor[x, y + 1] == list[i].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[i].X && y == list[i].Y && starsColor[x - 1, y] == list[i].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[i].X && y == list[i].Y && starsColor[x + 1, y] == list[i].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);
            }

        }


案例源码下载:


感谢xzh1995的开发。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏4 转播转播
回复 论坛版权

使用道具 举报

沙发
aolongxue 发表于 2014-8-21 17:29:50 | 只看该作者
感觉 很棒的样子
板凳
cjkall 发表于 2014-8-21 18:32:46 | 只看该作者
很棒  不错
地板
569794982 发表于 2014-8-21 23:54:12 | 只看该作者
  牛人啊 不错
5#
undead 发表于 2014-8-26 17:05:09 | 只看该作者
来赞一个.
回复

使用道具 举报

6#
zoney88 发表于 2015-2-13 20:34:47 | 只看该作者
赞+10086+10086
7#
liushiying18 发表于 2015-3-1 18:56:43 | 只看该作者
下载看看
回复

使用道具 举报

8#
xsy131 发表于 2015-3-5 12:05:40 | 只看该作者
下载看看
回复

使用道具 举报

9#
376389554 发表于 2016-8-12 15:55:35 | 只看该作者
金币不住``````````````````
10#
tayjiang 发表于 2017-5-8 10:51:04 | 只看该作者
感觉 很棒的样子
您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-11-25 08:13, Processed in 0.624476 second(s), 35 queries , Gzip On.

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