一、编译过程
编译时使用终端,gcc 文件名 -lcurses
二、代码
#include<curses.h>
#include<stdlib.h>
#define UP 1
#define DOWN -1
#define LEFT 2
#define RIGHT -2
struct snake
{
int hang;
int lie;
struct snake *next;
};
struct snake *head= NULL;
struct snake *tall= NULL;
int key;
int dir;
struct snake food;
void initfood()
{
int x = rand()%19;
int y = rand()%19;
food.hang = x;
food.lie = y;
}
void initncurse()
{
initscr();
keypad(stdscr,1);
noecho();
}
int hassnakenode(int i,int j)
{
struct snake *p;
p = head;
while(p != NULL){
if(p->hang == i && p ->lie == j){
return 1;
}
p = p->next;
}
return 0;
}
int hasfood(int i,int j)
{
if(food.hang == i && food.lie ==j){
return 1;
}
return 0;
}