예제 #1
0
    def test_stair_linking(self):
        """
        Test that stairs can be linked
        """
        level1 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        level2 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        stairs1 = Portal((None, None), None)

        stairs1.icon = 'stairs'
        add_portal(level1, (10, 10), stairs1)

        stairs2 = Portal((None, None), None)
        add_portal(level2, (5, 5), stairs2, stairs1)

        assert(stairs1.level == level1)
        assert(stairs1.location == (10, 10))
        assert(stairs1.get_other_end() == stairs2)

        assert(stairs2.level == level2)
        assert(stairs2.location == (5, 5))
        assert(stairs2.get_other_end() == stairs1)

        assert get_portal(level1, (10, 10)) == stairs1
        assert get_portal(level2, (5, 5)) == stairs2
예제 #2
0
    def test_stair_linking(self):
        """
        Test that stairs can be linked
        """
        level1 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        level2 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        stairs1 = Portal((None, None), None)

        stairs1.icon = 'stairs'
        add_portal(level1, (10, 10), stairs1)

        stairs2 = Portal((None, None), None)
        add_portal(level2, (5, 5), stairs2, stairs1)

        assert(stairs1.level == level1)
        assert(stairs1.location == (10, 10))
        assert(stairs1.get_other_end() == stairs2)

        assert(stairs2.level == level2)
        assert(stairs2.location == (5, 5))
        assert(stairs2.get_other_end() == stairs1)

        assert get_portal(level1, (10, 10)) == stairs1
        assert get_portal(level2, (5, 5)) == stairs2
예제 #3
0
    def test_portal_has_icons(self):
        """
        Test that portal created by adder has two icons set
        One to display and another to be used by opposite end
        """
        level = (LevelBuilder()
                 .with_size((20, 20))
                 .with_floor_tile(self.floor_rock)
                 .with_wall_tile(self.wall_empty)
                 .build())

        level_generator = mock()

        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                add_location_tag(level, (loc_x, loc_y), 'room')

        portal_adder = PortalAdder((1, 2),
                                   'room',
                                   level_generator,
                                   False,
                                   self.rng)

        portal_adder.add_portal(level)

        portals = []
        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                temp = get_portal(level, (loc_x, loc_y))
                if temp:
                    portals.append(temp)
        portal = portals[0]

        assert_that(portal.icon, is_(equal_to(1)))
        assert_that(portal.other_end_icon, is_(equal_to(2)))
예제 #4
0
    def test_add_stairs_to_room(self):
        """
        Test that stairs can be added to a room
        """
        level = (LevelBuilder()
                 .with_size((20, 20))
                 .with_floor_tile(self.floor_rock)
                 .with_wall_tile(self.wall_empty)
                 .build())

        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                add_location_tag(level, (loc_x, loc_y), 'room')

        portal_adder = PortalAdder((1, 2),
                                   'room',
                                   mock(),
                                   False,
                                   self.rng)

        portal_adder.add_portal(level)

        portals = []
        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                temp = get_portal(level, (loc_x, loc_y))
                if temp:
                    portals.append(temp)

        assert_that(portals, has_length(1))
        portal = portals[0]
        assert_that(located_in_room(portal), is_(True))
예제 #5
0
    def test_portal_has_icons(self):
        """
        Test that portal created by adder has two icons set
        One to display and another to be used by opposite end
        """
        level = (LevelBuilder().with_size((20, 20)).with_floor_tile(
            self.floor_rock).with_wall_tile(self.wall_empty).build())

        level_generator = mock()

        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                add_location_tag(level, (loc_x, loc_y), 'room')

        portal_adder = PortalAdder((1, 2), 'room', level_generator, False,
                                   self.rng)

        portal_adder.add_portal(level)

        portals = []
        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                temp = get_portal(level, (loc_x, loc_y))
                if temp:
                    portals.append(temp)
        portal = portals[0]

        assert_that(portal.icon, is_(equal_to(1)))
        assert_that(portal.other_end_icon, is_(equal_to(2)))
예제 #6
0
    def test_add_stairs_to_room(self):
        """
        Test that stairs can be added to a room
        """
        level = (LevelBuilder().with_size((20, 20)).with_floor_tile(
            self.floor_rock).with_wall_tile(self.wall_empty).build())

        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                add_location_tag(level, (loc_x, loc_y), 'room')

        portal_adder = PortalAdder((1, 2), 'room', mock(), False, self.rng)

        portal_adder.add_portal(level)

        portals = []
        for loc_y in range(8, 12):
            for loc_x in range(8, 12):
                temp = get_portal(level, (loc_x, loc_y))
                if temp:
                    portals.append(temp)

        assert_that(portals, has_length(1))
        portal = portals[0]
        assert_that(located_in_room(portal), is_(True))
예제 #7
0
    def mouseEvent(self, event):
        """
        Handle mouse events
        """
        if self.model.player is None:
            return

        player = self.model.player
        next_creature = self.model.get_next_creature(self.rules_engine)

        if next_creature == player:
            point = self.view.mapToScene(event.pos())
            x = int(point.x() / 32)
            y = int(point.y() / 32)

            player = self.model.player
            level = player.level
            location = player.location

            # if player was clicked, take stairs or open menu
            if (x, y) == location:
                if get_portal(level, location):
                    if pyherc.vtable['\ufdd0:is-move-legal'](player, 9):
                        pyherc.vtable['\ufdd0:move'](player, 9)
                else:
                    self.MenuRequested.emit()

            elif is_move(
                    event, player,
                (x, y)):  # TODO: maybe moving should be possible with mouse?
                move(event, player, (x, y))
            else:
                direction = find_direction(location, (x, y))
                distance = distance_between(location, (x, y))

                if distance == 1:
                    #melee attack?
                    if pyherc.vtable['\ufdd0:is-attack-legal'](player,
                                                               direction):
                        pyherc.vtable['\ufdd0:attack'](player, direction)
                else:
                    if (location[0] == x) or (location[1] == y):
                        if pyherc.vtable['\ufdd0:is-attack-legal'](player,
                                                                   direction):
                            pyherc.vtable['\ufdd0:attack'](player, direction)

        self.process_npc()
예제 #8
0
파일: map.py 프로젝트: tuturto/pyherc
    def mouseEvent(self, event):
        """
        Handle mouse events
        """
        if self.model.player is None:
            return

        player = self.model.player
        next_creature = self.model.get_next_creature(self.rules_engine)

        if next_creature == player:
            point = self.view.mapToScene(event.pos())
            x = int(point.x() / 32)
            y = int(point.y() / 32)

            player = self.model.player
            level = player.level
            location = player.location

            # if player was clicked, take stairs or open menu
            if (x, y) == location:
                if get_portal(level, location):
                    if pyherc.vtable['\ufdd0:is-move-legal'](player, 9):
                        pyherc.vtable['\ufdd0:move'](player, 9)
                else:
                    self.MenuRequested.emit()

            elif is_move(event, player, (x, y)): # TODO: maybe moving should be possible with mouse?
                move(event, player, (x, y))
            else:
                direction = find_direction(location, (x, y))
                distance = distance_between(location, (x, y))

                if distance == 1:
                    #melee attack?
                    if pyherc.vtable['\ufdd0:is-attack-legal'](player, direction):
                        pyherc.vtable['\ufdd0:attack'](player, direction)
                else:
                    if (location[0] == x) or (location[1] == y):
                        if pyherc.vtable['\ufdd0:is-attack-legal'](player, direction):
                            pyherc.vtable['\ufdd0:attack'](player, direction)

        self.process_npc()