Beispiel #1
0
def found_treasure(game):
    our_hero = game.character

    if not game.dungeon.is_challenge_completed(our_hero.view.current_x,
                                               our_hero.view.current_y):
        game.dungeon.complete_challenge(our_hero.view.current_x,
                                        our_hero.view.current_y, 'treasure')
        # Save picked_up_treasure to a pkl file so doesn't reset after a restart.
        level_adjustment = our_hero.view.current_level_id
        if level_adjustment > 5:
            level_adjustment = 5
        max_gold = (level_adjustment + 1) * 10
        min_gold = (level_adjustment + 1) * 1
        treasure = random.randint(min_gold, max_gold)
        our_hero.gold += treasure
        game.increment_treasure_score()
        msg: str = ' You found a treasure chest with %d gold in it!' % treasure

        # Check to see if the chest contains a map.
        drop_map = random.randint(0, 3)  # 25%
        if drop_map == 0:
            #  Drop the current dungeon level map.  If they have it, don't drop.
            if items.dungeon_map not in our_hero.inventory:
                our_hero.inventory.append(items.dungeon_map)
                msg += ' You find a map in the chest!'
        # Check to see if we have completed all the challenges.  If so, drop a skeleton key.
        if our_hero.view.dungeon.are_all_treasures_collected():
            our_hero.inventory.append(items.skeleton_key)
            msg += ' You find a %s!' % items.skeleton_key["name"]

        cmd = "Press any key to continue..."
        return screen.paint_two_panes(
            game=game,
            commands=cmd,
            messages=msg,
            left_pane_content=our_hero.view.generate_perspective(),
            right_pane_content=images.treasure_chest,
            sound='challenge-complete',
            delay=500,
            interaction_type='key_press')
    # else you have already picked up this chest
    return screen.paint_two_panes(
        game=game,
        commands=commands,
        messages="You see an empty treasure chest...",
        left_pane_content=our_hero.view.generate_perspective(),
        right_pane_content=images.empty_treasure_chest,
        sound=None,
        delay=0,
        interaction_type='key_press')
Beispiel #2
0
def paint(game):
    return screen.paint_two_panes(game=game,
                                  commands=commands,
                                  messages=message,
                                  left_pane_content=image,
                                  right_pane_content=draw_map_list(game),
                                  sound=None,
                                  delay=0,
                                  interaction_type='key_press')
Beispiel #3
0
def stepped_on_trap(game):
    our_hero = game.character
    if not our_hero.view.dungeon.is_challenge_completed(
            our_hero.view.current_x, our_hero.view.current_y):
        our_hero.view.dungeon.complete_challenge(our_hero.view.current_x,
                                                 our_hero.view.current_y,
                                                 'trap')
        trap = traps.Trap(traps.mace_trap)
        msg = trap.triggered(our_hero)

        if not our_hero.is_alive():
            # Hero has been killed
            game.game_over = True
            game.status = 'KIA: Trap, L' + str(our_hero.view.current_level_id)
            return screen.paint_two_panes(
                game=game,
                commands='Press the Enter key to continue...',
                messages=msg + " You have been killed!",
                left_pane_content=images.tombstone,
                right_pane_content=trap.image,
                sound='death-dirge',
                delay=1000,
                interaction_type='key_press')

        # return the damage summary you took from the trap
        return screen.paint_two_panes(
            game=game,
            commands=commands,
            messages=msg,
            left_pane_content=our_hero.view.generate_perspective(),
            right_pane_content=trap.image,
            sound='morning-star-trap',
            delay=500,
            interaction_type='key_press')
    else:
        return screen.paint_two_panes(
            game=game,
            commands=commands,
            messages="A morning star lays in the corner of the room...",
            left_pane_content=our_hero.view.generate_perspective(),
            right_pane_content=images.sprung_trap,
            sound=None,
            delay=None,
            interaction_type='key_press')
Beispiel #4
0
def paint(game, msg, sound):
    return screen.paint_two_panes(
        game=game,
        commands=commands,
        messages=msg,
        left_pane_content=game.character.view.generate_perspective(),
        right_pane_content=show_map(game.character),
        sound=sound,
        delay=0,
        interaction_type='key_press')
