int main()
{
    Post_t post = Post_new(0, 0);
    Post_addWantedCar(post, "007");
    Person_t carOwner = Person_new("Nikita", "Silchenko");
    Car_t car = Car_new("007");
    Car_setOwner(car, carOwner);
    char buff[128];
    Transist_t transist = Transist_new(car, TRANSIST_DEST_TO);
    Post_subscribeWantedCarTransist(post, carOwner, wantedCarPassed_Person, NULL );
    Post_pass(post, transist);
    List_t carsTo = Post_getCars(post, TRANSIST_DEST_TO);
    printf("%d\n", Post_getTransistsNum(post));
    int lSize = List_getSize(carsTo);
    for(int i = 0; i < lSize; i++){
        char buff[128];
        puts(Person_toString(Car_getOwner(List_get(carsTo, i, NULL)), buff));
    }

    Post_delete(post);
    Transist_delete(transist);
    Person_delete(carOwner);
    Car_delete(car);
    return 0;
}
Exemple #2
0
int main()
{
    Fish* fish = Fish_new();    // 创建鱼对象
    Dog* dog = Dog_new();       // 创建狗对象
    Car* car = Car_new();       // 创建车子对象

    Animal* animals[2] = { 0 };     // 初始化动物容器(这里是Animal指针数组)
    IMoveable* moveObjs[3] = { 0 }; // 初始化可移动物体容器(这里是IMoveable指针数组)

    int i = 0;                  // i和j是循环变量
    int j = 0;

    // 初始化鱼对象的昵称为:小鲤鱼,年龄为:1岁
    fish->init(fish, "Small carp", 1);

    // 将fish指针转型为Animal类型指针,并赋值给animals数组的第一个成员
    animals[0] = SUPER_PTR(fish, Animal);

    // 初始化狗对象的昵称为:牧羊犬,年龄为:2岁
    dog->init(dog, "sheepdog", 2);

    // 将dog指针转型为Animal类型指针,并赋值给animals数组的第二个成员
    animals[1] = SUPER_PTR(dog, Animal);

    // 将fish指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第一个成员
    moveObjs[0] = SUPER_PTR(fish, IMoveable);

    // 将dog指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第二个成员
    moveObjs[1] = SUPER_PTR(dog, IMoveable);

    // 将car指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第三个成员
    moveObjs[2] = SUPER_PTR(car, IMoveable);

    // 循环打印动物容器内的动物信息
    for(i=0; i<2; i++)
    {
        Animal* animal = animals[i];
        animal->eat(animal);
        animal->breathe(animal);
        animal->sayHello(animal);
    }

    // 循环打印可移动物体容器内的可移动物体移动方式的信息
    for(j=0; j<3; j++)
    {
        IMoveable* moveObj = moveObjs[j];
        moveObj->move(moveObj);
    }

    lw_oopc_delete(fish);
    lw_oopc_delete(dog);
    lw_oopc_delete(car);

    return 0;
}
Exemple #3
0
int main(int argc, char* argv[])
{
	Map map;
	Car cars[3] = {NULL, NULL, NULL};
	int x, y, i, rounds = 0, needPathfinding = 0, firstLoop = 1;
	List path;
	Position position;
	Vector acc;
	int fuel;

	srand(time(NULL));

	freopen("pshr4log.txt", "w+", stderr);
	// freopen("map.txt", "r", stdin);

	LOGINFO("Starting");

	initGC();

	map = Map_load(stdin);

	LOGINFO("Map loaded");

	while(!feof(stdin))
	{
		LOGINFO1I("===== Round number %d =====", rounds);

		for(i = 0; i < 3; i++)
		{
			fscanf(stdin, "%d %d", &x, &y);

			LOGINFO3I("Car number %i, position : %d %d", i, x, y);

			if(cars[i] == NULL)
				cars[i] = Car_new(x, y);
			else
				Car_updatePosition(cars[i], x, y);

			if(Car_updateArrivedStatus(cars[i], map))
			{
				recomputeDistances(map, cars);
				LOGINFO("I see you've arrived, let me see where I can park now...");
				needPathfinding = 1;
			}
		}

		if(firstLoop)
		{
			firstLoop = 0;
			path = doPathfinding(map, cars);
			List_tail(path);
			List_prev(path);
		}

		position = List_getCurrent(path);

		for(i = 1; i < 3; i++)
		{
			if(Position_equal(position, Car_getPosition(cars[i])))
			{
				needPathfinding = 1;
				LOGINFO("YOU TOOK MY SPOT JERK");
			}
		}

		if(needPathfinding)
		{
			freePath(path);
			path = doPathfinding(map, cars);
			List_tail(path);
			List_prev(path);
			needPathfinding = 0;
			position = List_getCurrent(path);
		}

		if(position == NULL)
		{
			goRandom();
		}
		else
		{
			LOGINFO2I("Going to %d %d", position->x, position->y);
			acc = Car_getAccelerationToReach(cars[0], position);
			go(acc->x, acc->y);

			if(Vector_squaredLength(acc) > 2)
			{
				Car_useBoost(cars[0]);
				LOGINFO("Using a boost");
			}

			Vector_delete(acc);
		}

		List_prev(path);

		rounds++;
	}

	LOGINFO("End");

	freePath(path);

	for(i = 0; i < 3; i++)
	{
		Car_delete(cars[i]);
	}

	Map_delete(map);
	freeGC();

	return 0;
}
Car_t Transist_getCar(Transist_t self){
    Car_t car = Car_new(car->id);
    *car = *self->car;
    return car;
}