| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2231 人关注过本帖
标题:我找不出错误,能帮我找出来吗?谢谢
只看楼主 加入收藏
敏敏吼
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2015-7-22
结帖率:60%
收藏
已结贴  问题点数:8 回复次数:10 
我找不出错误,能帮我找出来吗?谢谢
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#define N 21
int apple[3];
char score[3];
char tail[3];
void gotoxy(int x, int y)
{
    COORD pos;
    pos.X=x;
    POS.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int b)
{
    HANDLE hConsole=GetStdHandle((STD_OUTPUT_HANDLE));
    SetConsoleTextAttribute(hConsole,b);
}
int Block(char head[2])
{
    if(head[o]<1) || (head[0]>N) || (head[1]<1) || (head[1]>N)
        return 1;
    return o;
}
int Eat(char snake[2])
{
    if((snake[o]) && (snake[1]==apple[1]))
    {
        apple[0]=apple[1]=apple[2]=0;
        gotoxy(N+44,10);
        color(13);
        printf("%d",score[0]*10);
        color(11);
        return 1;
    }
    return 0;
}
void Draw(char **snake,int len)
{
    if(apple[2]){
        gotoxy(apple[1]*2,apple[0]);
        color(12);
        printf("●");
        color(11);
    }
    gotoxy(tail[1]*2,tail[0]);
    if(tail[2])
    {
        color(14);
        printf("★");
        color(11);
    }
    else
        printf("■");
    gotoxy(snake[0][1]*2,snake[0][0]);
    color(14);
    printf("★");
    color(11);
    putchar("\n");
}
char**Move(char**snake,char dirx,int*len)
{
    int i,full=Eat(snake[0]);
    memcpy(tail,snake[(*len)-1],2);
    for(i=(*len)-1;i>0;--i)
        memcpy(snake[i],snake[i-1],2);
    switch (dirx)
    {
    case'w':case'W':--snake[o][o];break;
    case's':case'S':++snake[0][0];break;
    case'a':case'A':--snake[0][1];break;
    case'd':case'D':++snake[0][1];break;
        default;
    }
    if(full)
    {
        snake=(char**)realloc(snake,sizeof(char*)*((*len)+1));
        snake[(*len)]=(char*)malloc(sizeof(char)*2);
        memcpy(snake[(*len)],tail,2);
        ++(*len);
        ++score[0];
        if(score[0]);
        if(score[3]<16)
            ++score[3];
        tail[2]=1;
    }
    else
        tail[2]=0;
    return snake;
}
void int(char plate[N+2][N+2],    char***snake_x,int*len)
{
    int i,j;
    char**snake=NULL;

    *len=3;
    score[0]=score[3]=3;
    snake=(char**)realloc(snake,sizeof(char*)*(*len));
    for(i=0;i<*len;++i)
        snake[i]=(char*)malloc(sizeof(char*)*(*len));
    snake[i]=(char*)malloc(sizeof(char)*2);
    for(i=0;i<3;i++)
    {
        snake[i][0]=N/2+1;
        snake[i][1]=N/2+1+i;
    }
    for(i=1;i<=N;++i)
        for(j=1;j<=N;++j)
            plate[i][j]=1;

        apple[0]=rand()%N+1;apple[1]=rand()%N+1;
        apple[2]=1;

        for(i=0;i<N+2;++i)
        {
            gotoxy(0,1);
            for(j=0;j<N+2;++j)
            {
                switch(plate[i][j])
                {
                    case 0;
                        color(12);printf("□")color(11);continue;
                case 1:priintf("■");continue;
                    default;
                }
                putchar('\n');
            }
            for(i=0;i<(*len);++i)
            {
                gotoxy(sanke[i][1]*2,snake[i][0]);
                printf("★");
            }
            putchar('\n');
            *snake_x=snake;
        }

        void Manual()
        {
            gotoxy(N+30,2);
            color(10);
            printf("按 W S A D 移动方向");
                gotoxy(N+30,4);
            printf("按 space 键暂停");
            gotoxy(N+30,8);
            color(11);
            printf("历史最高分为:");
            color(12);
            gotoxy(N+44,8);
            printf("%d",score[1]*10);
            color(11);
            gotoxy(N+30,12);
            printf("你现在的得分为:0");
        }
        int File_in()
        {
            FILE*fp;
            if((fp=fopen("C:\\tcs.txt","a+"))==NULL)
            {
                gotoxy(N+18,N+2);
                printf("文件不能打开\n");
                exit(0);
            }
            if((score[1]=fgetc(fp))!=EOF);
            else
                score[1]=0;
            return 0;
        }
        
        int File_out()
        {
            FILE*fp;
            if(score[1]>score[0])
            {gotoxy(10,10);
            color(12);
            puts("闯关失败,加油耶");
            gotoxy(0,N+2);
            return 0;
            }
            if((fp=fopen("C:\\tcs.txt","w+"))==NULL)
            {
                printf("文件不能打开\n");
                exit(0);
            }
            if(fput(--score[0],fp)==EOF)
                printf("输出失败\n");
            gotoxy(10,10);
            color(12);
            puts("恭喜您打破记录");
            gotoxy(0,N+2);
            return 0;
        }

        void Free(char**snake,int len)
        {
            int i;
            for(i=0;i<len;++i)
                free(snake[i]);
            free(snake);
        }
        int main(void)
        {
            int len;
            char ch = 'g';
            char a[N+2][N+2]={{0}};
                char**snake;
            srand((unsigned)time(NULL));
            color(11);
            File_int();
            int(a,&snake,&len);
            manual();
            while(ch!=0x1B)
            {
                Draw(snake,len);
                if(!apple[2]){
                    apple[0] = rand()%N+1;
                    apple[1] = rand()%N+1;
                    apple[2] = 1;
                }
                Sleep(200-score[3]*10);
                setbuf(stdin,NULL);
                if(kbhit())
                {
                    gotoxy(o,N+2);
                    ch = getche();
                }
                snake = Move(snake,ch,&len);
                if(Block(snake[0])==1)
                {
                    gotoxy(N+2,N+2);
                    PUTS("你输了");
                    File_out();
                    Free(snake,len);
                    getche();
                    exit(0);
                }
            }
            Free(snake,len);
            exit(0);
搜索更多相关主题的帖子: color apple include 
2015-07-27 11:02
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:4 
啥错误

DO IT YOURSELF !
2015-07-27 11:17
敏敏吼
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2015-7-22
收藏
得分:0 
回复 2楼 wp231957
tudio c++ 6.0\myprojects\sio\sio.c(14) : error C2065: 'pos' : undeclared identifier
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(14) : error C2224: left of '.X' must have struct/union type
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(15) : error C2065: 'POS' : undeclared identifier
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(15) : error C2224: left of '.Y' must have struct/union type
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(16) : error C2115: 'function' : incompatible types
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(16) : warning C4024: 'SetConsoleCursorPosition' : different types for formal and actual parameter 2
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(25) : error C2065: 'o' : undeclared identifier
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(25) : error C2143: syntax error : missing ';' before '||'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(63) : warning C4047: 'function' : 'int ' differs in levels of indirection from 'char [2]'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(63) : warning C4024: '_flsbuf' : different types for formal and actual parameter 1
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(77) : error C2143: syntax error : missing ':' before ';'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(95) : error C2120: 'void' illegal with all types
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(95) : error C2059: syntax error : 'type'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(145) : error C2018: unknown character '0xa3'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(145) : error C2018: unknown character '0xbb'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(208) : error C2018: unknown character '0xa3'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(208) : error C2018: unknown character '0xbb'
d:\软件\microsoft visual studio c++ 6.0\myprojects\sio\sio.c(243) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

sio.obj - 1 error(s), 0 warning(s)
2015-07-27 11:19
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
COORD pos;


这是啥鸟

DO IT YOURSELF !
2015-07-27 11:21
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:4 
3楼是一早就要贴出来的东西,别等人问,这是可看出你是否有诚意的行为。那些被人晾起的求助帖,基本上是这类。

授人以渔,不授人以鱼。
2015-07-27 11:22
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
你的vc++6没Windows.h吧,怎么会没报告没找到这个头?

授人以渔,不授人以鱼。
2015-07-27 11:25
敏敏吼
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2015-7-22
收藏
得分:0 
回复 5楼 TonyDeng
什么意思啊?是在说吗吗?
2015-07-27 11:26
敏敏吼
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2015-7-22
收藏
得分:0 
回复 6楼 TonyDeng
我也不懂啊,今早看到这个小游戏代码一激动就自己照着打下来了,我只是个新手。
2015-07-27 11:27
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
COORD是Windows.h中定义的结构类型,那个错误信息说pos没定义,就是COORD定义没了。在vs2010以上这个是没问题的,我从不用vc++6,所以难解释这是为什么。

授人以渔,不授人以鱼。
2015-07-27 11:31
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
以下是引用敏敏吼在2015-7-27 11:26:17的发言:

什么意思啊?是在说吗吗?

求助最重要的,是把情况描述清楚,包括错误信息、现象、自己做了什么出现这个等等。仅仅把代码贴上来,就问“为什么”,等于去看医生,不说病情,开口问自己有什么病。以后注意了,我想锁这类帖子很久了,一直忍着,等到忍不下去了,锁、删都照做不解释。

授人以渔,不授人以鱼。
2015-07-27 11:34
快速回复:我找不出错误,能帮我找出来吗?谢谢
数据加载中...
 
   



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

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