Пример #1
0
def active_context(ctx):
    """Context manager to set the current command context."""
    prev_ctx = adventurelib.current_context
    adventurelib.set_context(ctx)
    try:
        yield
    finally:
        adventurelib.set_context(prev_ctx)
Пример #2
0
    def __set_raw_status(self):
        raw_stati = []
        for ctx in self.ACTIVE:
            raw_stati.append(ctx.status)

        if raw_stati:
            set_context('.'.join(raw_stati))
        else:
            set_context(None)
Пример #3
0
 def on_enter(self):
     super().on_enter()
     if self._event is None:
         self._event = _AltarEvent()
         # TODO: Use add_event here and elsewhere;
         # omit _maybe_append_event from Room.add_event.
         self._event.room = self
         G.add_event(self._event, "post")
     adventurelib.set_context("altar")
Пример #4
0
def go(direction):
    global current_room
    room = current_room.exit(direction)
    if room:
        current_room = room
        a.say('You go %s.' % direction)
        look()
        if room == magic_forest:
            a.set_context('magic_aura')
        else:
            a.set_context('default')
Пример #5
0
    def _restart(unused_actor):
        # Creates the player character and ensures game will restart upon death.
        _G.player = actor.create_actor(
            health=10,
            psyche=10,
            strength=10,
            stamina=10,
            will=10,
            wisdom=10,
            insanity=0,
            name="player",
        )
        _G.player.log_stats = True
        _G.player.upon_death(_restart)

        # Removes all events from global queue.
        _G.clear_queues()

        # Resets just_died flag.
        _G.add_event(_ResetDiedFlag(), "pre")

        # Creates a small dungeon.
        level = floor.Floor.generate("cathedral",
                                     number_rooms=config["num_rooms"])

        # Places a monster in a random room.
        level.random_room().add_character(npcs.fish_man())

        # Places an NPC in a random room.
        level.random_room().add_character(npcs.mad_librarian())

        # Places a cool NPC in a random room.
        level.random_room().add_character(npcs.smokes_man())

        # Places the player.
        level.random_room().add_character(_G.player)

        # Starts it up.
        _get_random_start()
        adventurelib.set_context("start_game")
        adventurelib.set_context(None)
        with _poll_events(poll_before=True, poll_after=True):
            commands.enter_room(_G.player.current_room)
Пример #6
0
def start_battle():
    global battle_over
    battle_over = False
    new_context = 'attacking.' + character_enemy.name
    set_context(new_context)
    if character_enemy.name is cookies_name:
        print_delayed('\n\nFINAL COMBATANT', 3)
        print_delayed(
            'Linda\'s nemesis, the greatest and most terrible foe she will ever face...',
            2)
        print_delayed(
            'More dangerous than all previous combatants put together...', 2)
        print_delayed('The one...', 1)
        print_delayed('The only...', 1)
        print_delayed('STORE-BOUGHT CHOCOLATE CHIP COOKIES!!!!!', 3)
        print_delayed('(ooh, the horror!)', 1)
    else:
        print_delayed('\n\nNext combatant:', 3)
        print_delayed(f'{character_enemy.name}!!!', next_attack_delay)
Пример #7
0
def go(direction):
    global current_room
    room = current_room.exit(direction)
    if room:
        current_room = room
        current_room.visited = 1
        say('You go %s.' % direction)
        look()
        if room == door_room:
            set_context('final_door')
        elif room == shop_room:
            set_context('shop')
        elif room == starting_room:
            set_context('starting_room')
        elif room == grue_room:
            set_context('grue_room')
        else:
            set_context('default')
    else:
        say("You can't currently go %s." % direction)
        look()
Пример #8
0
def end_battle(losing_character):
    '''
    This function is called when a fight ends. It handles the cases where the enemy lost, and where Mom lost
    '''
    global num_turns_in_battle
    global character_enemy
    global current_character_enemy_index
    global battle_over
    if losing_character is character_mom:
        print_delayed(game_over, standard_delay)
        sys.exit()

    # First, print out character defeat info
    if losing_character is dict_enemies[
            tilly_name] and num_turns_in_battle == 10:
        print_delayed(
            'Because Tilly escaped defeat, Linda did not gain any points',
            standard_delay)
    else:
        global score
        score += increment_score(num_turns_in_battle)
        print_delayed(f'Your current score: {score}', standard_delay)

    if character_enemy == dict_enemies[cookies_name]:
        print_end_game_text()
        sys.exit()

    # Set the next enemy Mom will face, and reset her damage boost and active effect. Set context to 'break' to enable
    # break actions
    num_turns_in_battle = 1
    current_character_enemy_index += 1
    character_enemy = dict_enemies[enemy_order[current_character_enemy_index]]
    set_context('break')
    character_mom.damage_boost = 1.0
    character_mom.active_effect = dict_effects[Effects.NONE]
    battle_over = True
    print_delayed('\n\nLinda went to the hooga zone', standard_delay)
Пример #9
0
 def clear(cls):
     cls.ACTIVE = []
     set_context(None)
Пример #10
0
            "INT - Inteligence allows you to craft better items or trick your enemies in combat."
        )
        print(
            "MIND - Each point in Mind increases your total mana by {} and your concentration(chance to succesfully cast a spell) by 1"
            .format(cfg.MP_per_lvl))
        print("FORCE - Makes most of your spells more powerfull.")
        return

    print(
        "Use \"show SOMETHING\" command to learn information about the game elements."
    )
    print("As SOMETHING you can type:")
    print("spells - to get complete information about the spells you control.")
    print("stats - shows your stats and what they mean.")


set_context("combat")


@when('cast SPELL', context="combat")
def casting(spell):
    if spell in player.spells:
        if spell in spells_logic.spells:
            spells_logic.spells[spell].cast_spell(player, player)
    else:
        print("Invalid casting instructions.")


#set_context("combat")
start(help=False)
Пример #11
0
def main():
    set_context('attacking.Greg')
    print_start_of_game_text()
    start()
Пример #12
0
 def on_exit(self):
     super().on_exit()
     adventurelib.set_context(None)
Пример #13
0

# make the notebook to store letters
class Notebook(Item):
    letters_found = Bag()


notebook = Notebook('Notebook', 'book', 'notes')

# initialize the players inventory
inventory = Bag()
inventory.gold = 0
inventory.add(notebook)

#set starting context
set_context('starting_room')

#create master list for testing purposes
master_item_list = Bag({
    wand,
    compass,
    map,
    ball,
    notebook,
})
for letter in letter_bank:
    master_item_list.add(letter)


# action functions
@when('north', direction='north')