贪吃蛇游戏c语言编程心得体会,贪吃蛇游戏[C语言编程]第一页

本程序为贪吃蛇游戏,想必大家都玩过这个游戏,程序源代码用TC2.0编译通过,需要图形驱动文件的支持,在TC2.0的集成环境中有.

本程序利用数据结构中的链表,来将蛇身连接,同时当蛇吃到一定数目的东西时会自动升级,及移动速度会加快,程序会时刻将一些信息显示在屏幕上,包括所得分数,要吃多少东西才能升级,并且游戏者可以自己手动选择游戏级别,级别越高,蛇的移动速度越快.

另外,此游戏可能与CPU的速度有关系.

源代码如下:

**********************************************************************************

/*******************************COMMENTS**********************************/

/* snake_game.c

*/

/* it is a game for entermainment.

*/

/* in the begin,there is only a snake head,and it will have to eat

food */

/* to become stronger,and it eat a piece of food each time,it will

*/

/* lengthen it's body,with the number of food the snake eats going

up,it */

/* will become long more and more,and the score will goes up also.

*/

/* there is always useful information during the game process.

*/

/* if the path by which the snake goes to eat food is the

shortest,the */

/* score will add up a double.

*/

/*

*/

/* enjoy yourself,and any problem,contact

*/

/*************************************************************************/

/* all head file that will be used

*/

#include

#include

#include

#include

#include

#include

/* useful MACRO */

#define FOOD_SIZE 8

#define SCALE 8

#define UP_KEY 0x4800

#define DOWN_KEY 0x5000

#define LEFT_KEY 0x4b00

#define RIGHT_KEY 0x4d00

#define MOVE_UP 1

#define MOVE_LEFT 2

#define MOVE_DOWN 3

#define MOVE_RIGHT 4

#define INVALID_DIRECTION 0

#define QU99v_KEYC 0x1051

#define QU99v_KEY 0x1071

#define SELECT_KEYC 0x1f53

#define SELECT_KEY 0x1f73

#define PAUSE_KEYC 0x1950

#define PAUSE_KEY 0x1970

#define DEFAULT_LEVEL 1

#define HELP_COLOR WH99vE

#define WELCOME_COLOR WH99vE

#define DEFAULT_COLOR GREEN

/* define the macro as follows to improve the game in future

*/

#define FOOD_COLOR YELLOW

#define SNAKE_HEAD_COLOR RED

#define DEFAULT_SNAKE_COLOR YELLOW

#define EX99v_COLOR WH99vE

#define SCORE_COLOR YELLOW

/* sturcture for snake body mainly ,and

food also */

typedef struct food_infor *FOOD_INFOR_PTR;

typedef struct food_infor{

int posx; /* position for each piece of snake body */

int posy;

int next_move; /* next move direction */

int pre_move; /* previous move direction,seems unuseful */

int beEaten; /* xidentifier for snake body or food */

FOOD_INFOR_PTR next; /* pointer to next piece of snake body

*/

FOOD_INFOR_PTR pre; /* pointer to previous piece of snake body

*/

}FOOD_INFOR;

/* structure for snake head */

typedef struct _snake_head{

int posx;

int posy;

int next_move;

int pre_move;

int eatenC; /* number of food that have been eaten */

int hop; /* number of steps to eat food */

FOOD_INFOR_PTR next; /* pointer to the first piece of eaten food

*/

}SNAKE_HEAD;

/* the left-up corner and right-down

corner */

typedef struct point{

int x;

int y;

}POINT;

/* standards for game speed

*/

/* before level 5,the time interval is level_b[level - 1] / 10,and

after */

/* level 5,the time interval is 1.00 / level_b[level - 1] */

float level_b[9] =

{10.0,8.0,6.0,3.0,1.0,20.0,40.0,160.0,640.0};

/* available varary */

SNAKE_HEAD snake_head;

FOOD_INFOR *current; /* always point to food */

POINT border_LT,border_RB;

int driver,mode; /* for graphics driver */

int maxx,maxy; /* max length and width of screen,in pixel */

int eaten; /* identifier if the food is eaten */

int score = 0; /* total score */

int level = DEFAULT_LEVEL; /* level or speed */

float interval; /* based on speed */

int snake_color = DEFAULT_SNAKE_COLOR; /* snake body color */

int hopcount = 0; /* the shortest number of steps for snake

*/

/* to eat food

*/ 未完下一页

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C语言实训心得总结.doc C语言实训心得 10903090113 李新程 在初学C语言的一个学期后,我们进行了C语言实训阶段,尝试编写一个比较复杂的程序系统。在为期两周的时间中,我们同组的同学共同的感受是:C语言实训和平时上课所接触的程序是有很大不同的,所经受的考验和克服的困难是平时所无法比拟的。好在同组的搭档们精诚合作,分工明确,有问题共同解决,攻克了C语言实训的复杂程序。在这里,我作为其中的参与者,感触良多。 在这次实训中,我对对C语言有了一个更深的了解认识,也对这个学期学的知识得到巩固,还尝试运行编程,每次运行程序成功,让我对下面的项目就充满信心。通过自己与同学合作编写程序,最终把最初的理论知识转化基本技能。这次的实训,使我对C语言的学习产生浓厚的兴趣。 还是这次实训,最令人激动的就是合作做项目,虽然那只是一个很小很小的项目。每天大家来得很早,大家在一起学习,取长补短,我们很好的在实训中长知识,提高我们的学习热情。实训中深切体会到了老师认真负责的伟大的精神和热情为同学指导的促学方式,虽然对有些时候老师没给我们指出解决问题的方法有些小抱怨,但是到了结束时才知道,这种教学让我们自己学会了自学,学会了去看懂别人的代码。更多是老师给的感动,每天在我们来之前就到了教室,在讲课中海给我们分享他在公司上班的一些心得和体会,还有那些我们应该注意的事项,这些是平时上课时无法学到的,是更深层次的巨大收获
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值