徐凤年606 2021-03-28 10:09 采纳率: 100%
浏览 53
已采纳

c语言程序,求大佬帮忙看看这个到底出什么问题了?

编译器用的devc++,代码里RunGame1都没问题,一出现RunGame2就报错

报错内容:undefined reference to Rungame2()和id returned 1 exit status

#include<stdio.h>
#include<windows.h>
#include <MMSystem.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#pragma comment(lib,"Winmm.lib")

struct Message{
    char password[20];
    char word[20];
}a[10];

typedef struct Snake{
    int x;
    int y;
    struct Snake*next;
}snake;

int choice;
int speed=1;
int Judge;
int U=-1;
int m=10;
int o=0;
int n=15;
int right=1;
int score=0;
char dir=77;
char temp1[20];
char temp2[20];
char temp3[20];
snake* shead;
snake* newhead;
snake* p;
snake *t;

//欢迎界面 
void Welcome();
//改变光标的坐标
void SetcursorPosition(int x,int y);
//隐藏光标
void Setcursorhide() ;
//改变字体颜色 
void SetcursorColor(int L);
//登录注册账户
void Register(int FLAG) ;
//开始贪吃蛇游戏
void RunGame1(); 
//开始 
void RunGame2();


int main(){
     Welcome();
  
}

//欢迎 
void Welcome(){
    SetConsoleTitle("欢迎界面"); 
    int flag;
    SetcursorPosition(48,3);
    SetcursorColor(2); 
    printf("欢迎进入3399游戏");
    SetcursorPosition(40,5);
    printf("请您选择登录旧帐户或者注册新账户");
     SetcursorPosition(44,7);
     printf("1  登录账户      2.注册账户");
    SetcursorPosition(50,9);
    scanf("%d",&flag);
    system("cls");
    SetcursorColor(15); 
    
    Register(flag);

//改变光标坐标
void  SetcursorPosition(int x,int y){
    HANDLE hOut1;
    hOut1=GetStdHandle(STD_OUTPUT_HANDLE);
    COORD z={x,y};
    SetConsoleCursorPosition(hOut1,z);
}

//隐藏光标 
void Setcursorhide() 
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = false; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}

//改变字体颜色
void SetcursorColor(int L){
    HANDLE hOut2;
    hOut2=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hOut2,L);

//登录或者注册账号 
void Register(int FLAG) {
    PlaySound(TEXT("D:\\邓壬鑫-告白之夜(治愈版).wav"),NULL,SND_FILENAME | SND_ASYNC | SND_LOOP);
    SetConsoleTitle("账户登录界面"); 
    right=1;
    U++;
//如果选择创建新账户 
    if(FLAG==2){
            SetcursorPosition(35,3);
        for(int i=0;i<20;i++)
        printf("●");
        for(int i=0;i<15;i++){
            SetcursorPosition(35,3+i);
            printf("●");
        }
        SetcursorPosition(35,18);
        for(int i=0;i<20;i++)
        printf("●");
        for(int i=0;i<16;i++){
            SetcursorPosition(75,3+i);
            printf("●");
        }
        SetcursorPosition(40,6);
        printf("账 号 :");
        SetcursorPosition(40,10);
        printf("密 码 :"); 
        SetcursorPosition(40,14);
        printf("请确认密码 :"); 
        //输入新密码 
        SetcursorPosition(40,20);
        FILE *fp;
        if((fp=fopen("C:\\shuju.txt","wt+"))==NULL){
        printf("创建账户失败");
        Setcursorhide() ; 
        exit(1);
    }
       SetcursorPosition(47,6); 
       scanf("%s",a[U].password);
       getchar();
       while(right==1){
           
        SetcursorPosition(47,10);
        scanf("%s",a[U].word);
        getchar();
        SetcursorPosition(54,14);
        scanf("%s",temp1);
        getchar();
        if(strcmp(temp1,a[U].word))    {
            SetcursorPosition(40,20);
            printf("两次密码不一致,请重新输入密码");
            Sleep(2000);
            system("cls");
            SetcursorPosition(35,3);
        for(int i=0;i<20;i++)
        printf("●");
        for(int i=0;i<15;i++){
            SetcursorPosition(35,3+i);
            printf("●");
        }
        SetcursorPosition(35,18);
        for(int i=0;i<20;i++)
        printf("●");
        for(int i=0;i<16;i++){
            SetcursorPosition(75,3+i);
            printf("●");
        }
        SetcursorPosition(40,6);
        printf("账 号 :");
        SetcursorPosition(40,10);
        printf("密 码 :"); 
        SetcursorPosition(40,14);
        printf("请确认密码 :"); 
            right=1;
        }
        else
        right=0;

        }
        
        fprintf(fp,"%s\t%s\n",a[U].password,a[U].word);
        SetcursorPosition(47,21);
        printf("创建成功");
        Setcursorhide() ; 
        Sleep(2000);
        system("cls");
        Welcome();
    }
//如果选择登录旧帐户 
    if(FLAG==1){
        SetcursorPosition(35,3);
        for(int i=0;i<20;i++)
        printf("●");
        for(int i=0;i<10;i++){
            SetcursorPosition(35,3+i);
            printf("●");
        }
        SetcursorPosition(35,13);
        for(int i=0;i<20;i++)
        printf("●");
        for(int i=0;i<11;i++){
            SetcursorPosition(75,3+i);
            printf("●");
        }
        SetcursorPosition(40,6);
        printf("账 号 :");
        SetcursorPosition(40,10);
        printf("密 码 :"); 
        SetcursorPosition(47,6); 
       scanf("%s",temp2);
       getchar();
       SetcursorPosition(47,10);
        scanf("%s",temp3);
        SetcursorPosition(45,15);
        for(int p=0;p<10;p++){
        if((strcmp(temp2,a[p].password)==0)&&(strcmp(temp3,a[p].word)==0)){
            system("cls");
            SetcursorPosition(40,5);
        printf("登录成功,请选择你要进行的游戏");
         SetcursorPosition(40,10);
         printf("1. 贪吃蛇游戏");
         SetcursorPosition(40,15);
         printf("2. 游戏");
         SetcursorPosition(42,17);
         scanf("%d",&choice);
         if(choice==1)
         RunGame1(); 
        RunGame2();
        
        o=1;
    
        
        break;}
        }
        if(o==0){
        
            SetcursorColor(4);
        printf("账户不存在或密码错误");
        SetcursorPosition(45,18);
        printf("请重新登录或注册新账户");
        SetcursorPosition(43,21);
        SetcursorColor(11);
        printf("1. 重新登录 2. 注册新账户");
        SetcursorPosition(52,23);
        scanf("%d",&Judge);
        getchar();
        Sleep(1000);
        system("cls");
        if(Judge==1)
        Register(1);
        else
        Register(2);
        }
            
       
    }    
}

