c语言贪吃蛇 百度文库,贪吃蛇游戏代码(C语言编写).doc

#include "graphics.h"

#include "stdio.h"

#define MAX 200

#define MAXX 30

#define MAXY 30

#define UP 18432

#define DOWN 20480

#define LEFT 19200

#define RIGHT 19712

#define ESC 283

#define ENTER 7181

#define PAGEUP 18688

#define PAGEDOWN 20736

#define KEY_U 5749

#define KEY_K 9579

#define CTRL_P 6512

#define TRUE 1

#define FALSE 0

#define GAMEINIT 1

#define GAMESTART 2

#define GAMEHAPPY 3

#define GAMEOVER 4

struct SPlace

{

int x;

int y;

int st;

} place[MAX];

int speed;

int count;

int score;

int control;

int head;

int tear;

int x,y;

int babyx,babyy;

int class;

int eat;

int game;

int gamedelay[]={5000,4000,3000,2000,1000,500,250,100};

int gamedelay2[]={1000,1};

static int hitme=TRUE,hit = TRUE;

void init(void);

void nextstatus(void);

void draw(void);

void init(void)

{

int i;

for(i=0;i

{

place[i].x = 0;

place[i].y = 0;

place[i].st = FALSE;

}

place[0].st = TRUE;

place[1].st = TRUE;

place[1].x = 1;

speed = 9;

count = 0;

score = 0;

control = 4;

head = 1;

tear = 0;

x = 1;

y = 0;

babyx = rand()%MAXX;

babyy = rand()%MAXY;

eat = FALSE;

game = GAMESTART;

}

void nextstatus(void)

{

int i;

int exit;

int xx,yy;

xx = x;

yy = y;

switch(control)

{

case 1: y--; yy = y-1; break;

case 2: y++; yy = y+1; break;

case 3: x--; xx = x-1; break;

case 4: x++; xx = x+1; break;

}

hit = TRUE;

if ( ((control == 1) || (control ==2 )) && ( (y < 1) ||(y >= MAXY-1)) ||

(((control == 3) || (control == 4)) && ((x < 1) ||(x >= MAXX-1) ) ) )

{

hit = FALSE;

}

if ( (y < 0) ||(y >= MAXY) ||

(x < 0) ||(x >= MAXX) )

{

game = GAMEOVER;

control = 0;

return;

}

for (i = 0; i < MAX; i++)

{

if ((place[i].st) &&

(x == place[i].x) &&

(y == place[i].y) )

{

game = GAMEOVER;

control = 0;

return;

}

if ((place[i].st) &&

(xx == place[i].x) &&

(yy == place[i].y) )

{

hit = FALSE;

goto OUT;

}

}

OUT:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值