#include<curses.h> //使用ncurse
#include<stdlib.h>
#include<pthread.h> //使用多线程
#include<stdio.h>
#define UP 1
#define DOWN -1
#define LEFT 2
#define RIGHT -2
struct snake //创建蛇身链表
{
int hang;
int lie;
struct snake *next;
};
struct snake food;
struct snake *head=NULL;
struct snake *tall=NULL;
int dir;
int key;
void initfood() //食物初始化
{
int x=rand()%20;
int y=rand()%21;
struct snake *p=head;
while(p!=NULL){
if(p->hang==x&&p->lie==y){
x=rand()%20;
y=rand()%21;
p=head;
continue;
}
p=p->next;
}
food.hang=x;
while(y==0){
y=rand()%21;
}
food.lie=y;
}
int hassnakenode(int i,int j) //判断地图中该位置是否有蛇身
{
struct snake *p;
p=head
基于ncurse的贪吃蛇游戏
于 2021-01-06 22:00:56 首次发布
本文介绍了如何使用ncurses库逐步开发一个贪吃蛇游戏,包括按键处理、地图绘制、蛇身创建与移动、食物生成及碰撞检测等功能,通过这个项目加深了对链表的运用和程序优化技巧的理解。


7550

被折叠的 条评论
为什么被折叠?



