コード例 #1
0
    def __init__(self):
        """
        DungeonGame constructor.
        """
        player_input = query_player_input('Load last game (y/n)? ', ('y', 'n'))

        if player_input == 'y':

            self.game_map = GameMap()
            self.player = Player('')

            try:
                self.on_game_load()
            except FileNotFoundError as error:
                logging.error(error)
                logging.info('Save file not found, new game started.')
            else:
                return

        self.map_size = int(
            query_player_input('Enter map size: ', POSSIBLE_MAP_SIZES))
        self.game_map = GameMap(map_size=self.map_size)

        player_name = input('Enter your name: ')
        self.player = Player(player_name)
        self.player.randomize_position(self.map_size)

        while self.game_map.get_tile_character(
                *self.player.get_position()) != GAME_CHARACTERS['Empty']:
            self.player.randomize_position(self.map_size)
コード例 #2
0
ファイル: procgen.py プロジェクト: seansawyer/petal-gear
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
) -> GameMap:
    """Generate a dungeon by carving floors out of a map full of walls"""
    dungeon = GameMap(map_width, map_height)
    rooms: List[RectangularRoom] = []
    while len(rooms) < max_rooms:
        # size and place the room
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)
        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)
        room = RectangularRoom(x, y, room_width, room_height)
        # avoid creating overlapping rooms
        if any(room.intersects(other_room) for other_room in rooms):
            continue
        # clear out the room's inner area
        dungeon.tiles[room.inner] = tile_types.floor
        # tunnel to the previous room
        if len(rooms) > 0:
            for x, y in tunnel_between(rooms[-1].center, room.center):
                dungeon.tiles[x, y] = tile_types.floor
        rooms.append(room)
    return dungeon
コード例 #3
0
 def __init__(self, map_rows, map_cols, life_init_ratio):
     """将在主程序中初始化实例"""
     self.map_rows = map_rows
     self.map_cols = map_cols
     self.life_init_ratio = life_init_ratio
     self.game_map = GameMap(map_rows, map_rows)
     self.game_map.reset(life_init_ratio)
コード例 #4
0
def init():
    global game_map
    global hero
    global commander
    hero = Hero(10, 11.0, 11.0, math.pi / 2)
    commander = Commander()
    game_map = GameMap(20, 20, [
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
        1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
        0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
        1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1,
        1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
        1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
        0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
        1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
    ], hero, commander, [Unit(10, 10.5, 7.5, 0)])
    game_map.generate_hostiles(5)
    game_map.generate_friendlies(3)
コード例 #5
0
ファイル: map_generator.py プロジェクト: oeN/forest
def generate(width: int, height: int) -> GameMap:
    ROOMS = {'min_size': 7, 'max_size': 10, 'max': 30}

    gm = GameMap(width, height)
    gm.tiles[...] = WALL
    rooms: List[Room] = []

    for _ in range(ROOMS['max']):
        w = randint(ROOMS['min_size'], ROOMS['max_size'])
        h = randint(ROOMS['min_size'], ROOMS['max_size'])
        x = randint(0, width - w - 1)
        y = randint(0, height - h - 1)

        new_room = Room(x, y, w, h)
        if any(new_room.intersects(other) for other in rooms):
            continue

        gm.tiles[new_room.inner] = FLOOR
        if rooms:
            other_room = rooms[-1]
            t_start = new_room.center
            t_end = other_room.center
            t_middle = t_start[0], t_end[1]

            gm.tiles[tcod.line_where(*t_start, *t_middle)] = FLOOR
            gm.tiles[tcod.line_where(*t_middle, *t_end)] = FLOOR
        rooms.append(new_room)

    for room in rooms:
        room.place_entities(gm)

    gm.player = spawn_entity(entities_db.player(), gm[rooms[0].center])
    gm.entities.append(gm.player)
    gm.update_fov()
    return gm
