コード例 #1
0
ファイル: game_map.py プロジェクト: fredrb/roguelike-game
    def make_light_example(self, player, entities):
        player.x = 12
        player.y = 12
        new_room = Rect(10, 10, 10, 10)
        self.create_room(new_room)
        new_room_2 = Rect(25, 5, 10, 20)
        self.create_room(new_room_2)

        self.create_tunnel(20, 25, 15, True)

        self.tiles[27][12].blocked = True
        self.tiles[27][12].block_sight = True

        self.tiles[29][12].blocked = True
        self.tiles[29][12].block_sight = True

        self.tiles[31][12].blocked = True
        self.tiles[31][12].block_sight = True

        self.tiles[33][12].blocked = True
        self.tiles[33][12].block_sight = True

        self.tiles[27][18].blocked = True
        self.tiles[27][18].block_sight = True

        self.tiles[29][18].blocked = True
        self.tiles[29][18].block_sight = True

        self.tiles[31][18].blocked = True
        self.tiles[31][18].block_sight = True

        self.tiles[33][18].blocked = True
        self.tiles[33][18].block_sight = True
コード例 #2
0
ファイル: game_map.py プロジェクト: mgedmin/tcod-tutorial
    def make_map(self, max_rooms: int, room_min_size: int, room_max_size: int,
                 player: Entity, entities: List[Entity]) -> None:
        rooms: List[Rect] = []

        for r in range(max_rooms):
            # random width and height
            w = random.randint(room_min_size, room_max_size)
            h = random.randint(room_min_size, room_max_size)
            # random position without going out of the boundaries of the map
            x = random.randrange(self.width - w)
            y = random.randrange(self.height - h)

            # "Rect" class makes rectangles easier to work with
            new_room = Rect(x, y, w, h)

            # make sure the room doesn't intersect with any of the others
            for other_room in rooms:
                if new_room.intersect(other_room):
                    break
            else:
                # this means there are no intersections, so this room is valid

                # "paint" it to the map's tiles
                self.create_room(new_room)

                # center coordinates of new room, will be useful later
                new_x, new_y = new_room.center()

                if not rooms:
                    # this is the first room, where the player starts at
                    player.x = new_x
                    player.y = new_y
                else:
                    # all rooms after the first:
                    # connect it to the previous room with a tunnel

                    prev_x, prev_y = rooms[-1].center()

                    # flip a coin
                    if random.randrange(2):
                        # first move horizontally, then vertically
                        self.create_h_tunnel(prev_x, new_x, prev_y)
                        self.create_v_tunnel(prev_y, new_y, new_x)
                    else:
                        # first move vertically, then horizontally
                        self.create_v_tunnel(prev_y, new_y, prev_x)
                        self.create_h_tunnel(prev_x, new_x, new_y)

                self.place_entities(new_room, entities)

                # finally, append the new room to the list
                rooms.append(new_room)

        center_of_last_room_x, center_of_last_room_y = rooms[-1].center()
        down_stairs = Entity(center_of_last_room_x, center_of_last_room_y,
                             '>', tcod.white, 'Stairs',
                             render_order=RenderOrder.STAIRS,
                             stairs=Stairs(self.dungeon_level + 1))
        entities.append(down_stairs)
