Exemplo n.º 1
0
def load_game():
    global player_obj, current_map

    file = shelve.open("saves/savegame", "r")
    player_obj = file["player_obj"]
    file.close()

    messages.set_player(player_obj)
    current_map = player_obj.map

    raise SetState(playing)
Exemplo n.º 2
0
def new_game():
    global player_obj, current_map  # , level_roster

    # libtcod.console_clear(memory_console)

    libtcod.console_set_background_color(0, libtcod.black)
    libtcod.console_set_foreground_color(0, libtcod.white)

    libtcod.console_clear(0)

    if config.QUICK_START:
        name = "Test Player"

    else:
        name = ""

        while True:
            libtcod.console_clear(0)

            libtcod.console_print_left(
                0, 1, 1, libtcod.BKGND_NONE, "Enter your name (1-{} char):".format(MAX_NAME_LENGTH)
            )

            libtcod.console_print_left(0, 1, 3, libtcod.BKGND_NONE, name)

            if len(name) < MAX_NAME_LENGTH:
                libtcod.console_put_char_ex(0, 1 + len(name), 3, libtcod.CHAR_BLOCK1, libtcod.white, libtcod.black)

            libtcod.console_flush()

            key = libtcod.console_wait_for_keypress(True)

            if key.vk == libtcod.KEY_ESCAPE:
                raise SetState(start_menu())

            elif key.vk in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER] and name:
                break

            elif key.vk == libtcod.KEY_BACKSPACE and name:
                name = name[:-1]

            elif chr(key.c) in VALID_NAME_CHARS and len(name) < MAX_NAME_LENGTH:
                name += chr(key.c)

    player_obj = Player(name)

    if config.DEBUG_ITEMS:
        player_obj.inventory.add(items.PotionDebugHeal())
        player_obj.inventory.add(items.ScrollDebugScrying())
        player_obj.inventory.add(items.ScrollDebugTeleport())

    knife = items.WeaponKnife()
    player_obj.inventory.add(knife)
    player_obj.mainhand = knife

    messages.set_player(player_obj)

    messages.Basic("Behold, <c=libtcod.red>brutality</c>!", symbol1=player_obj)
    messages.Basic("[?] to see controls.", symbol1="?")

    current_map = maps.TestMap()
    current_map.place_actor_random(player_obj)

    player_obj.memory = Memory(player_obj)

    # level_roster = [maps.MazeOfMeat, maps.MeatCaves, maps.Meatnasium] # temporary solution

    raise SetState(playing)