コード例 #6
0
    def __init__(self):
        # Configfile
        try:
            config = configparser.ConfigParser()
            config.read('config.cfg')
            default = config['DEFAULT']
            self.name = default['name']
            self.width = int(default['width'])
            self.height = int(default['height'])
            self.tps = int(default['tps'])
            filenames = config['FILENAMES']
            self.background = pygame.image.load(os.path.join("game_assets", filenames['background']))
        except KeyError:
            create_config()
            Game()

        # Initialization
        pygame.mixer.pre_init(44100, -16, 2, 512)
        pygame.init()
        self.resolution = (self.width, self.height)
        self.screen = pygame.display.set_mode(self.resolution)
        self.tps_clock = pygame.time.Clock()
        self.tps_delta = 0.0
        self.game_map = GameMap(self)
        self.player = Player(self)
        self.magic_ball = MagicBall(self)

        # Sounds
        pygame.mixer.music.load('game_assets/sounds/game_sound.wav')
        pygame.mixer.music.set_volume(0.3)
        pygame.mixer.music.play(-1)

        # Run main loop
        self.run()
コード例 #7
0
def get_game_variables(constants):
    inventory_component = Inventory(26)
    body_component = get_human_body()
    player = Entity(int(constants['screen_width'] / 2),
                    int(constants['screen_height'] / 2),
                    '@',
                    tcod.white,
                    "Player",
                    blocks=True,
                    render_order=RenderOrder.ACTOR,
                    ai=Player,
                    inventory=inventory_component,
                    body=body_component)

    entities = [player]

    animator = Animator([])

    turn_count = 0

    game_map = GameMap(constants['map_width'], constants['map_height'])
    game_map.make_map(player, entities, constants)

    message_log = MessageLog(constants['message_x'],
                             constants['message_width'],
                             constants['message_height'])

    game_state = GameStates.PLAYER_TURN

    return player, entities, animator, turn_count, game_map, message_log, game_state
コード例 #8
0
ファイル: game.py プロジェクト: nobus/rogatut
    def __init__(self):
        # Initialization
        libtcodpy.console_set_custom_font('src/arial10x10.png', libtcodpy.FONT_TYPE_GREYSCALE | libtcodpy.FONT_LAYOUT_TCOD)
        libtcodpy.console_init_root(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT, 'ROGuelike TUTorial', False)
        libtcodpy.sys_set_fps(settings.LIMIT_FPS)
        self.con = libtcodpy.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT)

        self.game_map = GameMap(self.con)
        player_x, player_y = self.game_map.get_staring_position()
        # game objects
        self.player = Player(
            'Player',
            self.con,
            player_x, player_y, '@',
            fighter=Fighter(hp=15, defense=5, power=5, death_function=player_death))

        npc_x, npc_y = self.game_map.get_ending_position()
        self.npc = Npc('Trader', self.con, npc_x, npc_y, '@')
        self.objects = [self.npc, self.player]

        self.npcs = [self.npc]
        for monster in self.game_map.place_monsters():
            self.objects.append(monster)

            if hasattr(monster, 'is_selfmoving') and monster.is_selfmoving:
                self.npcs.append(monster)

        self.game_state = 'playing'
        self.player_action = None
コード例 #9
0
ファイル: main_menu.py プロジェクト: fredrb/roguelike-game
def get_game_variables():
    player = Entity(0, 0,
                    '@',
                    tcod.black,
                    'Player',
                    True, 
                    render_order=RenderOrder.ACTOR, 
                    inventory=component("INVENTORY"),
                    equipment=component("EQUIPMENT"),
                    purse=component("PURSE"),
                    fighter=component("PLAYER"))

    entities = [player]
    game_map = GameMap(CONFIG.get('MAP_WIDTH'), CONFIG.get('MAP_HEIGHT'))
    game_map.make_map(
        CONFIG.get('MAX_ROOMS'), 
        CONFIG.get('ROOM_MIN_SIZE'), 
        CONFIG.get('ROOM_MAX_SIZE'), 
        player, 
        entities, 
        CONFIG.get('MAX_MONSTERS'),
        CONFIG.get('MAX_ITEMS'),
        component)

    message_log = MessageLog(CONFIG.get("MESSAGE_X"),
                             CONFIG.get("MESSAGE_WIDTH"),
                             CONFIG.get("MESSAGE_HEIGHT"))

    game_state = GameStates.INSTRUCTIONS

    return player, entities, game_map, message_log, game_state
