static void _test_point(void) { int x, y; const void *clazz; void *point; const struct _propinfo props[] = { { MUME_TYPE_STRING, "name", _POINT_PROP_NAME, MUME_PROP_READWRITE }, { MUME_TYPE_STRING, "coord", _POINT_PROP_COORD, MUME_PROP_READWRITE }, }; const struct _property props1[] = { { "name", "hello" }, { "coord", "10, 20" }, }; const struct _property props2[] = { { "name", "another name" }, { "coord", "-1050, -1" }, }; _test_properties(point_class(), props, COUNT_OF(props)); test_assert(mume_class_of(mume_object_class()) == mume_meta_class()); test_assert(mume_class_of(mume_meta_class()) == mume_meta_class()); test_assert(mume_super_class(mume_object_class()) == mume_object_class()); test_assert(mume_super_class(mume_meta_class()) == mume_object_class()); point = point_new("hello", 10, 20); test_assert(strcmp(point_get_name(point), "hello") == 0); _test_get_properties(point, props1, COUNT_OF(props1)); point_get_coord(point, &x, &y); test_assert(10 == x && 20 == y); point_move(point, -10, 30); point_get_coord(point, &x, &y); test_assert(-10 == x && 30 == y); _test_set_properties(point, props2, COUNT_OF(props2)); _test_get_properties(point, props2, COUNT_OF(props2)); draw_result = 0; point_draw(point); test_assert(DRAW_POINT == draw_result); clazz = mume_class_of(point); test_assert(point_class() == clazz); test_assert(0 == strcmp(mume_class_name(clazz), "point")); test_assert(mume_object_class() == mume_super_class(clazz)); test_assert(mume_size_of(point) == sizeof(struct _point)); test_assert(mume_size_of(point_class()) == sizeof(struct _point_class)); test_assert(mume_is_a(point, point_class())); test_assert(mume_is_of(point, point_class())); test_assert(!mume_is_a(point, mume_object_class())); test_assert(mume_is_of(point, mume_object_class())); test_assert(mume_is_a(point_class(), point_meta_class())); test_assert(mume_is_of(point_class(), mume_object_class())); test_assert(mume_is_of(point_meta_class(), mume_meta_class())); test_assert(mume_is_of(point_class(), mume_meta_class())); mume_delete(point); }
static void check_wall_for_secret_door(struct generator *generator, struct point point, enum direction direction) { struct tile *inside_tile = generator_tile_at(generator, point); struct tile *outside_tile = generator_tile_at(generator, point_move(point, 1, direction)); switch (direction) { case direction_north: if (wall_type_solid != outside_tile->walls.south) return; break; case direction_south: if (wall_type_solid != inside_tile->walls.south) return; break; case direction_east: if (wall_type_solid != outside_tile->walls.west) return; break; case direction_west: if (wall_type_solid != inside_tile->walls.west) return; break; default: fail("Unrecognized direction %i", direction); break; } int score = roll("1d4", generator->rnd); if (score == 1) { if (tile_type_empty == outside_tile->type) { generator_set_wall(generator, inside_tile->point, direction, wall_type_secret_door); } else { struct digger *door_digger = generator_add_digger(generator, point_move(point, 1, direction), direction); if (!space_beyond_door(door_digger, wall_type_secret_door, false)) { generator_delete_digger(generator, door_digger); } } } }
static void _test_circle(void) { int x, y; double rad; const void *clazz; void *circle; const struct _propinfo props[] = { { MUME_TYPE_DOUBLE, "radian", _CIRCLE_PROP_RADIAN, MUME_PROP_READWRITE } }; const struct _property props1[] = { { "name", "world" }, { "coord", "40, 30" }, { "radian", "3.140000000000" }, }; const struct _property props2[] = { { "name", "diff world" }, { "coord", "0, -1024" }, { "radian", "-1.110000000000" }, }; _test_properties(circle_class(), props, COUNT_OF(props)); circle = circle_new("world", 40, 30, 3.14); test_assert(strcmp(point_get_name(circle), "world") == 0); _test_get_properties(circle, props1, COUNT_OF(props1)); point_get_coord(circle, &x, &y); test_assert(40 == x && 30 == y); point_move(circle, 50, 60); point_get_coord(circle, &x, &y); test_assert(50 == x && 60 == y); rad = circle_get_radian(circle); test_assert(fabs(rad - 3.14) < 0.001); _test_set_properties(circle, props2, COUNT_OF(props2)); _test_get_properties(circle, props2, COUNT_OF(props2)); draw_result = 0; point_draw(circle); test_assert((DRAW_POINT | DRAW_CIRCLE) == draw_result); clazz = mume_class_of(circle); test_assert(circle_class() == clazz); test_assert(0 == strcmp(mume_class_name(clazz), "circle")); test_assert(mume_super_class(clazz) == point_class()); test_assert(mume_size_of(circle) == sizeof(struct _circle)); test_assert(mume_size_of(circle_class()) == sizeof(struct _circle_class)); test_assert(mume_is_a(circle, circle_class())); test_assert(!mume_is_a(circle, point_class())); test_assert(mume_is_of(circle, point_class())); mume_delete(circle); }
static int _point_set_property( struct _point *self, const void *prop, const void *var) { switch (mume_property_get_id(prop)) { case _POINT_PROP_NAME: point_set_name(self, mume_variant_get_string(var)); return 1; case _POINT_PROP_COORD: { mume_point_t pt; pt = mume_point_from_string( mume_variant_get_string(var)); point_move(self, pt.x, pt.y); } return 1; } return 0; }