예제 #1
0
파일: snake.c 프로젝트: ga2arch/Snake
static void snake_move()
{
	int i, k, eat = 0;
	snake *temp = NULL;
	for (temp = ps.s; temp; temp = temp->next) {
		ps.grid[temp->x][temp->y] = ' ';
		mvwprintw(ps.field, temp->x + 1, temp->y + 1, "%c", ps.grid[temp->x][temp->y]);
		if ((eat) && (!temp->next)) {
			i = temp->x;
			k = temp->y;
		}
		switch (temp->direction) {
			case RIGHT:
			temp->y++;
			if (temp->y == COLS)
				temp->y = 0;
			break;
			case LEFT:
			temp->y--;
			if (temp->y == -1)
				temp->y = COLS - 1;
			break;
			case UP:
			temp->x--;
			if (temp->x == -1)
				temp->x = ROWS - 1;
			break;
			case DOWN:
			temp->x++;
			if (temp->x == ROWS)
				temp->x = 0;
			break;
		}
		if ((temp == ps.s) && (ps.grid[temp->x][temp->y] == '*'))
			eat = 1;
		if (ps.grid[temp->x][temp->y] == 'O') {
			ps.lose = 1;
			return;
		}
		ps.grid[temp->x][temp->y] = 'O';
		wattron(ps.field, COLOR_PAIR(2));
		mvwprintw(ps.field, temp->x + 1, temp->y + 1, "%c", ps.grid[temp->x][temp->y]);
		wattroff(ps.field, COLOR_PAIR);
	}
	if (eat) {
		eat_fruit(i, k);
		mvwprintw(ps.score, 1, 1, "%d points.", ps.points);
		wrefresh(ps.score);
	}
}
예제 #2
0
int main()
{
    banana_eaten = apple_eaten = false;
    else_count = 0;

    eat_fruit(banana{});
    eat_fruit(apple{});
    eat_fruit(chestnut{});

    TEST_ASSERT_OP(banana_eaten, ==, true);
    TEST_ASSERT_OP(apple_eaten, ==, true);



    banana_eaten = apple_eaten = false;
    else_count = 0;

    eat_fruit2(banana{});
    eat_fruit2(apple{});
    eat_fruit2(chestnut{});

    TEST_ASSERT_OP(banana_eaten, ==, true);
    TEST_ASSERT_OP(apple_eaten, ==, true);



    banana_eaten = apple_eaten = false;
    else_count = 0;

    eat_fruit3(banana{});
    eat_fruit3(apple{});
    eat_fruit3(chestnut{});

    TEST_ASSERT_OP(banana_eaten, ==, true);
    TEST_ASSERT_OP(apple_eaten, ==, true);
    TEST_ASSERT_OP(else_count, ==, 4);



    banana_eaten = apple_eaten = false;
    else_count = 0;

    eat_fruit4(banana{});
    eat_fruit4(apple{});
    eat_fruit4(chestnut{});

    TEST_ASSERT_OP(banana_eaten, ==, true);
    TEST_ASSERT_OP(apple_eaten, ==, true);
    TEST_ASSERT_OP(else_count, ==, 1);



    banana_eaten = apple_eaten = false;
    else_count = 0;

    eat_fruit5(banana{});
    eat_fruit5(apple{});
    eat_fruit5(chestnut{});

    TEST_ASSERT_OP(banana_eaten, ==, true);
    TEST_ASSERT_OP(apple_eaten, ==, true);
    TEST_ASSERT_OP(else_count, ==, 1);

    return 0;
}