Beispiel #5
0
def hero_is_slain(game, message):
    monster = game.dungeon.current_monster
    hero = game.character
    if items.lucky_rock in hero.inventory:
        # The lucky rock saves the character from dying!
        msg = "   You are struck down by the " + monster.name + "!" \
              "\nAs you lay dying, " \
              "\nyour L U C K Y  R O C K begins to glow...\n" \
              "your strength returns and\n" \
              "you scramble away from the monster.\n" \
              "The rock crumbles into dust!"
        game.dungeon.current_monster = None
        hero.hit_points = hero.max_hit_points / 2
        hero.inventory.remove(items.lucky_rock)
        #  Turn around and crawl one step back.
        hero.view.turn_right()
        hero.view.turn_right()
        hero.view.step_forward()
        game.current_controller = 'dungeon'

        return screen.paint_two_panes(game=game,
                                      commands='Press any key to continue...',
                                      messages='Your still Alive!',
                                      left_pane_content=images.lucky_rock_glow,
                                      right_pane_content=msg,
                                      sound='magic',
                                      delay=2000,
                                      interaction_type='key_press')
    else:
        game.game_over = True
        game.status = 'KIA: ' + game.dungeon.current_monster.name + ', L' + str(
            game.dungeon.current_level_id)

        return screen.paint_two_panes(
            game=game,
            commands='Press the Enter key to continue...',
            messages=message + " You have been slain! Your game score is " +
            str(game.score) + ". Better luck next time...",
            left_pane_content=images.tombstone,
            right_pane_content=game.dungeon.current_monster.image,
            sound='death-dirge',
            delay=2000,
            interaction_type='key-press')
Beispiel #6
0
def paint(game, msg, sound):
    return screen.paint_two_panes(
        game=game,
        commands=commands,
        messages=msg,
        left_pane_content=image,
        right_pane_content=game_play.screen.list_inventory(game.character),
        sound=sound,
        delay=0,
        interaction_type='key_press')
Beispiel #7
0
def paint(game):
    # Print the Town Page if we don't know what the action is.
    return screen.paint_two_panes(
        game=game,
        commands=commands,
        messages=msg,
        left_pane_content=image,
        right_pane_content=game_play.screen.list_inventory(game.character),
        sound=None,
        delay=0,
        interaction_type='key_press')
Beispiel #8
0
def paint(game, msg):

    return screen.paint_two_panes(
        game=game,
        commands=commands,
        messages=msg,
        left_pane_content=image,
        right_pane_content=draw_healing_list(game.character),
        sound=None,
        delay=0,
        interaction_type='key_press'
    )
Beispiel #9
0
def paint(game, monster, msg):
    commands = "(F)ight, (T)ame, (R)un away!"
    if monster is None:
        image = msg
    else:
        image = monster.image

    return screen.paint_two_panes(
        game=game,
        commands=commands,
        messages=msg,
        left_pane_content=game.character.view.generate_perspective(),
        right_pane_content=image,
        sound=None,
        delay=0,
        interaction_type='key_press')
Beispiel #10
0
def purchase_a_map(game, action):
    if game.character.gold < map_cost(game)[0]:
        msg = "You don't have enough money for that!"
    elif items.dungeon_map in game.character.inventory:
        msg = "You already have a map of the dungeon!"
    else:
        game.character.gold -= map_cost(game)[0]
        game.character.inventory.append(items.dungeon_map)
        msg = "You have boughten the " + items.dungeon_map["name"] + "!"

    return screen.paint_two_panes(game=game,
                                  commands=commands,
                                  messages=msg,
                                  left_pane_content=image,
                                  right_pane_content=draw_map_list(game),
                                  sound=None,
                                  delay=0,
                                  interaction_type='key_press')
Beispiel #11
0
def paint(game):
    # Print the Town Page if we don't know what the action is.
    # Wrap long of narratives
    wrapper = textwrap.TextWrapper(width=46)
    word_list = wrapper.wrap(text=help_content)
    # Print each line
    formatted_content = ""
    for line in word_list:
        formatted_content += line + '\n'

    return screen.paint_two_panes(game=game,
                                  commands=commands,
                                  messages=None,
                                  left_pane_content=image,
                                  right_pane_content=formatted_content,
                                  sound=None,
                                  delay=0,
                                  interaction_type='key_press')