コード例 #10
0
def initialize(standard_screen):
    globals.STDSCR = standard_screen
    globals.MAIN = MainMenu()
    globals.INTERFACES.append(globals.MAIN)
    globals.MAP = GameMap()
    globals.INTERFACES.append(globals.MAP)
    globals.INVENTORY = Inventory()
    globals.INTERFACES.append(globals.INVENTORY)
    globals.PAUSE = PauseMenu()
    globals.INTERFACES.append(globals.PAUSE)
    globals.STORY = StoryScreen()
    globals.INTERFACES.append(globals.STORY)
    globals.CONTROLS_MAP = Controls(Controls.Type.game_map)
    globals.INTERFACES.append(globals.CONTROLS_MAP)
    globals.CONTROLS_INVENTORY = Controls(Controls.Type.inventory)
    globals.INTERFACES.append(globals.CONTROLS_INVENTORY)
    globals.CREDITS = Credits()
    globals.INTERFACES.append(globals.CREDITS)
    globals.NEW_GAME = NewGameDialog()
    globals.INTERFACES.append(globals.NEW_GAME)
    globals.QUIT_GAME = EndGameDialog()
    globals.INTERFACES.append(globals.QUIT_GAME)
    globals.SAVE_GAME = SaveGameDialog()
    globals.INTERFACES.append(globals.SAVE_GAME)
    globals.MONSTER = MonsterDialog()
    globals.INTERFACES.append(globals.MONSTER)
    globals.ITEM = ItemDialog()
    globals.INTERFACES.append(globals.ITEM)
    globals.GAME_OVER = GameOverDialog()
    globals.INTERFACES.append(globals.GAME_OVER)
    globals.LADDER = LadderDialog()
    globals.INTERFACES.append(globals.LADDER)
コード例 #11
0
def new_game(logger, renderer):
    # clear console
    renderer.clear_all()
    # Game map
    game_map = GameMap(MAP_WIDTH, MAP_HEIGHT, logger=logger)
    # generate an populate dungeons, create fov map 
    game_map.generate_map()
    player_pos = game_map.player_initial_pos
    
    # instantiate player
    fighter_component = Fighter(hp=30, defense=2, power=2, death_function=player_death)
    player = MainPlayer(
        player_pos[0],
        player_pos[1],
        PLAYER_TILE[USE_TILES].code,
        'player',
        PLAYER_TILE[USE_TILES].color,
        blocks=True,
        fighter=fighter_component,
        logger=logger)
    # initial equipment: a dagger
    equipment_component = Equipment(slot=RIGHT_HAND, power_bonus=2)
    obj = BaseObject(player.get_x_position(), player.get_y_position, DAGGER_TILE[USE_TILES], 'dagger', DAGGER_TILE[USE_TILES].color, logger=logger, equipment=equipment_component)
    player.inventory.append(obj)
    equipment_component.equip(player.inventory)
    obj.always_visible = True
   
    # Greet the player
    logger.log_message(
        'Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.',
        tcod.red
    )
    return game_map, player
コード例 #12
0
def generate_dungeon(max_rooms: int, room_min_size: int, room_max_size: int,
                     map_width: int, map_height: int,
                     max_monsters_per_room: int, player: Entity) -> GameMap:
    dungeon = GameMap(map_width, map_height, entities=[player])

    rooms: List[RectangularRoom] = []

    for r in range(max_rooms):
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)

        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        new_room = RectangularRoom(x, y, room_width, room_height)

        if any(new_room.intersects(other_room) for other_room in rooms):
            continue

        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            player.x, player.y = new_room.center
        else:
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor

        place_entities(new_room, dungeon, max_monsters_per_room)

        rooms.append(new_room)

    return dungeon
コード例 #13
0
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    engine: Engine,
) -> GameMap:
    """Generate a new dungeon map."""
    player = engine.player
    dungeon = GameMap(engine, map_width, map_height, entities=[player])

    #rooms = naiveGenerate(dungeon, max_rooms, room_min_size, room_max_size)
    rooms = bspGenerate(dungeon, player, engine, max_rooms, room_min_size,
                        room_max_size, 1)
    player.place(*rooms[0].center, dungeon)
    print_dungeon(dungeon)

    for room in rooms:
        place_entities(room, dungeon, engine.game_world.current_floor)

    last_room = rooms[len(rooms) - 1]
    dungeon.tiles[last_room.center] = tile_types.down_stairs
    dungeon.downstairs_location = last_room.center
    return dungeon
コード例 #14
0
ファイル: procgen.py プロジェクト: hagukin/Geophyte
def generate_dungeon(
    biome,
    engine,
    depth,
) -> GameMap:
    player = engine.player
    rooms: List[Room] = []

    dungeon = GameMap(depth=depth, engine=engine, biome=biome, entities=[player]) #NOTE: tilemap initialization happens during  gamemap.__init__()
    dungeon.tileset = tile_functions(biome=biome)

    generate_earth(
        dungeon=dungeon,
        map_width=biome.map_width,
        map_height=biome.map_height,
        engine=engine
    )

    generate_rooms(
        dungeon=dungeon,
        rooms=rooms,
        max_rooms=biome.max_rooms,
        engine=engine
    )

    generate_tunnels(
        dungeon=dungeon,
        rooms=rooms,
    )

    adjust_convex(
        dungeon=dungeon,
        rooms=rooms,
        )

    generate_terrain(
        dungeon=dungeon,
        rooms=rooms,
        map_width=biome.map_width,
        map_height=biome.map_height,
    )

    generate_stair(
        dungeon=dungeon,
        rooms=rooms,
        stair_type="pair"
    )

    generate_entities(
        dungeon=dungeon,
        rooms=rooms,
        depth=depth,
        max_monsters_per_room=biome.max_monsters_per_room,
        max_items_per_room=biome.max_items_per_room,
    )

    # debug(dungeon=dungeon)

    return dungeon
コード例 #15
0
ファイル: procgen.py プロジェクト: drewww/sneak
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    max_monsters_per_room: int,
    engine: Engine,
) -> GameMap:
    """Generate a new dungeon map."""
    player = engine.player
    dungeon = GameMap(engine, map_width, map_height, entities=[player])

    rooms: List[RectangularRoom] = []

    dungeon.tiles[:] = tile_types.floor

    #

    for r in range(max_rooms):
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)

        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        # "RectangularRoom" class makes rectangles easier to work with
        new_room = RectangularRoom(x, y, room_width, room_height)

        # Run through the other rooms and see if they intersect with this one.
        if any(new_room.intersects(other_room) for other_room in rooms):
            continue  # This room intersects, so go to the next attempt.
        # If there are no intersections then the room is valid.

        # Dig out this rooms inner area.
        dungeon.tiles[new_room.outer] = tile_types.wall
        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            # The first room, where the player starts.
            player.place(*new_room.center, dungeon)
        else:  # All rooms after the first.
            # Dig out a tunnel between this room and the previous one.
            # in this new generation model this is sort of a hack -- it creates
            # doors but does nothing else.
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor

        place_entities(new_room, dungeon, max_monsters_per_room)

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

    # don't allow more than one enemy for now
    # this is disgusting but seems to work because sets have an implicit order
    # and I can trust it at this point in execution???
    # dungeon.entities = set(list(dungeon.entities)[0:2])

    return dungeon
