运行展示
开始场景
游戏场景
结束场景
下面是源码
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
#define H 15
#define W 15
#define max 30
#define HB 10
#define WB 10
#define HC 15
#define WC 5
struct Choose
{
int x;
int y;
//struct xy coor[max];
int dir;
}choose,chooseend;
int b[HB][WB];
int a[H][W];
int c[HC][WB];
//int eatsuccess=0;
enum
{
up,
down,
left,
right,
};
struct point
{
int x;
int y;
};
//蛇的结构
struct Snake
{
int size;
int dir;
struct point coor[max];
}snake;
struct Food
{
int x;
int y;
int flag;
}food;
void clear()
{
printf("\e[1;1H\e[2J");
}
void initscreen()
{
//初始化位置不合适
/*int i,j;
for(i=0;i<HB;i++)
{
for(j=0;j<WB;j++)
{
if(i==0||i==HB-1||j==0||j==WB-1)
{
b[i][j]=1;
}
else
{
b[i][j]=0;
}
}
}*/
//init key
b[HB/2][WB/4]=2;
b[HB/2][WB/2+WB/4]=2;
//init choose
choose.x=HB/2;
choose.y=WB/2-1;
choose.dir;
b[choose.x][choose.y]=3;
c[HC/2][WC/2]=2;
//c[HC/2][WC/2+WC/4]=2;
//init chooseend
chooseend.x=HC/4;
chooseend.y=WC/4;
chooseend.dir;
c[chooseend.x][chooseend.y]=3;
}
void drawstart()
{
int i,j;
// int i,j;
for(i=0;i<HB;i++)
{
for(j=0;j<WB;j++)
{
if(i==0||i==HB-1||j==0||j==WB-1)
{
b[i][j]=1;
}
else
{
b[i][j]=0;
}
}
}
b[HB/2][WB/4]=2;
b[HB/2][WB/2+WB/4]=4;
b[choose.x][choose.y]=3;