标题:大家可否提示一下解题思路啊?
只看楼主
zsk503
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-5-17
 问题点数:0 回复次数:5 
大家可否提示一下解题思路啊?
我下了一个贪食蛇的源程序,问题在于它是怎么动的?这一点看不明白,主要代码:
bool flag = true;     
int fangx = 2;  // fangx 代表的是什么???不懂
 Point dou = new Point()
LinkedList<Point> ll = new LinkedList<Point>()
void F_Move()

        {

            Point first = ll.First.Value;//ll表示双向链表
            switch (fangx)
            {
                case 0:
                    {
                        if (flag)
                        {
                            if (first.Y == 0)//为什么坐标是这样?不懂

                            {
                                first.Y = 40;
                            }
                        }
                        ll.AddFirst(new Point(first.X, --first.Y ));
                        break;
                    }
                case 1:
                    {
                        if (flag)
                        {
                            if (first.X == 0)//为什么坐标是这样?不懂
                            {
                                first.X = 40;
                            }
                        }
                        ll.AddFirst(new Point(--first.X, first.Y));
                        break;
                    }
                case 2:
                    {
                        if (flag)
                        {
                            if (first.X == 39)
                            {
                                first.X = -1;
                            }
                        }
                        ll.AddFirst(new Point(++first.X, first.Y));//不懂?????
                        break;
                    }
                case 3:
                    {
                        if (flag)
                        {
                            if (first.Y == 39)//不懂??
                            {
                                first.Y = -1;
                            }
                        }
                        ll.AddFirst(new Point(first.X, ++first.Y ));
                        break;
                    }
            }
            if (first.Equals(dou))
            {
                F_score();//获得分数
                dou = F_getdou();
            }
            else
            {
                ll.RemoveLast();
            }
            int i = 0;
            foreach (Point p in ll)
            {
                if (p.Equals(first))
                {
                    i++;
                }
            }
            if (first.X > 39 || first.X < 0 || first.Y > 39 || first.Y < 0 || i > 1)//不懂???
            {
                F_Over();//结束
                return;
            }
            F_paint();
        }

      Point  F_getdou()
        {
            int i = new Random().Next(1690);
            return  new Point(i / 40, i % 40);
        }
//
搜索更多相关主题的帖子: 思路 解题 提示 
2008-10-07 23:37
duanchangren
Rank: 1
等 级:新手上路
威 望:1
帖 子:252
专家分:0
注 册:2008-7-26
得分:0 
2008-10-08 00:56
candy110
Rank: 1
等 级:新手上路
帖 子:146
专家分:0
注 册:2008-9-25
得分:0 
2008-10-08 08:23
小瘪三的烦恼
Rank: 1
等 级:新手上路
帖 子:86
专家分:3
注 册:2008-9-20
得分:0 
游戏编程要用到人工智能.........
2008-10-08 19:11
hellson
Rank: 2
来 自:北京
等 级:新手上路
威 望:4
帖 子:195
专家分:0
注 册:2008-9-1
得分:0 
first.Y == 0 的时候蛇头部就不能再往上移动了,要挂掉,就赋成范围外值用来后边判断
ll.AddFirst(new Point(first.X, --first.Y ));
使得在当前蛇头纵坐标-1的位置变长一截,效果就是往上前进了

if (first.Equals(dou))
如果吃到豆就得分,没吃到话尾巴减1,实际长度就不变了

if (first.X > 39 || first.X < 0 || first.Y > 39 || first.Y < 0 || i > 1)
移动出边框了,挂掉啦

春了夏了秋冬了,来了来了又来了
相信我的帖子打开都很快,看我头像就知道了
2008-10-08 19:44
hellson
Rank: 2
来 自:北京
等 级:新手上路
威 望:4
帖 子:195
专家分:0
注 册:2008-9-1
得分:0 
if (first.X > 39 || first.X < 0 || first.Y > 39 || first.Y < 0 || i > 1)
哦还有个i > 1 是蛇撞到自己了

春了夏了秋冬了,来了来了又来了
相信我的帖子打开都很快,看我头像就知道了
2008-10-08 20:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-236905-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.435869 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved