第一范文网 - 专业文章范例文档资料分享平台

贪吃蛇(C语言知识学习)

来源:用户分享 时间:2025/5/22 5:31:34 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

.

#include #include #include #include #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语言知识学习) 的文档
贪吃蛇(C语言知识学习).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0g8kn5y31m8qp2012imx4yj364q3d4011ki_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top