//贪吃蛇游戏主体部分
void RunGame1(){
    SetcursorColor(9);
    //播放背景音乐 
    PlaySound(TEXT("D:\\Joanie-Madden-Down-By-The-Salley-Gardens.wav"),NULL,SND_FILENAME | SND_ASYNC | SND_LOOP);
    SetConsoleTitle("贪吃蛇小游戏"); 
    system("cls");
    //绘制围墙 
    for(int i=0;i<25;i++){
        printf("■");
    }
    SetcursorPosition(0,0);
    for(int i=0;i<25;i++){
        SetcursorPosition(0,0+i);
        printf("■");
    }
    SetcursorPosition(50,0);
    for(int i=0;i<26;i++){
        SetcursorPosition(50,0+i);
        printf("■");
    }
    SetcursorPosition(0,25);
        for(int i=0;i<25;i++){
        printf("■");
    }
    //获得蛇头坐标
      shead=(snake*)malloc(sizeof(snake)) ;
    shead->x=18;
    shead->y=15;
    shead->next=NULL;
    
    
     //绘制蛇身
     for(int i=0;i<4;i++){
     p=(snake*)malloc(sizeof(snake)) ;
    p->x=18+2*i;
    p->y=15;
    p->next=NULL;
    p->next=shead;
    shead=p;
    }
    
    t=shead;
    while(t){
        SetcursorPosition(t->x,t->y);
        printf("■"); 
        t=t->next;
    }
    while(1){
        speed++;
        SetcursorPosition(60,8);
        printf("积分:%d",score);
        SetcursorPosition(60,12);
        printf("游戏规则:不能触碰墙壁和自己的身体");
        SetcursorColor(10);
        SetcursorPosition(60,16);
        printf("tips:贪吃蛇的速度会越来越快");
        SetcursorColor(15);
        if(_kbhit()){
            getch();
            dir=getch();
        }
        newhead=(snake*)malloc(sizeof(snake)) ;
    switch(dir){
        case 72:newhead->x=shead->x;newhead->y=shead->y-1;break;
        case 80:newhead->x=shead->x;newhead->y=shead->y+1;break;
        case 75:newhead->x=shead->x-2;newhead->y=shead->y;break;
        case 77:newhead->x=shead->x+2;newhead->y=shead->y; break;
    }
        newhead->next=shead;
        shead=newhead;
        SetcursorPosition(newhead->x,newhead->y);
        printf("■"); 
        
        t=shead;
        while(t->next->next){
            t=t->next;
        }
         SetcursorPosition(t->next->x,t->next->y);
         printf("  ");
         free(t->next);
         t->next=NULL;
         
         Setcursorhide();
        Sleep(500-2*speed);
        SetcursorPosition(m,n);
        printf("■");
        if((shead->x==m)&&(shead->y)==n){
            score++;
        p=(snake*)malloc(sizeof(snake)) ;
    p->x=shead->x+2;
    p->y=shead->y;
    p->next=NULL;
    p->next=shead;
    shead=p;
        
            SetcursorPosition(m,n);
            printf("■");
          
        srand((unsigned)time(NULL));    
        m=rand()%25+2;
        n=rand()%25+1;
        SetcursorPosition(m,n);
        printf("■");
           }
         
    
        
    }
    
}    

//游戏主体部分
void RunGmae2(){
    printf("asfafsasf");

 

  • 写回答

2条回答 默认 最新

  • cpp_learners 2021-03-28 11:36
    关注

    具体不知道你的是什么问题,拷贝过来编译出现编译问题,

    需使用:

    scanf_s

    fopen_s

    _getch();

     

    还有这个函数还没有实现方法体,也是运行报错的问题之一。

    void RunGame2();

    然后就可以运行了。

     

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多