void ioDestroy(void) {
	if (eventThreadID != -1) {
		threadkill(eventThreadID);
	}
	closemouse(mousectl);
	closekeyboard(keyboardctl);
}
示例#2
0
文件: snake.c 项目: shixv/test
int main(void)
{
	int XMax,YMax;
	Getborder(&XMax,&YMax);
	srand((unsigned int)time(0));
	RP r={0,0};
	RP *rp=&r;
	SNode *sp=NULL;
	Initheadtail(&sp);
	Randpoint(rp,sp,XMax,YMax);
	initscr();
	initkeyboard();
	//----------------------
	int ch=0;
	while(ch!='q')
	{
		ch=0;
		if(kbhit())
			ch=readch();
//		printf("%c\n",ch);
//		read(0,&ch,1);
		switch(ch){
			case 'w':
				sp->direction=N;
				break;
			case 's':
				sp->direction=S;
				break;
			case 'a':
				sp->direction=W;
				break;
			case 'd':
				sp->direction=E;
				break;
		}
//		printw("%d\n",sp->direction);
		switch(Checkhead(sp,rp)){
			case -1:
				goto END;
			case 0:
				break;
			case 1:
				Eatpoint(&sp,rp,XMax,YMax);
				break;
		}
		Freshsanke(&sp);
		Convertborder(sp,XMax,YMax);
		Printscr(sp);
		Printpoint(r);
		refresh();
		clear();
		usleep(100000);
	}
	//----------------------
END:closekeyboard();
	endwin();
	Freenode(sp);
	return 0;
}