コード例 #3
0
ファイル: map.py プロジェクト: TeaTrey/RoguePy
    def make_map(self, max_rooms, room_min_size, room_max_size, map_width,
                 map_height, player, entities, max_monsters_per_room,
                 max_items_per_room):
        rooms = []
        num_rooms = 0
        print(max_rooms)

        for r in range(max_rooms):
            # random width and height
            w = randint(room_min_size, room_max_size)
            h = randint(room_min_size, room_max_size)
            # random position without going out of the boundaries of the map
            x = randint(0, map_width - w - 1)
            y = randint(0, map_height - h - 1)

            # "Rect" class makes rectangles easier to work with
            new_room = Rect(x, y, w, h)

            # run through the other rooms and see if they intersect with this one
            for other_room in rooms:
                if new_room.intersect(other_room):
                    break
            else:
                # this means there are no intersections, so this room is valid

                # "paint" it to the map's tiles
                self.create_room(new_room)

                # center coordinates of new room, will be useful later
                (new_x, new_y) = new_room.center()

                if num_rooms == 0:
                    # this is the first room, where the player starts at
                    player.x = new_x
                    player.y = new_y
                else:
                    # all rooms after the first:
                    # connect it to the previous room with a tunnel

                    # center coordinates of previous room
                    (prev_x, prev_y) = rooms[num_rooms - 1].center()

                    # flip a coin (random number that is either 0 or 1)
                    if randint(0, 1) == 1:
                        # first move horizontally, then vertically
                        self.create_h_tunnel(prev_x, new_x, prev_y)
                        self.create_v_tunnel(prev_y, new_y, new_x)
                    else:
                        # first move vertically, then horizontally
                        self.create_v_tunnel(prev_y, new_y, prev_x)
                        self.create_h_tunnel(prev_x, new_x, new_y)

                        # finally, append the new room to the list
                        self.place_entities(new_room, entities,
                                            max_monsters_per_room,
                                            max_items_per_room)
                rooms.append(new_room)
                num_rooms += 1
コード例 #4
0
    def generate_room(self, x1=0, y1=0, width=None, height=None):
        if not width:
            width = randint(ROOM_MIN_S_W, ROOM_MAX_S_W)
        if not height:
            height = randint(ROOM_MIN_S_H, ROOM_MAX_S_H)
        x2 = width + x1
        y2 = height + y1
        room = Rect(x1, y1, x2, y2)

        return room
コード例 #5
0
from web_request import get_page, get_page_text
from bs4 import BeautifulSoup as BS
import re
from rectangle import Rect

r = Rect(5, 10)
print(r.sq)

s = "1 2 3 W w \w .w"
print(re.findall("\w", s))

page = get_page("https://yandex.ru")
print(re.findall("[А-Яа-я]", page.text))

