编译器用的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");
}