| // 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(); //出队函数 void ClearKeyBuf(); //清除键盘缓冲,此函数可以消除不停的按无效键的影响 |