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

主题标签Tag

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

[复制链接]
乔克斯 发表于 2014-8-19 15:30:56 | 显示全部楼层 |阅读模式
查看: 6631|回复: 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的开发。
回复 论坛版权

使用道具 举报

aolongxue 发表于 2014-8-21 17:29:50 | 显示全部楼层
感觉 很棒的样子
cjkall 发表于 2014-8-21 18:32:46 | 显示全部楼层
很棒  不错
569794982 发表于 2014-8-21 23:54:12 | 显示全部楼层
  牛人啊 不错
undead 发表于 2014-8-26 17:05:09 | 显示全部楼层
来赞一个.
回复

使用道具 举报

zoney88 发表于 2015-2-13 20:34:47 | 显示全部楼层
赞+10086+10086
liushiying18 发表于 2015-3-1 18:56:43 | 显示全部楼层
下载看看
回复

使用道具 举报

xsy131 发表于 2015-3-5 12:05:40 | 显示全部楼层
下载看看
回复

使用道具 举报

376389554 发表于 2016-8-12 15:55:35 | 显示全部楼层
金币不住``````````````````
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, 2021-11-28 09:51, Processed in 0.406227 second(s), 37 queries , Gzip On.

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