赞
踩
满意答案
leemcuypil
推荐于 2019.10.16
采纳率:45% 等级:12
已帮助:4660人
#include
#include
#include
#include
#define U 1
#define D 2
#define L 3
#define R 4 //蛇的状态,U:上 ;D:下;L:左 R:右
typedef struct SNAKE { //蛇身的一个节点
int x;
int y;
struct SNAKE *next;
} snake;
//全局变量//
int score=0,add=10;//总得分与每次吃食物得分。
int status,sleeptime=200;//每次运行的时间间隔
snake *head, *food;//蛇头指针,食物指针
snake *q;//遍历蛇的时候用到的指针
int endgamestatus=0; //游戏结束的情况,1:撞到墙;2:咬到自己;3:主动退出游戏。
//声明全部函数//
void Pos();
void creatMap();
void initsnake();
int biteself();
void createfood();
void cantcrosswall();
void snakemove();
void pause();
void gamecircle();
void welcometogame();
void endgame();
void gamestart();
void Pos(int x,int y)//设置光标位置
{
COORD pos;
HANDLE hOutput;
pos.X=x;
pos.Y=y;
hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOutput,pos);
}
void creatMap()//创建地图
{
int i;
for(i=0; i<58; i+=2) { //打印上下边框
Pos(i,0);
printf("■");
Pos(i,26);
printf("■");
}
for(i=1; i<26; i++) { //打印左右边框
Pos(0,i);
printf("■");
Pos(56,i);
printf("■");
}
}
void initsnake()//初始化蛇身
{
snake *tail;
int i;
tail=(snake*)malloc(sizeof(snake));//从蛇尾开始,头插法ÿ
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。