Example #1
0
def check_room(direction, current_room):
    if current_room.name == 'Snake Den':
        if direction == 'n' or direction == 'e':
            color.prRed("\nA snake has attacked and you died instanstly!")
            color.prGreen("Try again!\n")
            return False
        elif direction == 's' and not has_rope():
            return False
        else:
            return True
    elif current_room.name == 'Grand Overlook':
        if direction == 'n' and not has_rope():
            return False
        else:
            return True
    elif current_room.name == 'Treasure Chamber':
        if direction == 'n':
            text = "You found a weak spot in the northern wall of the " \
                   "Treasure Chamber."
            color.prGreen(f"\n{textwrap.fill(text)}")
            if has_pickaxe():
                room['treasure'].n_to = room['hidden']
                return True
        elif direction == 'w' or direction == 'e':
            color.prYellow(f"\nThere is a sturdy wall to that direction.")
        return True
    else:
        return True
Example #2
0
def has_pickaxe():
    if check_item('pickaxe', player.items):
        color.prGreen("\nYou used your pickaxe to break through the wall!")
        return True
    else:
        color.prYellow("\nThe wall may be weak but you have nothing to break "
                       "through it.")
        return False
Example #3
0
def go_room(new_room):
    player.current_room = new_room
    color.prGreen(f"\n{textwrap.fill(str(player))}")
    if new_room.name == 'Hidden Treasure Chamber':
        color.prGreen(f"\n***You have won!***\n")
        global game
        game = False
    else:
        color.prPurple("\nWhat would you like to do?")
Example #4
0
 def on_take(self, player):
     if self.can_take:
         player.add_item(self)
         player.current_room.remove_item(self)
         color.prGreen(f'\nYou have picked up the {self.name}.')
         return True
     else:
         color.prYellow(f'\nYou cannot pick up the {self.name}.')
         return False
Example #5
0
def has_rope():
    if check_item('rope', player.items):
        text = "You succesfully lassoed the rope to a boulder accross " \
               "the chasm and tied the rope to a boulder in the current " \
               "room. You shimmy accross the rope and untie it.\n"
        color.prGreen(f"\n{textwrap.fill(text)}")
        return True
    else:
        color.prRed("\nYou attempted to leap accross the chasm and " "failed!")
        color.prYellow("\nNext time try to use an item to cross.")
        color.prGreen("\nTry again!\n")
        return False
Example #6
0
def go_dir(direction, current_room):
    if check_room(direction, current_room):

        direction_cmd = direction + '_to'
        new_room = getattr(current_room, direction_cmd, False)
        if new_room:
            go_room(new_room)
        else:
            color.prYellow(f"\nYou cannot go this way from "
                           f"{current_room.name}.\n")
            text = f"{current_room.description}"
            color.prGreen(f"{textwrap.fill(text)}")
            color.prPurple("\nWhat would you like to do?")

    else:
        global game
        game = False
Example #7
0
def get_inv(inventory, current_room):
    if inventory == 'i':
        if len(player.list_items()) < 1:
            color.prCyan(f"\nYou don't have any items at this time.")
        else:
            color.prCyan(f"\nYou are currently carrying:")
            for i in player.list_items():
                color.prCyan(f'-{i}')
        color.prPurple("\nWhat would you like to do?")

    elif inventory == 'l':
        if len(current_room.list_items()) < 1:
            color.prCyan(f"\nYou look arround and see that the area is empty.")
        else:
            color.prCyan(f"\nYou look around and find:")
            for i in current_room.list_items():
                color.prCyan(f'-{i}')
        color.prGreen(f"\n{textwrap.fill(str(player))}")
        color.prPurple("\nWhat would you like to do?")
Example #8
0
def go_room(new_room):
    player.current_room = new_room
    color.prGreen(f"\n{textwrap.fill(str(player))}")
    if new_room.name == 'Hidden Treasure Chamber':
        color.prGreen(f"\n***You have won!***\n")
        global game
        game = False
    else:
        color.prPurple("\nWhat would you like to do?")


game = True
try:
    player = player['player1']
    color.prGreen(f"\nWelcome {player.name}! {textwrap.fill(str(player))}")
    color.prGreen(f"\nRemember to keep looking around. "
                  "You are able to take and drop items!")
    color.prPurple("\nWhat would you like to do?")

    inventories = ['l', 'i']
    directions = ['n', 's', 'e', 'w']

    while game:
        print("\nOptions     = [l]:look around / [i]:inventory / [q]:quit"
              "\nMove        = "
              "[n]:go north    / "
              "[s]:go south  / "
              "[e]:go east / "
              "[w]:go west"
              "\nOther       = [action] [object] ex. take rock")
Example #9
0
 def on_drop(self, player):
     player.remove_item(self)
     player.current_room.add_item(self)
     color.prGreen(f'\nYou have dropped the {self.name}.')