コード例 #16
0
def generate_dungeon(
        max_rooms: int,
        room_min_size: int,
        room_max_size: int,
        map_width: int,
        map_height: int,
        max_monsters_per_room: int,
        max_items_per_room: int,
        engine: Engine,
) -> GameMap:
    """Genererer et Dungeon Map

     Args:
         max_rooms (int): Maks antal af rum i dungeon
         room_min_size (int): Mindste størrelse af et rum
         room_max_size (int): Største størrelse af et rum
         map_width (int): Hele Dungeons bredde
         map_height (int): Hele Dungeons højde
         player ([type]): Player entity

     Returns:
        GameMap: Området hvor PCen er.
    """
    player = engine.player
    dungeon = GameMap(engine, map_width, map_height, entities=[player, ])

    rooms: List[RectangularRoom] = []
    center_of_last_room = (0, 0)

    for room in range(max_rooms):
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)

        pos_x = random.randint(0, dungeon.width - room_width - 1)
        pos_y = random.randint(0, dungeon.height - room_height - 1)

        new_room = RectangularRoom(pos_x, pos_y, room_width, room_height)

        if any(new_room.intersects(other_room) for other_room in rooms):
            continue

        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            # Første rum, hvor spilleren starter
            player.place(*new_room.center, dungeon)
        else:
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor
            center_of_last_room = new_room.center

        place_entities(new_room, dungeon, max_monsters_per_room, max_items_per_room)

        dungeon.tiles[center_of_last_room] = tile_types.down_stairs
        dungeon.downstairs_location = center_of_last_room

        rooms.append(new_room)

    return dungeon
コード例 #17
0
    def build_map(self, level=1):
        self.game_map = GameMap(self.message_log, level)
        self.entities = Entities(self.game_map)
        self.game_map.make_map(self.player, self.entities)
        self.entities.insert_entity(self.player)

        self.fov_recompute = True
        self.fov_map = initialize_fov(self.game_map)
コード例 #18
0
ファイル: procgen.py プロジェクト: pkshingleton/rogue
def generate_random_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    max_enemies: int,
    engine: Engine,
) -> GameMap:
    ''' 
    Generates a new procedurally-built dungeon map. 
    '''
    # Get the player
    player = engine.player
    # Get the map width/height passed into the function and set a map instance with those dimensions.
    dungeon = GameMap(engine, map_width, map_height, entities=[player])

    # Set a typed List to hold all the generated room instances (reference/key is 'rooms')
    rooms: List[RectangularRoom] = []

    for room in range(max_rooms):
        # Set random room width/height
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)
        # Set random coordinates to place the room
        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        # Create a room (class instance) using the random values
        new_room = RectangularRoom(x, y, room_width, room_height)

        # Iterate through other rooms in the List to determine if it overlaps (True or False)
        if any(new_room.intersects(other_room) for other_room in rooms):
            # If 'True', scrap the room and start the loop again to create a new one
            continue

        # When '.intersects()' does return 'False' (room doesn't overlap), the room is valid and can be tiled
        # (Set tiles to replace the default inner wall tiles initialized by the GameMap class)
        dungeon.tiles[new_room.inner] = tile_types.grass

        # Set player's starting position in the first room (from Tuple returned by room's '.center()' method)
        if len(rooms) == 0:
            player.place(*new_room.center, dungeon)

        else:
            # Connect the centers of the previous room and the current one (tunnel)
            # ('rooms[-1]' goes backward in the rooms array by one item)
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                # Set the tiling for the tunnel
                dungeon.tiles[x, y] = tile_types.dirt

        place_entities(new_room, dungeon, max_enemies)

        # Add the new room to the list of other rooms
        rooms.append(new_room)

    return dungeon
コード例 #19
0
    def __init__(self):

        self.my_game_map = GameMap()
        self.DIRECTION_TO_MOVE = {
            'up': [-1, 0],
            'down': [1, 0],
            'left': [0, -1],
            'right': [0, 1]
        }
コード例 #20
0
ファイル: procgen.py プロジェクト: TavishLaughlin/HullBreaker
def generate_dungeon(map_width, map_height) -> GameMap:
    dungeon = GameMap(map_width, map_height)

    room_1 = RectangularRoom(x=20, y=15, width=10, height=15)
    room_2 = RectangularRoom(x=35, y=15, width=10, height=15)

    dungeon.tiles[room_1.inner] = tile_types.floor
    dungeon.tiles[room_2.inner] = tile_types.floor

    return dungeon
コード例 #21
0
ファイル: main_menu.py プロジェクト: SWE-C3/Adventure-Game
 def handle(self, key: int, previous):
     if key == ord('n'):
         return previous
     elif key == ord('j'):
         globals.STORY.text = globals.STORY.stories['intro']
         globals.MAP = GameMap()
         globals.INVENTORY = Inventory()
         return globals.STORY
     previous.print()
     return self
