1.gotoxyԴ?源码?
2.c++编程小游戏代码
gotoxyԴ??
gotoxy(x,y)是TC的函数,一般编译器没有
void gotoxy(int x,源码锁机源码吾爱破解 int y)
{
COORD pos;
pos.X = x - 1;
pos.Y = y - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
需加头文件
#include <windows.h>
#include <conio.h>
c++编程小游戏代码
以下是贪吃蛇源代码:
#include<iostream.h>
#include<windows.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
#define N
void gotoxy(int x,int y)//位置函数{
COORD pos;
pos.X=2*x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int a)//颜色函数{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void init(int apple[2])//初始化函数(初始化围墙、显示信息、源码python魔塔源码苹果)
{
int i,源码beanvalidation源码分析j;//初始化围墙
int wall[N+2][N+2]={ { 0}};
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
wall[i][j]=1;
}
color();
for(i=0;i<N+2;i++)
{
for(j=0;j<N+2;j++)
{
if(wall[i][j])
cout<<"■";
else cout<<"□" ;
}
cout<<endl;
}
gotoxy(N+3,1);//显示信息
color();
cout<<"按 W S A D 移动方向"<<endl;
gotoxy(N+3,2);
color();
cout<<"按任意键暂停"<<endl;
gotoxy(N+3,3);
color();
cout<<"得分:"<<endl;
apple[0]=rand()%N+1;//苹果
apple[1]=rand()%N+1;
gotoxy(apple[0],apple[1]);
color();
cout<<"●"<<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;i<len;i++)
snake[i]=(int*)malloc(sizeof(int)*2);
for(i=0;i<len;i++)
{
snake[i][0]=N/2;
snake[i][1]=N/2+i;
gotoxy(snake[i][0],snake[i][1]);
color();
cout<<"★"<<endl;
}
while(1)//进入消息循环
{
tail[0]=snake[len-1][0];
tail[1]=snake[len-1][1];
gotoxy(tail[0],tail[1]);
color();
cout<<"■"<<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();
cout<<"★"<<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();
cout<<"★"<<endl;
Sleep(abs(-0.5*score));
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();
cout<<"●"<<endl;
gotoxy(N+5,3);
color();
cout<<score<<endl;
}
if(snake[0][1]==0||snake[0][1]==N||snake[0][0]==0||snake[0][0]==N)//撞到围墙后失败
{
gotoxy(N/2,N/2);
color();
cout<<"失败!!!"<<endl;
for(i=0;i<len;i++)
free(snake[i]);
Sleep(INFINITE);
exit(0);
}
}
return 0;
}
2024-11-28 15:322795人浏览
2024-11-28 15:21505人浏览
2024-11-28 15:201141人浏览
2024-11-28 14:011882人浏览
2024-11-28 14:00771人浏览
2024-11-28 13:001829人浏览
1.Content-Encoding设置为utf-8åapplication/jsonçåºå«2.开源项目轻量元数据管理解决方案——Marquez3.扩展SpringBoot
1.婚庆网站模板设计要注意什么2.求会声会影婚庆相册模板婚庆网站模板设计要注意什么 婚庆行业的发展非常迅速,各种各样的婚庆企业也开始兴起来,与婚庆有关的业务,例如婚车的租赁、酒店婚宴等等都开始被人
1.爆火的云蹦迪直播间如何搭建?云蹦迪还能“蹦”多久?2.minecraft 谁能给我D大直播帖的目录啊 我翻了好久都找不到!!!3.如何获取巴巴托斯内核源代码?爆火的云蹦迪直播间如何搭建?云蹦迪还能