Qt 编程了个小程序,当程序关闭时,出现The program has unexpectedly finished.。

Qt 编程了个小程序,当程序关闭时,出现The program has unexpectedly finished.。,第1张

1、这样的问题一般都是变量未初始化了、控件未new、已经释放后又访问、索引越界、内存溢出等内存访问违例:

>

下面是你要的截图

貌似你弄错了考研时间啊,今年是12月底,不是1月初

在百度上看到的一个贪吃蛇游戏

includelt;iostreamh;

includelt;windowsh;

includelt;timeh;

includelt;stdlibh;

includelt;conioh;

define N 21

void gotoxy(int x,int y)//位置函数

{

COORD pos;

posX=2x;

posY=y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);

}

void color(int a)//颜色函数

{

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);

}

void init(int apple[2])//初始化函数(初始化围墙、显示信息、苹果)

{

int i,j;//初始化围墙

int wall[N+2][N+2]={{0}};

for(i=1;ilt;=N;i++)

{

for(j=1;jlt;=N;j++)

wall[i][j]=1;

}

color(11);

for(i=0;ilt;N+2;i++)

{

for(j=0;jlt;N+2;j++)

{

if(wall[i][j])

coutlt;lt;;■;;

else coutlt;lt;;□; ;

}

coutlt;lt;endl;

}

gotoxy(N+3,1);//显示信息

color(20);

coutlt;lt;;按 W S A D 移动方向;lt;lt;endl;

gotoxy(N+3,2);

color(20);

coutlt;lt;;按任意键暂停;lt;lt;endl;

gotoxy(N+3,3);

color(20);

coutlt;lt;;得分:;lt;lt;endl;

apple[0]=rand()%N+1;//苹果

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

gotoxy(apple[0],apple[1]);

color(12);

coutlt;lt;;●;lt;lt;endl;

}

int main()

{

int i,j;

int snake=NULL;

int apple[2];

int score=0;

int tail[2];

int len=3;

char ch=;p;;

srand((unsigned)time(NULL));

init(apple);

snake=(int)realloc(snake,sizeof(int)len);

for(i=0;ilt;len;i++)

snake[i]=(int)malloc(sizeof(int)2);

for(i=0;ilt;len;i++)

{

snake[i][0]=N/2;

snake[i][1]=N/2+i;

gotoxy(snake[i][0],snake[i][1]);

color(14);

coutlt;lt;;★;lt;lt;endl;

}

while(1)//进入消息循环

{

tail[0]=snake[len-1][0];

tail[1]=snake[len-1][1];

gotoxy(tail[0],tail[1]);

color(11);

coutlt;lt;;■;lt;lt;endl;

for(i=len-1;i;0;i--)

{

snake[i][0]=snake[i-1][0];

snake[i][1]=snake[i-1][1];

gotoxy(snake[i][0],snake[i][1]);

color(14);

coutlt;lt;;★;lt;lt;endl;

}

if(kbhit())

{

gotoxy(0,N+2);

ch=getche();

}

switch(ch)

{

case ;w;:snake[0][1]--;break;

case ;s;:snake[0][1]++;break;

case ;a;:snake[0][0]--;break;

case ;d;:snake[0][0]++;break;

default: break;

}

gotoxy(snake[0][0],snake[0][1]);

color(14);

coutlt;lt;;★;lt;lt;endl;

Sleep(abs(200-05score));

if(snake[0][0]==apple[0]snake[0][1]==apple[1])//吃掉苹果后蛇分数加1,蛇长加1

{

score++;

len++;

snake=(int)realloc(snake,sizeof(int)len);

snake[len-1]=(int)malloc(sizeof(int)2);

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

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

gotoxy(apple[0],apple[1]);

color(12);

coutlt;lt;;●;lt;lt;endl;

gotoxy(N+5,3);

color(20);

coutlt;lt;scorelt;lt;endl;

}

if(snake[0][1]==0snake[0][1]==Nsnake[0][0]==0snake[0][0]==N)//撞到围墙后失败

{

gotoxy(N/2,N/2);

color(30);

coutlt;lt;;Game over;lt;lt;endl;

for(i=0;ilt;len;i++)

free(snake[i]);

Sleep(INFINITE);

exit(0);

}

}

return 0;

}

以上就是关于Qt 编程了个小程序,当程序关闭时,出现The program has unexpectedly finished.。全部的内容,包括:Qt 编程了个小程序,当程序关闭时,出现The program has unexpectedly finished.。、一段QT小程序,我需要其在LINUX下的运行结截图、qt编程可以做什么小游戏等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9431836.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存