soup = BS(page.text, "html.parser")
#print(soup.prettify())
#links = soup.find_all("a")
#for li in links:
#    print(li.get("href", ""))
コード例 #6
0
    def make_map(self, max_rooms, room_min_size, room_max_size, map_width,
                 map_height, player, entities, max_monsters_per_area,
                 max_items_per_area, kolors, current_roster, current_mm):
        rooms = []
        connected_rooms = []
        num_rooms = 0
        tunnel_built = False

        for r in range(max_rooms):
            # "Rect" and "Hex" classes make shapes easier to work with
            if num_rooms > 0:
                prev_room = new_room
            room_roll = randint(0, 99)
            if room_roll < 75:
                # random width and height
                w = randint(room_min_size, room_max_size)
                h = randint(room_min_size, room_max_size)
                # random position without going out of the boundaries of the map
                x = randint(0, map_width - w - 1)
                y = randint(0, map_height - h - 1)
                #Create new rectangular room
                new_room = Rect(x, y, w, h)
            else:
                h = randrange(8, 14, 2)
                w = int(h * 1.3)  #Fat hexagons look better than 1.1547 true
                # random position without going out of the boundaries of the map
                x = randint(0, map_width - w - 1)
                y = randint(0, map_height - h - 1)
                #Create new hexagonal room
                new_room = Hex(x, y, w, h)

            # Go through the room list  and see if they intersect with this one
            for other_room in rooms:
                if new_room.intersect(other_room):
                    break
            else:
                # this means there are no intersections, so this room is valid
                # "paint" it to the map's tiles
                self.create_room(new_room)

                # center coordinates of new room, will be useful later
                (new_x, new_y) = new_room.center()

                if num_rooms == 0:
                    # this is the first room, where the player starts at
                    player.x = new_x
                    player.y = new_y
                else:
                    # all rooms after the first:
                    #connect to the previous room with a tunnel if nearby
                    # center coordinates of previous room
                    (prev_x, prev_y) = rooms[num_rooms - 1].center()
                    #Build a tunnel between rooms
                    dist_threshold = 50
                    tunnel_built = self.build_tunnel(prev_x, prev_y, new_x,
                                                     new_y, dist_threshold)
                    #Keep track of connected rooms
                    if tunnel_built == True:
                        if new_room.center() not in connected_rooms:
                            connected_rooms.append(new_room.center())
                        if prev_room.center() not in connected_rooms:
                            connected_rooms.append(prev_room.center())

                #Add monsters
                self.place_entities(new_room, entities, max_monsters_per_area,
                                    max_items_per_area, kolors, current_roster,
                                    current_mm)
                # finally, append the new room to the list
                rooms.append(new_room)
                num_rooms += 1

        #Add short corridors
        for i in range(0, 30):
            shuffle(rooms)
            first_room = True
            for cur_room in range(0, len(rooms)):
                if first_room == True:
                    first_room = False
                else:
                    (prev_x, prev_y) = rooms[cur_room - 1].center()
                    (cur_x, cur_y) = rooms[cur_room].center()
                    dist_threshold = 25
                    tunnel_built = self.build_tunnel(prev_x, prev_y, cur_x,
                                                     cur_y, dist_threshold)
                    #Keep track of connected rooms
                    if tunnel_built == True:
                        if rooms[cur_room].center() not in connected_rooms:
                            connected_rooms.append(rooms[cur_room].center())
                        if rooms[cur_room - 1].center() not in connected_rooms:
                            connected_rooms.append(rooms[cur_room -
                                                         1].center())

        #Connect orphan rooms
        for cur_room in range(0, len(rooms)):
            tunnel_built = False
            if rooms[cur_room].center() not in connected_rooms:
                for i in range(0, 1000):
                    rand_room = randint(0, len(rooms) - 1)
                    (rand_x, rand_y) = rooms[rand_room - 1].center()
                    (cur_x, cur_y) = rooms[cur_room].center()
                    dist_threshold = 50
                    tunnel_built = self.build_tunnel(rand_x, rand_y, cur_x,
                                                     cur_y, dist_threshold)
                    if tunnel_built == True:
                        break

        #Create doors
        for cur_room in range(0, len(rooms)):
            if rooms[cur_room].room_type == "rectangle":
                edge_tiles = rooms[cur_room].edge()
                for cur_tile in edge_tiles:
                    (x, y) = cur_tile
                    north, south, west, east = True, True, True, True
                    if ((y - 1) >= 0):
                        north = self.tiles[x][y - 1].blocked
                    if ((y + 1) < map_height):
                        south = self.tiles[x][y + 1].blocked
                    if ((x - 1) >= 0):
                        west = self.tiles[x - 1][y].blocked
                    if ((x + 1) < map_width):
                        east = self.tiles[x + 1][y].blocked
                    #If it's a true door then mark it
                    #The ^ syntax is a bitwise xor
                    if (not (north and south)) ^ (not (west and east)):
                        if self.tiles[x][y].blocked == False:
                            self.tiles[x][y].door = True
                            self.tiles[x][y].block_sight = True
