コード例 #1
0
ファイル: snake.c プロジェクト: akaehy/Project
int snake_move(void)
{
	int sx[100] = {250, 200, 150, 100, 50};
	int sy[100] = {300, 300, 300, 300, 300};
	int fx = 0;
	int fy = 0;
	int f_count = 100;
	int step = 50;
	int x_offset = step;
	int y_offset = 0;
	int s_len = 5;

	char dict = 'd';
	char new_dict = 0;
	char flag = 0;
	char eat_state = 0;
	barriar();
	system("stty raw -echo");
	while(flag == 0)
	{
		show_food(&fx, &fy, sx, sy, s_len, &f_count);

		if(move_one_step(sx, sy, x_offset,y_offset, s_len, eat_state) == -1)
		{
			restart_game(sx, sy, s_len);
			dict = 'd';
			new_dict = 0;
			x_offset = step;
			y_offset = 0;
			s_len = 5;
		}
		eat_state = eat_food(&fx, &fy, sx, sy, &s_len,&f_count);
		
		new_dict = get_key();
		switch(new_dict)
		{
			case 'a' : if(dict != 'd') dict = new_dict;break;
			case 'd' : if(dict != 'a') dict = new_dict;break;
			case 'w' : if(dict != 's') dict = new_dict;break;
			case 's' : if(dict != 'w') dict = new_dict;break;
			case 'q' : dict = new_dict;						   
			default  :  break;					   
		}

		switch(dict)
		{
			case 'a' : x_offset=-step; y_offset=0;break;
			case 'd' : x_offset=step; y_offset=0;break;
			case 'w' : x_offset=0; y_offset=-step;break;
			case 's' : x_offset=0; y_offset=step;break;
			case 'q' : flag = 1;break;				   
			default : break;				   
		}
		usleep(1000);
	}	
	system("stty cooked echo");

	return 0;
}
コード例 #2
0
ファイル: use-obj.c プロジェクト: BackupTheBerlios/nangband
bool use_object(object_type *o_ptr, bool *ident)
{
	bool used;

	/* Analyze the object */
	switch (o_ptr->tval)
	{
		case TV_FOOD:
		{
			used = eat_food(o_ptr, ident);
			break;
		}

		case TV_POTION:
		{
			used = quaff_potion(o_ptr, ident);
			break;
		}

		case TV_SCROLL:
		{
			used = read_scroll(o_ptr, ident);
			break;
		}

		case TV_STAFF:
		{
			used = use_staff(o_ptr, ident);
			break;
		}

		case TV_WAND:
		{
			used = aim_wand(o_ptr, ident);
			break;
		}

		case TV_ROD:
		{
			used = zap_rod(o_ptr, ident);
			break;
		}

		default:
		{
			used = activate_object(o_ptr, ident);
			break;
		}
	}

	return (used);
}
コード例 #3
0
int main()
{	
	//intalize
		initialize_file_pointers();



		a=time(0);
		initialize_feld(FIELD_S,FIELD_C_S,FIELD_B);

		write_to_file_everything();
		memset(&players[0], 0 ,sizeof(player));
		for (int i = 0; i < num_of_players; ++i)
		{
			initialize_player(&players[i]);
		}
	//intalize

	// main loop
	while(1)
	{
		//for (int i = 0; i < num_of_players; ++i)
		{
			move_player(comand(),&players[0]);
		}
				update();

		DONT_GET_OUT();
		eat_food();
		spawn_food();

		b=time(0);
		printf("%llu\n%lf FPS\n",tiks, (double)tiks/(double)(b-a) );
		tiks++;
		system("sleep 0.010960");

	}

	

	return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: dalhorinek/snakie
int game ( int *c ) {
	char title[100];

	int **body;
	int i = 0;
	int dir = *c;
	int state = 0;

	snakesize = 7;
	food_x = 0;
	food_y = 0;
	points = 0;
	*c = KEY_RIGHT;

	clear();
	body = (int **) malloc(sizeof(int *)*snakesize);
	for ( i = 0; i != snakesize; i++ ) {
		body[i] = (int *) malloc(sizeof(int)*2);
	}

	attron(COLOR_PAIR(PANEL));
	for ( i = 0; i != COLS; i++ ) {
		mvaddch(0, i, ' ');
	}
	sprintf(title," ..:: Snakie v 1.0 ::.. ");
	mvaddstr(0, COLS/2-strlen(title)/2, title);
	attroff(COLOR_PAIR(PANEL));
	refresh();

	for ( i = 0; i!= snakesize; i++ ) {
		body[i][x] = (COLS/2)-i;
		body[i][y] = (LINES/2);
	}

	
	pos_food(body);
	draw_food();
	draw_snake(body);

	while ( 1 ) { 
		clear_snake(body);
		switch(*c) {
			case KEY_UP:
				dir = 'U';
				break;

			case KEY_DOWN:
				dir = 'D';
				break;

			case KEY_RIGHT:
				dir = 'R';
				break;

			case KEY_LEFT:
				dir = 'L';
				break;
		}

		if ( *c == 'q' ) { 
			if ( confirm() == 1 ) {
				state = 0; 
				break; 
			}
		}

		move_snake(dir, &body);
		if ( (state = check_position(body)) != 0 ) {
			dead = 1;
			break;
		}
		eat_food(&body);
		draw_food();
		draw_info();
		draw_snake(body);
		usleep( dir == 'L' || dir == 'R' ? speed*0.75 : speed );
	}
	int ret = quit(&body, state);
	return ret;
}