コード例 #1
0
def test_get_distance_between_actors():
    actor0 = Actor(0)
    actor0.location[0] = 0
    actor0.location[1] = 2
    actor1 = Actor(1)
    actor1.location[0] = 10
    actor1.location[1] = 2
    assert actor0.get_distance_from(actor1) == 10
コード例 #2
0
def test_fight():
    actor = Actor(0)
    actor.strength = 25
    enemy = Actor(1)
    enemy.health_points = enemy.unit_max()
    actor.location[0] = 50
    actor.location[1] = 50
    enemy.location[0] = 50
    enemy.location[1] = 50
    assert actor.fight(enemy) == 25
コード例 #3
0
def test_fight_from_distance():
    actor = Actor(0)
    enemy = Actor(1)
    enemy.health_points = enemy.unit_max()
    actor.location[0] = 50
    actor.location[1] = 40
    enemy.location[0] = 50
    enemy.location[1] = 50
    weapon_range = 10
    weapon = 25
    assert actor.fight_from_distance(enemy, weapon_range, weapon) == 25
    weapon_range = 1
    assert actor.fight_from_distance(enemy, weapon_range, weapon) == 0
コード例 #4
0
def test_move_actor():
    actor = Actor(0)
    enemy = Actor(1)
    actor.location[0] = 20
    actor.location[1] = 10
    enemy.location[0] = 10
    enemy.location[1] = 50
    actor.speed = 30
    actor.move_actor(enemy)
    assert actor.location[
        0] == 10  # 20 - 30 = -10 but enemy is at 10 so stop at 10
    assert actor.location[1] == 40  # 10 + 30 = 40
    actor.location[0] = 100
    actor.location[1] = 100
    actor.move_actor(enemy)
    assert actor.location[0] == 70
    assert actor.location[1] == 70
コード例 #5
0
ファイル: Map.py プロジェクト: bearhockey/bobgame_py
    def build_map(self):
        for layer in self.map_data["layers"]:
            if layer["visible"]:
                if layer["type"] == "tilelayer":
                    pos = 0
                    t_width = self.map_data["tilesets"][0]["tilewidth"]
                    t_height = self.map_data["tilesets"][0]["tileheight"]
                    for i in layer["data"]:
                        if i != 0:
                            y_cord = int(pos / layer["width"])
                            x_cord = int(pos % layer["width"])

                            if layer["name"] == "passmap":
                                self.passmap.append(
                                    pygame.Rect(x_cord * t_width,
                                                y_cord * t_height, t_width,
                                                t_height))
                            else:
                                tile_x = (i - 1) % (
                                    self.map_data["tilesets"][0]["imagewidth"]
                                    / t_width)
                                tile_x = tile_x * t_width
                                tile_y = (i - 1) / (
                                    self.map_data["tilesets"][0]["imagewidth"]
                                    / t_height)
                                # need to figure out what the -4 is from
                                tile_y = tile_y * t_height - 4

                                if "properties" in layer \
                                        and "upper" in layer["properties"] \
                                        and layer["properties"]["upper"]:
                                    map_to_draw = self.upper_map
                                else:
                                    map_to_draw = self.lower_map

                                map_to_draw.blit(
                                    self.map_tileset,
                                    (x_cord * t_width, y_cord * t_height),
                                    area=pygame.Rect(
                                        tile_x, tile_y,
                                        self.map_data["tilesets"][0]
                                        ["tilewidth"],
                                        self.map_data["tilesets"][0]
                                        ["tileheight"]))
                        pos += 1
                elif layer["type"] == "objectgroup":
                    for o in layer["objects"]:
                        if "door" in o["properties"]:
                            self.door_list.append(Door(o))
                        elif "start" in o["properties"]:
                            self.starting_location = (o['x'], o['y'])
                        elif "ACTOR" in o["properties"]:
                            self.actor_list.append(Actor(o))
                        else:
                            self.object_list.append(
                                MapObject(o, self.tileset_data))
コード例 #6
0
def test_keep_in():
    actor = Actor(0)
    actor.location[0] = -1
    actor.location[1] = actor.battlefield_max() + 1
    actor.keep_in()
    assert actor.location[0] == 0
    assert actor.location[1] == actor.battlefield_max()
    actor.location[0] = actor.battlefield_max() + 1
    actor.location[1] = -1
    actor.keep_in()
    assert actor.location[0] == actor.battlefield_max()
    assert actor.location[1] == 0
    actor.location[0] = 50
    actor.location[1] = 50
    actor.keep_in()
    assert actor.location[0] == 50
    assert actor.location[1] == 50
コード例 #7
0
def test_actor_health_is_within_50_to_100():
    actor = Actor(0)
    assert 50 <= actor.health_points <= actor.unit_max()
コード例 #8
0
def test_actor_name():
    actor = Actor(5)
    assert actor.name == "Unit_5"
コード例 #9
0
def test_to_string():
    actor = Actor(25)
    assert actor.to_string().__contains__("Name : Unit_25")
コード例 #10
0
def test_actor_location_xy_is_within_0_to_100():
    actor = Actor(0)
    assert 0 <= actor.location[0] <= actor.battlefield_max()
    assert 0 <= actor.location[1] <= actor.battlefield_max()
コード例 #11
0
def test_actor_speed_is_within_1_to_100():
    actor = Actor(0)
    assert 1 <= actor.speed <= actor.unit_max()
コード例 #12
0
def test_actor_strength_is_within_1_to_100():
    actor = Actor(0)
    assert 1 <= actor.strength <= actor.unit_max()
コード例 #13
0
def test_take_damage():
    actor = Actor(0)
    actor.health_points = 50
    actor.take_damage(40)
    assert actor.health_points == 10