文档介绍:唐山学院
毕业设计
设计题目:贪吃蛇游戏
信息工程二系
04计算机与信息管理(3)班
系别:____________________________
翟丽丽
班级:____________________________
姜方正
班级:____________________________
指导教师:____________________________
2006年6月9 日
贪吃蛇游戏
摘要
贪吃蛇游戏是一个深受人们喜爱的游戏,它能够让你在忙碌的工作中放松一下自己,游戏贪吃蛇就是在屏幕上画出蛇,同时随机地给出食物。游戏者通过键盘操作控制贪吃蛇的移动,去吃食物,吃到后食物消失,然后再随机给出食物同时蛇的身体增长。撞到墙壁或身体交叉蛇头撞到自己的身体,则游戏结束。
这个程序关键点是表示蛇的图形以及蛇的移动。用一个小矩形块表示蛇的一节身体,身体每长一节,增加一个矩形块,蛇头用两节表示。移动时必须从蛇头开始,所以蛇不能向相反的方向移动,也就是蛇尾不能改作蛇头。如果不按任何键,蛇自行在当前方向上前移,当游戏者按了有效的方向键后,蛇头朝着指定的方向移动,一步移动一节身体,所以当按了有效的方向键后,先确定蛇头的位置,然后蛇身体随着蛇头移动,图形的实现是从蛇头的新位置开始画出蛇,这时,由于没有清屏的原因,原来蛇的位置差一个单位,所以看起来蛇会多一节身体,所以将蛇的最后一节用背景色覆盖。食物的出现和消失也是画矩形块和覆盖矩形块。
本程序实现的主要技巧在二维数组的应用上。编写此游戏掌握了用C语言知识的了解,通过这次毕业设计,提高了我们的编程的水平。
关键词:食物和蛇
Tanchishe game
Abstract
Tanchishe game is a very popular game is that it can allow you to relax at work in a busy themselves in the game Tanchiyi screen is painted snake while random to give food. Tanchiyi operational control of the game through keyboard movement, eat food, after eating food disappeared, and then randomly given food and snake physical growth. Hit the walls or physical cross-snake hit their physical, the game ended.
The key point is that the procedures of the snake and the snake mobile graphics. Using a small rectangle pieces that snake section body, the body of each long section, add a rectangle pieces, with two sections that snakeheads. Movement must start from the snake, the snake can not be contrary to the direction of movement that is capable not for snakeheads. If we do not by any keys, snakes themselves in the current direction of everything, when those games by an effective direction keys, snake head towards the designated direction movements, step movement section of the body, so when the effective direction keys, to identify the snake's position, and then snake body with snakeheads movement graphic realization from the snakeheads new location beginning painted snake, then, In the absence of the Qing Ping reasons, the original location o