コード例 #22
0
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    max_monsters_per_room: int,
    max_items_per_room: int,
    engine: Engine,
) -> GameMap:
    """Generate a new dungeon map."""
    player = engine.player
    dungeon = GameMap(engine, map_width, map_height, entities=[player])

    rooms: List[RectangularRoom] = []

    center_of_last_room = (0, 0)

    for r in range(max_rooms):
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)

        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        # "RectangularRoom" class makes rectangles easier to work with
        new_room = RectangularRoom(x, y, room_width, room_height)

        # Run through the other rooms and see if they intersect with this one.
        if any(new_room.intersects(other_room) for other_room in rooms):
            continue  # This room intersects, go to the next attempt.
        # If there are no intersections then the room is valid.

        # Dig out this rooms inner area.
        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            # The first room, where the player starts.
            player.place(*new_room.center, dungeon)
        else:
            # Dig out a tunnel between this room and the previous one.
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor

            center_of_last_room = new_room.center

        place_entities(new_room, dungeon, max_monsters_per_room,
                       max_items_per_room)

        dungeon.tiles[center_of_last_room] = tile_types.down_stairs
        dungeon.downstairs_location = center_of_last_room

        rooms.append(new_room)

    return dungeon
コード例 #23
0
ファイル: procgen.py プロジェクト: SamuelKyle1998/YARG
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    engine: Engine,
) -> GameMap:
    """Generate a new dungeon map"""
    player = engine.player
    dungeon = GameMap(engine, map_width, map_height, entities=[player])
    #keep a running list of all of the rooms
    rooms: List[RectangularRoom] = []

    center_of_last_room = (0, 0)

    for r in range(max_rooms):
        #use given minimum and maximum room sizes to set the room's width and height
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)

        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        #"RectangularRoom" class makes rectangles easier to work with
        new_room = RectangularRoom(x, y, room_width, room_height)

        #Run through the other rooms to see if they intersect with this one
        if any(new_room.intersects(other_room) for other_room in rooms):
            continue  #This room intersects, so go on to next attempt
        #If there are no intersections then the room is valid.

        #dig out this room's inner area.
        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            #The first room, where the player starts
            player.place(*new_room.center, dungeon)
        else:  #All rooms that come after the first
            #Dig out a tunnel between this room and the previous room
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor

            center_of_last_room = new_room.center

        place_entities(new_room, dungeon, engine.game_world.current_floor)

        dungeon.tiles[center_of_last_room] = tile_types.down_stairs
        dungeon.downstairs_location = center_of_last_room

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

    return dungeon
コード例 #24
0
class GameMapTest(unittest.TestCase):
    
    game_map = GameMap()
    game_map.mapsize = 9    
  
    def test_generate_cells(self):
        
        cells = self.game_map.generate_cells(12)   
        respond = self.game_map.mapsize * self.game_map.mapsize // 12
          
        self.assertEqual(respond, len(cells))
コード例 #25
0
 def __init__(self):
     """
     Constructor for GameStep class
     """
     self.my_game_map = GameMap()
     self.DIRECTION_TO_MOVE = {
         'up': [-1, 0],
         'down': [1, 0],
         'left': [0, -1],
         'right': [0, 1]
     }
コード例 #26
0
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    engine: Engine,
) -> GameMap:
    '''Generate a new dungeon map.'''
    player = engine.player
    dungeon = GameMap(engine, map_width, map_height, entities=[player])

    rooms: List[RectangularRoom] = []

    center_of_last_room = (0, 0)

    for r in range(max_rooms):
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)

        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        # RectangularRoom class makes rectangles a bit easier to work w
        new_room = RectangularRoom(x, y, room_width, room_height)

        # spot some intersections
        if any(new_room.intersects(other_room) for other_room in rooms):
            continue  # room intersects, so go to the next one

        # dig out room inner area
        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            # first room, where player starts
            player.place(*new_room.center, dungeon)
        else:
            # dig a tunnel between this and the previous
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor

            center_of_last_room = new_room.center

        place_entities(new_room, dungeon, engine.game_world.current_floor)

        # the very last room added will get the `tile_types.down_stairs` tile
        dungeon.tiles[center_of_last_room] = tile_types.down_stairs
        dungeon.downstairs_location = center_of_last_room

        # append room to list
        rooms.append(new_room)

    return dungeon
