.
#include
//蛇头移动方向 #define UP 1 #define DOWN 2 #define LEFT 3 #define RIGHT 4
//死亡判定(怼墙或怼自己) #define KISSASS 1 #define KISSWALL 2
//坐标转化
#define POINT(x,y) ((y)*80+(x)+1) //将(x,y)坐标转化为一个int类数值 #define GETX(x) (((x)-1)?)//将int类数值提取出原先的x #define GETY(y) (((y)-1)/80)//同理,提取出y
HANDLE Console;
.
void Position(int x, int y); //移动光标到(x,y) //Windows.h void DrawMap();//画墙
void ShowText(char *text);//根据字符串的长短智能打印出包围字符串的笑脸 void ResetSnake();//初始化贪吃蛇 int RefreshSnake();//更新蛇的移动 void CreatFood();//生成食物 void Draw();//画出蛇身和食物 void RefreshScreen();//屏幕刷新
void GameOver(int Type);//游戏结束条件 int Gaming();//代码跑起来
char play = 0; ////值为1则继续游戏,值为0游戏退出 char pause = 0; //值为1则暂停,值为0游戏继续 char direction; //蛇头方向
int snake[500]; //snake[0]为蛇头 int body; //蛇身体长度
int newbody;//吃完食物新长的蛇身
int addHead,deleteTail;//增加蛇头擦去蛇尾,使贪吃蛇动起来 int food = 0; //食物
.
void main() { }
void Position(int x, int y) //移动光标到(x,y) //Windows.h { }
SetConsoleCursorPosition(Console, coors); COORD coors = { x, y };
CONSOLE_CURSOR_INFO CurrInfo = { sizeof(CONSOLE_CURSOR_INFO), 0 }; Console = GetStdHandle(STD_OUTPUT_HANDLE); DrawMap();
ShowText(\张博元\while(Gaming()) { }; return 0;
if (play)
DrawMap();
.
void DrawMap() //画墙 {
int i;
for (i = 3; i < 70; i = i + 12) { }
for (i = 0; i < 25; i = i + 1) { }
for (i = 3; i < 70; i = i + 12) { }
for (i = 0; i < 25; i = i + 1) {
Position(76, i); printf(\Position(i, 24);
printf(\Position(0, i); printf(\Position(i, 0);
printf(\我是墙===\
.
}
}
void ShowText(char *text) //根据字符串的长短智能打印出包围字符串的笑脸 {
int i;
int strLength = strlen(text); //得到字符串长度 Position(40 - (strLength / 2)-1, 11); printf(\
for (i = 0; i < strLength + 2; i++) { }
printf(\
Position(40 - (strLength / 2)-1, 12); printf(\printf(text); printf(\
Position(40 - (strLength / 2)-1, 13); printf(\
for (i = 0; i < strLength + 2; i++) {
printf(\
贪吃蛇(C语言知识学习)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)