贪吃蛇代码以及游戏程序
#include <>
#include <>
#include <>
#include <>
#include <>
#include <>
int snake_len=1;//蛇的长度
int snake_loc[50][2]={31,12};//整条蛇的位置,最长为50
int snake_head[2]={31,12};//蛇头位置,初始值为11,12;
int food[2];//食物位置
char snake_direction='s';
int delay=200; //蛇每delay个时间走一步
int eat_flag=0;//1表示吃了食物,0表示未吃
int liv_stat=0;//1表示死了,游戏该结束了;0表示还活着
void gotoxy(int x, int y)//定位光标,x为行坐标,y为列坐标
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
void hidden()//隐藏光标
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
i;
GetConsoleCursorInfo(hOut,&cci);
=0;//赋1为显示,赋0为隐藏
SetConsoleCursorInfo(hOut,&cci);
}
void init()//初始化
{
int i;
snake_len=1;//蛇的长度
snake_loc[0][0]=31;//整条蛇的位置
snake_loc[0][1]=12;
snake_head[0]=31;//蛇头位置,初始值为11,12;
snake_head[1]=12;
snake_direction='s';
delay=200;
eat_flag=0;
liv_stat=0;
for(i=1;i<50;i++)
{
snake_loc[i][0]=0;//整条蛇的位置
snake_loc[i][1]=0;
}
}
void create_window()//创建窗口
{
gotoxy(0,0);
printf("********************************************************************************");
printf("* * *");
printf("* * *");
printf("* * 分数:1 *");
printf("* * 按键说明: *");
printf("* * 上:w *");
printf("* * 下:s *");
printf("* * 左:a *");
printf("* * 右:d *");
printf("* * 暂停:空格*");
printf
贪吃蛇代码 以及游戏程序 来自淘豆网m.daumloan.com转载请标明出处.