#include〈iostream〉
#include<windows。h〉
#include<conio。h>
#include〈time。h〉
#include〈stdlib。h〉
using namespace std;
int GameOver=0;
struct Body//蛇身(链表结构)
{
int x,y;//蛇身结点坐标
Body *next;//下一个结点
};
void SetPos(int i,int j)//设定光标位置
{
COORD pos={i—1,j—1};//坐标变量
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);//获取输出句柄
SetConsoleCursorPosition(Out,pos);//设定光标位置
}
class Sneak//贪吃蛇类
{
private:
Body *head;//蛇头指针
int Direction;//移动方向.1,2,3,4 对应上左下右
int Count;//蛇长
int Speed;//速度(等级)
int FoodExist;//食物存在标记
int Food_x;//食物 X 坐标
int Food_y;//食物 Y 坐标
public:
Sneak(int a=3,int b=4,int c=1,int d=0)//构造函数
{
FoodExist=d;//起始不存在食物
Body *temp1,*temp2;
head=new(Body);//申请起始蛇身 3 节
head->x=4;
head—〉y=2;
temp1=new(Body);
temp1—>x=3;
temp1—>y=2;
temp2=new(Body);
temp2-〉x=2;
评论0
最新资源