Beispiel #12
0
def paint(game):

    db.init_db()
    lb = db.load_leaderboard()
    content = "  H e r o ' s   o f   T h o r d o n\n\n\n"
    content += '  Rank | Character       | Score\n'
    content += '<------o-----------------o--------> \n'
    # getting length of list
    for i in range(len(lb.leaders)):
        content += "   " + \
                   screen.back_padding(str(i + 1), 3) + " | " + \
                   screen.back_padding(lb.leaders[i].gamer_tag, 15) + " | " + \
                   str(lb.leaders[i].score) + '\n'

    return screen.paint_two_panes(game=game,
                                  commands="E(x)it",
                                  messages=None,
                                  left_pane_content=images.shield,
                                  right_pane_content=content,
                                  sound=None,
                                  delay=0,
                                  interaction_type='key_press')
    return monster_count


def is_wall(position):
    if position == '-' or \
            position == '|' or \
            position == '+':
        return True
    return False


def is_opening(floor_space):
    return floor_space == ' '


if __name__ == "__main__":
    # Testing
    for i in range(16):
        m = generate_dungeon_level(i, 'easy')
        view = screen.paint_two_panes(game=None,
                                      commands="Commands Goes Here",
                                      messages="Nothing to see here...",
                                      left_pane_content=images.tombstone,
                                      right_pane_content=m["map"],
                                      sound=None,
                                      delay=None,
                                      interaction_type='key_press')

        for row in view.get("canvas"):
            print(row)
Beispiel #14
0
def process(game, action):
    hero = game.character
    dungeon = game.dungeon
    monster = dungeon.current_monster

    if action is None:
        return paint(
            game, monster,
            "A " + monster.name + " stands before you, blocking your path!")

    if action.lower() == "f":
        message = hero.attack_monster(monster)
        if monster.is_alive():
            message = message + '\n ' + monster.attack(hero)
            if not hero.is_alive():
                return hero_is_slain(game, message)
            return paint(game, monster, message)
        else:
            # Monster has been killed
            dungeon.complete_challenge(hero.view.current_x,
                                       hero.view.current_y, 'monster')
            # Grab Gold
            hero.gold += monster.gold
            game.increment_monster_score()

            # Check to see if the monster drops it's monster parts. If so, put it in the hero's inventory.
            # Have monsters drop less the deeper the hero goes into the dungeon.
            drop_part = random.randint(0, game.dungeon.current_level_id)
            if drop_part == 0:
                hero.monster_parts += 1
                message = message + ' You recover %s from the %s!' % (
                    monster.item_dropped["name"], monster.name)
            message = message + ' Digging through the %s remains you found %d gold!' % (
                monster.name, monster.gold)
            commands = "Press any key to continue..."

            if monster.is_boss:
                dungeon.current_monster = None
                return level_complete.process(game, True, monster)

            game.dungeon.current_monster = None
            game.current_controller = 'dungeon'
            return screen.paint_two_panes(
                game=game,
                commands=commands,
                messages=message,
                left_pane_content=hero.view.generate_perspective(),
                right_pane_content=images.treasure_chest,
                sound='challenge-complete',
                delay=500,
                interaction_type='key_press')

    # Attempt to Tame the wolf
    if action.lower() == "t":
        # If you have monster parts you can feed to the wolf, you have a chance of taming it.
        if hero.monster_parts > 0:
            hero.monster_parts -= 1
            # You have tamed the wolf!
            # hero.inventory.append(monster)
            msg = 'You have Tamed the %s!!!' % monster.name
            dungeon.complete_challenge(hero.view.current_x,
                                       hero.view.current_y, 'monster')
            game.current_controller = 'dungeon'
            return paint(game, None, msg)
        else:
            # The wolf rips the food away from you and bites at you
            message = "You have no food! The monster continues to attack you! "
            message += monster.attack(hero)
            if not hero.is_alive():
                return hero_is_slain(game)
            return paint(game, monster, message)

    # Run Away
    if action.lower() == "r":
        # The monster gets one last parting shot as you flee.
        monster.attack(hero)
        if not hero.is_alive():
            return hero_is_slain(game)

        message = "You get away!!"
        #  Turn around and go one step back.
        hero.view.turn_right()
        hero.view.turn_right()
        hero.view.step_forward()
        game.current_controller = 'dungeon'
        return paint(game, None, message)

    # Default message if they typed jibberish
    return paint(
        game, monster,
        "A " + monster.name + " stands before you, blocking your path!")