コード例 #7
0
ファイル: game_map.py プロジェクト: fredrb/roguelike-game
    def make_map(self, max_rooms, min_size, max_size, player, entities,
                 max_monsters, max_items, components):
        if False:
            return self.make_light_example(player, entities)
        if ((self.dungeon_level % 7) == 0):
            return self.make_boss_map(player, entities)
        rooms = []
        num_rooms = 0
        last_room_x = None
        last_room_y = None
        for r in range(max_rooms):
            w = randint(min_size, max_size)
            h = randint(min_size, max_size)
            x = randint(0, self.width - w - 1)
            y = randint(0, self.height - h - 1)

            new_room = Rect(x, y, w, h)
            for other_room in rooms:
                if new_room.intersect(other_room):
                    break
            else:
                self.create_room(new_room)
                (new_x, new_y) = new_room.center()

                last_room_x = new_x
                last_room_y = new_y
                last_corner_x = x + 1
                last_corner_y = y + 1
                if num_rooms == 0:
                    player.x = new_x
                    player.y = new_y
                else:
                    (prev_x, prev_y) = rooms[num_rooms - 1].center()
                    if randint(0, 1) == 1:
                        self.create_tunnel(prev_x, new_x, prev_y, True)
                        self.create_tunnel(prev_y, new_y, new_x, False)
                    else:
                        self.create_tunnel(prev_y, new_y, prev_x, False)
                        self.create_tunnel(prev_x, new_x, new_y, True)
                self.place_entities(new_room, entities, max_monsters,
                                    max_items, components)
                rooms.append(new_room)
                num_rooms += 1

        stairs_component = Stairs(self.dungeon_level + 1)
        down_stairs = Entity(last_room_x,
                             last_room_y,
                             '>',
                             libtcod.white,
                             'Stairs',
                             render_order=RenderOrder.STAIRS,
                             stairs=stairs_component)
        entities.append(down_stairs)

        shop_component = Shop(self.dungeon_level)
        self.shopkeeper = Entity(down_stairs.x + 1,
                                 down_stairs.y + 1,
                                 '@',
                                 libtcod.light_blue,
                                 'Shopkeeper',
                                 True,
                                 render_order=RenderOrder.ACTOR,
                                 shop=shop_component)
        entities.append(self.shopkeeper)
        for e in entities:
            if e.x == self.shopkeeper.x and e.y == self.shopkeeper.y and e != self.shopkeeper:
                entities.remove(e)
コード例 #8
0
ファイル: game_map.py プロジェクト: fredrb/roguelike-game
    def make_boss_map(self, player, entities):
        new_room = Rect(10, 10, 10, 10)
        self.create_room(new_room)

        player.x = 12
        player.y = 15

        if (self.dungeon_level <= 7):
            dragon = make_monster('dragon', self.dungeon_level + 3, boss=True)
            dragon.x = 18
            dragon.y = 15
            entities.append(dragon)
        elif (self.dungeon_level <= 14):
            dragon = make_monster('dragon', self.dungeon_level + 3, boss=True)
            dragon.x = 18
            dragon.y = 15
            warlock1 = make_monster('warlock', self.dungeon_level + 2)
            warlock1.x = 19
            warlock1.y = 14
            warlock2 = make_monster('warlock', self.dungeon_level + 2)
            warlock2.x = 19
            warlock2.y = 16
            entities.append(dragon)
            entities.append(warlock1)
            entities.append(warlock2)
        elif (self.dungeon_level <= 28):
            dragon = make_monster('red_dragon',
                                  self.dungeon_level + 4,
                                  boss=True)
            dragon.x = 18
            dragon.y = 15
            warlock1 = make_monster('warlock', self.dungeon_level + 2)
            warlock1.x = 19
            warlock1.y = 11
            warlock2 = make_monster('warlock', self.dungeon_level + 2)
            warlock2.x = 19
            warlock2.y = 19
            troll1 = make_monster('troll', self.dungeon_level + 3)
            troll1.x = 14
            troll1.y = 16
            entities.append(dragon)
            entities.append(warlock1)
            entities.append(warlock2)
        else:
            dragon = make_monster('elder_dragon',
                                  self.dungeon_level + 4,
                                  boss=True)
            dragon.x = 18
            dragon.y = 15
            troll1 = make_monster('troll_chief', self.dungeon_level + 3)
            troll1.x = 14
            troll1.y = 16
            warlock1 = make_monster('shaman', self.dungeon_level + 2)
            warlock1.x = 13
            warlock1.y = 11
            warlock2 = make_monster('shaman', self.dungeon_level + 2)
            warlock2.x = 14
            warlock2.y = 19
            entities.append(dragon)
            entities.append(warlock1)
            entities.append(warlock2)