资源简介
本源代码为基于C语言实现的贪吃蛇,通过链表实现,具有打分、存储分数等功能,可以供新学习的同学进行参考与借鉴
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#define WIDTH 60
#define HEIGHT 20
enum direction
{
LEFTRIGHTUPDOWN
};
struct structFood
{
int x;
int y;
};
struct structNode
{
int x;
int y;
struct structNode *pNext;
};
struct structSnake
{
int length;
enum direction dir;
};
struct structFood *pFood;
struct structSnake *pSnake;
struct structNode *pNode*pTail;
int speech=250;
double score=0;
double lastscore=0;
char level=‘F‘;
double maxeat=0;
int smark=0;
int stop=0;
int counttime=0;
int countfood=0;
time_t startend;
void hideCursor(void);
void gotoXY(int xint y);
void initSnake(void);
void addNode(int xint y);
void initFood(void);
void homePage(void);
void keybordHit(void);
void move(void);
void draw(void);
void eatFood(void);
void addTail(void);
void showresult(void);
void record(void);
void getlastscoreandlevel(void);
int main(void)
{
start =time(NULL);
homePage();
while(stop==0)
{
keybordHit();
move();
draw();
Sleep(speech);
}
return 0;
}
void hideCursor(void)
{
CONSOLE_CURSOR_INFO cursorInfo={10};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE)&cursorInfo);
}
void gotoXY(int xint y)
{
COORD pos;
pos.X=x-1;
pos.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE)pos);
}
void addNode(int xint y)
{
struct structNode *newnode=(struct structNode*)malloc(sizeof(struct structNode));
struct structNode *p=pNode;
newnode->pNext=pNode;
newnode->x=x;
newnode->y=y;
pNode=newnode;
if(x<2||x>=WIDTH||y<2||y>=HEIGHT)
{
stop=1;
gotoXY(2121);
printf(“撞墙游戏结束按任意键退出!“);
getch();
free(pNode);
free(pSnake);
showresult();
exit(0);
}
while(p!=NULL)
{
if(p->pNext!=NULL)
{
if((p->x==x)&&(p->y==y))
{
stop=1;
gotoXY(2121);
printf(“撞到自身游戏结束按任意键退出!“);
getch();
free(pNode);
free(pSnake);
showresult();
exit(0);
}
}
p=p->pNext;
}
}
void initSnake(void)
{
int i;
pSnake=(struct structSnake *)malloc(sizeof(struct structSnake));
pFood=(struct structFood *)malloc(sizeof(struct structFood));
pSnake->length=5;
pSnake->dir=RIGHT;
for(i=2;i<=pSnake->length+2;i++)
addNode(i2);
}
void homePage(void)
{
hideCursor();
printf(“xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t x\n“);
printf(“x\t\t\t\t\t\t\t
- 上一篇:MPEG4视频压缩
- 下一篇:基于C++的简易FTP服务/客户端源码
相关资源
- 猜数字游戏 c语言代码
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- LINUX下命令行界面的C语言细胞游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 用C语言实现的一个打字游戏
- C语言版3D魔方游戏源代码
- 打飞机小游戏57466
- c++ 简易贪吃蛇源码
- 北京化工大学计算方法(C/C++)讲义
- 俄罗斯方块游戏源码(Tetris)
- GBT 28169-2011 嵌入式软件 C语言编码规范
- c++ 猜拳小游戏
- XUnZip Zip解压缩.rar
- Windows_API_函数大全 C/C++
- 扫雷游戏.cpp
- 贪吃蛇大作战(c源码+报告文档)
- 杨中科游戏开发引擎
- 智商超高的中国象棋游戏源码(C++版
- C语言程序设计教材习题参考答案.do
- c++ 扫雷游戏源码(控制台)
- C++跑跑卡丁车
- C++“倒忌时”小游戏
- XX游戏客户端源码
- c++小游戏源码.doc
- 基于ege图形的推箱子游戏
- C语言ege贪吃蛇游戏
- C++小游戏4款(源码)
- 推箱子小游戏源码
- 五子棋游戏源码(控制台)
评论
共有 条评论