| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1310 人关注过本帖
标题:求帮忙看下刚刚弄的贪吃蛇为什么不能动?
只看楼主 加入收藏
QJlin
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:186
专家分:560
注 册:2013-5-18
结帖率:100%
收藏
 问题点数:0 回复次数:10 
求帮忙看下刚刚弄的贪吃蛇为什么不能动?
Snake.rar (46.94 KB)
附上源代码求指导!100分结贴!
搜索更多相关主题的帖子: 源代码 贪吃蛇 
2013-06-12 15:36
QJlin
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:186
专家分:560
注 册:2013-5-18
收藏
得分:0 
等待英雄的出现,先自己坐个沙发!

慢慢前进走,不求一步登天,只求慢慢前进
2013-06-12 20:10
QJlin
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:186
专家分:560
注 册:2013-5-18
收藏
得分:0 
我自己调试出来了····

慢慢前进走,不求一步登天,只求慢慢前进
2013-06-12 20:31
lxb932979339
Rank: 5Rank: 5
等 级:职业侠客
威 望:4
帖 子:84
专家分:313
注 册:2013-4-24
收藏
得分:0 
private void StartGame()
        {
            Dsnake = new Ds(Putfood);
            this.Invoke(Dsnake, null);
            while (true)
            {
                Thread.Sleep(speed);
                if (isGameover())
                {
                    MessageBox.Show("GAME OVER");
                    try
                    {
                        thread.Abort();
                    }
                    catch
                    {
                    }
                }
                if (sb.HasEatfood(temppoint))
                {
                    Dsnake = new Ds(Killfood);
                    this.Invoke(Dsnake, null);
                    Dsnake = new Ds(Putfood);
                    this.Invoke(Dsnake, null);
                }
                Dsnake = new Ds(Movesnakes);
                this.Invoke(Dsnake, null);
            }
            
        } 有待于完善
2013-06-12 20:52
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
private void StartGame()
        {
            Dsnake = new Ds(Putfood);
            this.Invoke(Dsnake, null);

            while (true)
            {
                Thread.Sleep(speed);

                if (sb.HasEatfood(temppoint))
                {
                    Dsnake = new Ds(Killfood);
                    this.Invoke(Dsnake, null);
                    Dsnake = new Ds(Putfood);
                    this.Invoke(Dsnake, null);
                }

                Dsnake = new Ds(Movesnakes);
                this.Invoke(Dsnake, null);

                if (isGameover())
                {
                    MessageBox.Show("GAME OVER");
                    try
                    {
                        thread.Abort();
                    }
                    catch
                    {
                    }
                }
            }

            //if(sb.HasEatfood(temppoint))
            //{
            //    Dsnake = new Ds(Killfood);
            //    this.Invoke(Dsnake, null);
            //    Dsnake = new Ds(Putfood);
            //    this.Invoke(Dsnake, null);
            //}

            //Dsnake = new Ds(Movesnakes);
            //this.Invoke(Dsnake, null);
        }
form1中的StartGame方法,如上代码,将注释代码放入while中即可
不过除此以外,程序还有不少bug,但应该都是些小问题
2013-06-12 20:56
QJlin
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:186
专家分:560
注 册:2013-5-18
收藏
得分:0 
以下是引用lxb932979339在2013-6-12 20:52:43的发言:

 private void StartGame()
        {
            Dsnake = new Ds(Putfood);
            this.Invoke(Dsnake, null);
            while (true)
            {
                Thread.Sleep(speed);
                if (isGameover())
                {
                    MessageBox.Show("GAME OVER");
                    try
                    {
                        thread.Abort();
                    }
                    catch
                    {
                    }
                }
                if (sb.HasEatfood(temppoint))
                {
                    Dsnake = new Ds(Killfood);
                    this.Invoke(Dsnake, null);
                    Dsnake = new Ds(Putfood);
                    this.Invoke(Dsnake, null);
                }
                Dsnake = new Ds(Movesnakes);
                this.Invoke(Dsnake, null);
            }
            
        } 有待于完善

大神,现在我想它GameOver之后我按确定键盘之后把窗口关了怎么办
 if (dr == DialogResult.OK)
                    {
                       求补充!
                    }
                    我自己写的this.close()它跳进disopse里面()我不会弄···求帮助!

慢慢前进走,不求一步登天,只求慢慢前进
2013-06-12 21:49
QJlin
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:186
专家分:560
注 册:2013-5-18
收藏
得分:0 
以下是引用yhlvht在2013-6-12 20:56:56的发言:

private void StartGame()
        {
            Dsnake = new Ds(Putfood);
            this.Invoke(Dsnake, null);

            while (true)
            {
                Thread.Sleep(speed);

                if (sb.HasEatfood(temppoint))
                {
                    Dsnake = new Ds(Killfood);
                    this.Invoke(Dsnake, null);
                    Dsnake = new Ds(Putfood);
                    this.Invoke(Dsnake, null);
                }

                Dsnake = new Ds(Movesnakes);
                this.Invoke(Dsnake, null);

                if (isGameover())
                {
                    MessageBox.Show("GAME OVER");
                    try
                    {
                        thread.Abort();
                    }
                    catch
                    {
                    }
                }
            }

            //if(sb.HasEatfood(temppoint))
            //{
            //    Dsnake = new Ds(Killfood);
            //    this.Invoke(Dsnake, null);
            //    Dsnake = new Ds(Putfood);
            //    this.Invoke(Dsnake, null);
            //}

            //Dsnake = new Ds(Movesnakes);
            //this.Invoke(Dsnake, null);
        }
form1中的StartGame方法,如上代码,将注释代码放入while中即可
不过除此以外,程序还有不少bug,但应该都是些小问题

我也是这样调回来的,我发现它没跳进那里我仔细看了下发现做的时候{}放错了
现在关闭窗口我不会求指导 if (dr == DialogResult.OK)
                    {
                        求补充
                        
                    }
我本来打的是this.close()但是它跳到disopse()里面我不会弄求教下!

慢慢前进走,不求一步登天,只求慢慢前进
2013-06-12 21:52
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
窗体上放个timer
 private void 开始ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sb.DrawSnake();
            thread = new Thread(new ThreadStart(StartGame));
            thread.Start();
            Drawsnake();
            timer1.Enabled = true;
            this.Focus();
        }

       private void timer1_Tick(object sender, EventArgs e)
        {
            if (thread != null && thread.ThreadState == ThreadState.Stopped)
            {
                timer1.Enabled = false;
                this.Close();
            }
        }
2013-06-13 00:37
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
private void StartGame()
        {
            Dsnake = new Ds(Putfood);
            this.Invoke(Dsnake, null);

            while (true)
            {
                Thread.Sleep(speed);

                if (sb.HasEatfood(temppoint))
                {
                    Dsnake = new Ds(Killfood);
                    this.Invoke(Dsnake, null);
                    Dsnake = new Ds(Putfood);
                    this.Invoke(Dsnake, null);
                }

                Dsnake = new Ds(Movesnakes);
                this.Invoke(Dsnake, null);

                if (isGameover())
                {
                    MessageBox.Show("GAME OVER");
                    Dsnake = new Ds(closeForm);
                    this.Invoke(Dsnake, null);

                    try
                    {
                        thread.Abort();
                        
                    }
                    catch
                    {
                    }
                }
              
            }        
        }

private void closeForm()
        {
            this.Close();
        }
2013-06-13 00:44
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
以上2种方法都可
2013-06-13 00:52
快速回复:求帮忙看下刚刚弄的贪吃蛇为什么不能动?
数据加载中...
 
   



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

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