Linux环境下的贪吃蛇游戏

#include<curses.h>
#include<stdlib.h>
#include<stdio.h>
void initNcurse()
{
    
    
	initscr();
	keypad(stdscr,1);
}
struct snake
{
    
    
	int hang;
	int lie;
	struct snake *next;
};
struct snake node1={
    
    2,2,NULL};
struct snake node2={
    
    2,3,NULL};
struct snake node3={
    
    2,4,NULL};
int hasNode(int i,int j)
{
    
    
	struct snake* p;
	p=&node1;

	while(p!=NULL)
	{
    
    
		if(p->hang==i && p->lie==j)
		{
    
    
			return 1;
		}
		p=p->next;



	}
	return 0;



}

void gamePic()
{
    
    
	int hang;
	int lie;
	for(hang=0;hang<20;hang++)
	{
    
    
		if(hang==0)
		{
    
    
			for(lie =0;lie<20;lie++)
			{
    
    
				printw("--");
			}
			printw("\n");
		
		}
		if(hang>0 && hang<=19)
		{
    
    
			for(lie=0;lie<=20;lie++)
			{
    
    
				if(lie==0 ||lie==20)
				{
    
    
					printw("|");
				}
				else if(hasNode(hang,lie)==1)
				{
    
    
					printw("[]");
				}
				else
				{
    
    
					printw("  ");
				}
			}
			printw("\n");
			
		}
		if(hang==19)
		{
    
    
			for(lie=0;lie<20;lie++)
			{
    
    
				printw("--");
			}
			printw("\n");
			printw("Designed by QYY\n");
		}
	}
}
int main()
{
    
    
	initNcurse();
	
	node1.next=&node2;
	node2.next=&node3;

	gamePic();
	getch();
	endwin();
	return 0;
}

在这里插入图片描述

这只是刚开始贪吃蛇图形创建模块,功能在后面逐渐实现

猜你喜欢

转载自blog.csdn.net/qq_43482790/article/details/114944203