link_snake.c

来自「linux下 贪食蛇代码的书写 利用到linux的图形库 时钟中断 等系统调用功」· C语言 代码 · 共 83 行

C
83
字号


#include <stdio.h>
#include <stdlib.h>

#include "link_snake.h"

struct body *creat()
{
	struct body *head,*p1;
	
	p1=(struct body *)malloc(LEN_STR);
	p1->x=12;
	p1->y=12;
	p1->next=NULL;
	head=p1;
}
void insert(struct body *head,int x_value,int y_value)
{
	struct body *p1;
	p1=head;
	while (p1->next!=NULL)
		p1=p1->next;
	
	p1->next=(struct body *)malloc(LEN_STR);
	p1=p1->next;
	p1->x=x_value;
	p1->y=y_value;
	p1->next=NULL;
}

void born_snake(struct body *head)
{
	insert(head,12,13);
	insert(head,12,14);
	insert(head,12,15);
}

/*
In this funcation : do not care last node !!!
*/

int seek_snake(struct body *head,int x_value,int y_value)
{
	struct body *p1=head;

	while(p1->next!=NULL)
	{
		if (p1->x==x_value&&p1->y==y_value) {
			return 1;
		}
		p1=p1->next;
	}
	
	return 0;
}

struct body *last_node(struct body *head)
{	
	struct body *p1=head;

	while(p1->next!=NULL)
		p1=p1->next;

	return p1;
}	


void  increase_snake(struct body *head ,int x_value,int y_value)
{
	struct body *p1=head;
	
	while(p1->next!=NULL)
		p1=p1->next;
	
	p1->next=(struct body *)malloc(LEN_STR);
	p1=p1->next;

	p1->x=x_value;
	p1->y=y_value;
	p1->next=NULL;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?