| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 646 人关注过本帖
标题:求大神帮我分析下程序
只看楼主 加入收藏
qmcx
Rank: 2
等 级:论坛游民
帖 子:17
专家分:27
注 册:2014-8-24
结帖率:0
收藏
已结贴  问题点数:30 回复次数:6 
求大神帮我分析下程序
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>

typedef struct snake
{
    int a;
    int b;
    struct snake *u;
    struct snake *n;
}snake,*snake1;
typedef struct food
{
    int a;
    int b;
}food;
void main()
{   
    char c,c0 = 'd';
    int i,j,k,n=1,t,at;
    snake p,q;
    snake *dd,*dd0,*dd1,*dd2;
    food f;
    srand(time(NULL));
    p.u = NULL;
    p.n = &q;
    p.a = 5;p.b = 6;q.a = 5;q.b = 5;
    q.u = &p;q.n = NULL;
    dd=dd2= &q;
    f.a=(rand()%15+1);
    f.b=(rand()%15+1);
    while(1)
    {
        srand(time(NULL));
        system("cls");
        for(i = 0;i < 17;i ++)
        {
            for(j = 0; j < 17;j++)
            {

                if(i == 0 )
                    printf("▁");
                else if(i == 16)
                    printf("▔");
                else if(j == 0)
                    printf("▕");
                else if(j == 16)
                    printf("▏");
                else if(i == p.a && j == p.b)
                    printf("○");
                else if(i == f.a && j == f.b)
                    printf("★");
                else
                {
                    t = 0;
                    dd = dd2;
                    for(k = 0; k < n ;k++)
                    {
                        if(i == dd->a && j == dd->b)
                        {
                            printf("□");
                            t = 1;
                            break;
                        }
            
                        dd = dd->u;   
                    }
                    if(t == 0)
                        printf("  ");
                }
               
            }printf("\n");
        }
        at = 0;
        dd =dd2;
        for(i=0;i<n;i++)
        {
            if(p.a == dd->a  && p.b == dd->b)
            {
                printf("you are game over!!\n");
                getchar();
                exit(0);
            }
            dd = dd->u;
        }
        if(p.a == f.a && p.b == f.b)
        {
            dd = dd2;
            at =1;
            f.a = (rand()%15+1);
            f.b = (rand()%15+1);
            for(i=0;i<n;i++)
            {
                if(f.a == dd->a && f.b == dd->b)
                {
                    f.a = dd2->a;
                    f.b = dd2->b;
                    break;
                }
            }
            n++;
        }
        if(kbhit())
        {
            c = getch();
            dd = dd2;
            if(c == 'w' && c0 != 's')
            {
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                if(p.a == 1)
                    p.a = 15;
                else
                    p.a = (p.a-1)%15;
            }
            else if(c == 's' && c0 != 'w')
            {   
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                p.a = (p.a%15)+1;
            }
            else if(c == 'a' && c0 != 'd')
            {   
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                if(p.b == 1)
                    p.b = 15;
                else
                    p.b = (p.b-1)%15;
            }
            else if(c == 'd' && c0 != 'a')
            {   
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                p.b = (p.b%15)+1;
            }            
            else
            {
                goto qq;
            }
            c0 = c;
        }
        else
        {
qq:            if(c0 == 'w')
            {
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                if(p.a == 1)
                    p.a = 15;
                else
                    p.a=(p.a-1)%15;
            }
            else if(c0 == 's')
            {
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                p.a=(p.a%15)+1;
            }
            else if(c0 == 'a')
            {
               
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                if(p.b == 1)
                    p.b = 15;
                else
                    p.b=(p.b-1)%15;
            }
            else if(c0 == 'd')
            {
                if(at == 1)
                {
                    dd0 =(snake1)malloc(sizeof(snake));
                    dd0->a = dd2->a;dd0->b = dd2->b;
                    dd0->n = NULL;dd0->u = dd2;
                    dd2=dd0;
                }
                dd = dd2;
                for(i = 0; i<n ; i++)
                {
                    dd1 = dd->u;
                    dd->b = dd1->b;
                    dd->a = dd1->a;
                    dd = dd->u;
                }
                p.b=(p.b%15)+1;
               
            }
        }
        fflush(stdin);
        dd = &q;
        _sleep(200);
    }
}
几乎完全看不懂
求大神帮我分析下
感激不尽
搜索更多相关主题的帖子: include 
2014-08-24 21:34
cszzlsw
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:3
专家分:8
注 册:2014-8-20
收藏
得分:8 
你至少说明一下程序是干哈的,在那块看不懂了,你把程序原样贴出来是什么意思,这么长的程序让人怎么帮你看,一行一行帮你读,然后告诉你每一行是干什么的?

正在学习嵌入式中,希望能碰到志同道合的朋友或者是嵌入式的大神,走向进步!
2014-08-24 23:00
ditg
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:16
帖 子:852
专家分:1937
注 册:2014-4-10
收藏
得分:8 
贪食蛇?

梦想拥有一台龙芯3A-4000
2014-08-24 23:32
qmcx
Rank: 2
等 级:论坛游民
帖 子:17
专家分:27
注 册:2014-8-24
收藏
得分:0 
是啊,基本上看不懂
想把它变为自己的东西之前得看懂
没办法,只有找大神分析了
2014-08-25 10:42
鹏哥v5
Rank: 2
等 级:论坛游民
帖 子:18
专家分:80
注 册:2014-8-3
收藏
得分:8 
就这样怎么能让人看懂呢,来点注释啊
2014-08-25 11:22
qmcx
Rank: 2
等 级:论坛游民
帖 子:17
专家分:27
注 册:2014-8-24
收藏
得分:0 
回复 5 楼 鹏哥 v5
我要的就是注释
2014-08-25 11:26
l3456
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:80
专家分:133
注 册:2014-4-16
收藏
得分:8 
至少要说说这程序是干啥的吧,来点题目啥的,就一大串代码,什么都没有,谁有耐心看啊

走向光明的菜鸟学生,励志成为新一代程序猿
2014-08-27 11:01
快速回复:求大神帮我分析下程序
数据加载中...
 
   



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

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