コード例 #27
0
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    max_monsters_per_room: int,
    max_items_per_room: int,
    engine: Engine,
) -> GameMap:
    """Generates a new dungeon map."""
    player: Entity = engine.player
    dungeon: GameMap = GameMap(engine,
                               map_width,
                               map_height,
                               entities=[player])

    rooms: List[RectangularRoom] = []

    center_of_last_room: Tuple[int, int] = (0, 0)

    for r in range(max_rooms):
        room_width: int = random.randint(room_min_size, room_max_size)
        room_height: int = random.randint(room_min_size, room_max_size)

        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        new_room: RectangularRoom = RectangularRoom(x, y, room_width,
                                                    room_height)

        if any(new_room.intersects(other_room) for other_room in rooms):
            continue
        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            player.place(*new_room.center, dungeon)
        else:
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor

            center_of_last_room = new_room.center

        place_entities(new_room, dungeon, max_monsters_per_room,
                       max_items_per_room)

        dungeon.tiles[center_of_last_room] = tile_types.down_stairs
        dungeon.downstairs_location = center_of_last_room

        rooms.append(new_room)

    return dungeon
コード例 #28
0
    def __init__(self, master, **kwargs):
        super().__init__(master, **kwargs)
        Oriented.__init__(self, 'north')
        Rectangular.__init__(self, (self.winfo_reqwidth(), self.winfo_reqheight()))
        Positionable.__init__(self, (0, 0))

        self.images = {}
        self.sprites = {}
        self.key_pressed = False

        self.map = GameMap(GameMapConfig.size, self)
        self.map.place_rectangle(pos=(0, 0), dim=(500, 500), fill='green')
        self.map.draw()
コード例 #29
0
def generate_dungeon(map_width, map_height) -> GameMap:
    dungeon = GameMap(map_width, map_height)

    room_1 = RectangularRoom(x=20, y=15, width=10, height=15)
    room_2 = RectangularRoom(x=35, y=15, width=10, height=15)

    dungeon.tiles[room_1.inner] = tile_types.floor
    dungeon.tiles[room_2.inner] = tile_types.floor

    for x, y in tunnel_between(room_2.center, room_1.center):
        dungeon.tiles[x, y] = tile_types.floor

    return dungeon
コード例 #30
0
def generate_dungeon(
    max_rooms: int,
    room_min_size: int,
    room_max_size: int,
    map_width: int,
    map_height: int,
    max_monsters_per_room: int,
    engine: Engine,
) -> GameMap:
    """Generate a new dungeon map"""

    player = engine.player
    dungeon = GameMap(engine, map_width, map_height, entities=[player])

    rooms: List[RectangularRoom] = []

    for r in range(max_rooms):
        room_width = random.randint(room_min_size, room_max_size)
        room_height = random.randint(room_min_size, room_max_size)

        # coordinates that keep it from going off the map
        x = random.randint(0, dungeon.width - room_width - 1)
        y = random.randint(0, dungeon.height - room_height - 1)

        # "RectangularRoom" class makes rectangles easier to work with
        new_room = RectangularRoom(x, y, room_width, room_height)

        # Run through the other rooms and see if they intersect with this one
        if any(new_room.intersects(other_room) for other_room in rooms):
            continue  # This room intersects, so go to the next attempt

        # If there are no intersections then the room is valid

        # Dig out this rooms inner area
        dungeon.tiles[new_room.inner] = tile_types.floor

        if len(rooms) == 0:
            # The first room, where the player starts
            player.place(*new_room.center, dungeon)
        else:  # All rooms after the first
            # Dig out a tunnel between this room and the previous one
            for x, y in tunnel_between(rooms[-1].center, new_room.center):
                dungeon.tiles[x, y] = tile_types.floor

        # places entities in the rooms
        place_entities(new_room, dungeon, max_monsters_per_room)

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

    return dungeon