c语言开发dos版贪吃蛇,DOS简易版C语言贪吃蛇.pdf

DOS简简易易版版C语语言言贪贪吃吃蛇蛇

本文实例为大家分享了C语言实现贪吃蛇的具体代码,供大家参考,具体内容如

#include

#include

#include

#include

#include

#define WALL_LENGTH 22

#define LEFT x4b

#define RIGHT x4d

#define DOWN x5

#define UP x48

struct Snakes{

int x;

int y;

struct Snakes *prev;

struct Snakes *next;

};

struct Food{

int x;

int y;

};

struct Snakes *header;

struct Snakes *tailer;

struct Food *food;

int wall[WALL_LENGTH][WALL_LENGTH];

int direction = RIGHT;

/**/

void init();

void draw();

void move();

void doMove(int x1, int y1);

void eat();

void keydown();

void foods();

int isOver();

int isDrawSnake(int x, int y);

int isDrawFood(int x, int y);

int main(){

init();

while(1){

if(isOver()){

break;

}

move();

eat();

draw();

_sleep( 1 );

keydown();

}

printf("GAME OVER!");

system("pause");

}

void init(){

int y, x;

for(y= ; y < WALL_LENGTH; y++){

for(x= ; x < WALL_LENGTH; x++){

if(y == || y == WALL_LENGTH - 1 || x == || x == WALL_LENGTH - 1){

wall[y][x] = 1;

}

}

}

header=(struct Snakes *)malloc(sizeof(struct Snakes));

header->x=1 ;

header->y=1 ;

header->prev=NULL;

tailer=(struct Snakes *)malloc(sizeof(struct Snakes));

tailer->x=9;

tailer->y=1 ;

tailer->next=NULL;

tailer->prev=header;

header->next=tailer;

foods();

}

void draw(){

int y, x;

system("cls");

for(y= ; y < WALL_LENGTH; y++){

for(x= ; x < WALL_LENGTH; x++){

if(wall[y][x] == 1){

printf("[]");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值