假如在vc或者bc中运行,可以把这个bool类型注释掉.
贪吃蛇的核心算法时如何实现移动和吃掉食物.
没有碰到食物的时候,把当前运动方向上的下个节点入队,并以蛇节点的颜色重绘这个节点.
然后把头指针所指的节点出队,并以游戏框架内部背景色重绘出队的节点,这样就可以达到移动的效果.
而在吃到食物的时候,则只需把食物入队即可.
// greedsnake.cpp
#include <bios.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#include "conf.h" typedef strUCt node
{
int x,y;
struct node *next;
}Node; typedef struct
{
Node *head,*tail;
int length;
}Snake;
typedef struct
{
int left,top,right,bottom;
}Frame; typedef enum //四个方向
{
up,down,left,right
}Direction;
typedef enum
{
false,true
}bool; void InitGraphMode(); //初始化图形驱动
void CloseGraphMode();
void Foot(int,int);
void Head(int,int);
void CreateFrame(); //完成整个游戏框架的绘制
void CreateSnake(); //创建一条两个节点的蛇,蛇的每一节是队列中的一个节点
bool PlayGame(); //游戏的主体函数,
int Hit(int,int); //判定是否越界,或者撞到自身,两个参数分别是新的头接点的x,y坐标
bool GameOver(); //绘制游戏结束时弹出的对话框
void Enqueue(Node); //入队函数
Node Dequeue(); &n
