Ejemplo n.º 1
0
def item_on_ground_message():
    """Prints what item is on the ground when moved onto

    PARAM player a correctly formatted dictionary
    PARAM dungeon_map a list of lists
    PRECONDITION player is a correctly formatted dictionary
    PRECONDITION dungeon_map is a list with lists with 12 elements each
    POSTCONDITION prints a message about what item is on the ground is printed

    """
    dungeon_map = map.get_map()
    player = character.get_character_info()
    # prints a message if player is on a key
    if dungeon_map[player['row']][player['column']] == ' K ':
        print('You see a key on a table')
    # prints a message if player is on a sword
    elif dungeon_map[player['row']][player['column']] == ' S ':
        print(
            'There is a sword propped up against the wall, it seems to be in good condition'
        )
    # prints a message if player is on bread
    elif dungeon_map[player['row']][player['column']] == ' B ':
        print('You see some bread left on a bench, it looks edible')
    # prints a message if player is on treasure
    elif dungeon_map[player['row']][player['column']] == ' C ':
        print('You find the treasure you were searching for')
Ejemplo n.º 2
0
def scenario_message():
    """Prints a message about the environment

    PARAM player a correctly formatted dictionary
    PARAM dungeon_map a list of lists
    PRECONDITION player is a correctly formatted dictionary
    PRECONDITION dungeon_map is a list with lists with 12 elements each
    POSTCONDITION prints a message about the environment the player is on
    """
    dungeon_map = map.get_map()
    player = character.get_character_info()
    if player['row'] == 9 and player['column'] == 4:
        print('You come across a church that is still in good condition')
        print('There is a door that seems to be unlocked')
    elif player['row'] == 7 and player['column'] == 4:
        print('There is a run down shack to your left')
    elif dungeon_map[player['row']][player['column']] == '| |':
        print('You walk over the stone bridge')
    elif dungeon_map[player['row']][player['column'] - 1] == ' L ':
        print('You reach the treasury but it looks like the door is locked')
        print('You will need some sort of key to get through')
    elif dungeon_map[player['row']][player['column']] == '   ':
        print('You are on a dirt path')
    elif dungeon_map[player['row']][player['column']] == '...':
        print('The wooden boards creak underneath your feet')
    elif dungeon_map[player['row']][player['column']] == ':::':
        print('You are on a grassy field')
    elif dungeon_map[player['row']][player['column']] == '###':
        print('You walk over the cold stone floor of the church')
    elif dungeon_map[player['row']][player['column']] == '"""':
        print('You are in the treasury')
Ejemplo n.º 3
0
 def test_take_key(self):
     character.character_info['inventory'] = []
     character.set_column(5)
     character.set_row(5)
     map.set_map(5, 5, ' K ')
     take_item_check('take key')
     self.assertEqual(character.get_character_info()['inventory'], ['key'])
Ejemplo n.º 4
0
 def test_take_treasure(self):
     character.character_info['inventory'] = []
     character.set_column(5)
     character.set_row(5)
     map.set_map(5, 5, ' C ')
     take_item_check('take treasure')
     self.assertEqual(character.get_character_info()['inventory'],
                      ['treasure'])
Ejemplo n.º 5
0
def take_item_check(player_input: str) -> bool:
    """if user inputs to take an item checks if it is on the players tile

    PARAM player a correctly formatted dictionary
    PARAM dungeon_map a list of lists
    PARAM player_input a string
    PRECONDITION player is a correctly formatted dictionary
    PRECONDITION dungeon_map is a list of lists with 12 elements each
    PRECONDITION player_input is a string
    POSTCONDITION Prints nothing or an error message if input is incorrect
    RETURN True if error in input and False if no error
    """
    dungeon_map = map.get_map()
    player = character.get_character_info()
    # if player inputs take key checks if key is on the player and takes it if it is
    if player_input == 'take key' and dungeon_map[player['row']][
            player['column']] == ' K ':
        dungeon_map[player['row']][player['column']] = '###'
        player['inventory'].append('key')
        return False

    # if player inputs take sword checks if sword is on the player and takes it if it is
    elif player_input == 'take sword' and dungeon_map[player['row']][
            player['column']] == ' S ':
        dungeon_map[player['row']][player['column']] = '...'
        player['inventory'].append('sword')
        return False

    # if player inputs take bread checks if bread is on the player and takes it if it is
    elif player_input == 'take bread' and dungeon_map[player['row']][
            player['column']] == ' B ':
        dungeon_map[player['row']][player['column']] = '   '
        player['inventory'].append('bread')
        return False

    # if player inputs take treasure checks if treasure is on the player and takes it if it is
    elif player_input == 'take treasure' and dungeon_map[player['row']][
            player['column']] == ' C ':
        dungeon_map[player['row']][player['column']] = '"""'
        player['inventory'].append('treasure')
        return False

    # the item the user tried to take is not on the player, prints an error
    else:
        print('You cant take that')
        return True
Ejemplo n.º 6
0
def dont_have_item_check(player_input: str) -> bool:
    """checks if the user has the item they are trying to use

    PARAM player_input a string
    PARAM player a dictionary
    PRECONDITION player_input is a string
    PRECONDITION player is a correctly formatted dictionary
    RETURN True if player doesnt have item, False if they do
    """
    player = character.get_character_info()
    if player_input == 'use sword' and 'sword' in player['inventory']:
        return False
    elif player_input == 'use bread' and 'bread' in player['inventory']:
        return False
    else:
        # no correct input found so returns error = true
        print('You dont have that item')
        return True
Ejemplo n.º 7
0
def collision_check(player_input: str) -> bool:
    """Checks if there is a wall where the player is trying to move

    PARAM player a correctly formatted dictionary
    PARAM dungeon_map a list of lists
    PARAM player_input a string
    PRECONDITION player is a correctly formatted dictionary
    PRECONDITION dungeon_map is a list of lists with 12 elements each
    PRECONDITION player_input is the string north, east, south, or west
    POSTCONDITION Prints nothing or an error message if there is a wall
    RETURN True if user cant walk in that direction False otherwise
    """
    # list of all un-walkable terrain
    unwalkable_terrain = ('---', ' | ', ' \ ', ' / ', '~~~', '|||', ' D ',
                          ' L ')
    dungeon_map = map.get_map()
    player = character.get_character_info()

    # Checks user move direction and whether that directions area is in un-walkable terrain
    if player_input == 'east' and dungeon_map[player['row']][
            player['column'] + 1] not in unwalkable_terrain:
        character.set_column(player['column'] + 1)
        return False
    elif player_input == 'west' and dungeon_map[player['row']][
            player['column'] - 1] not in unwalkable_terrain:
        character.set_column(player['column'] - 1)
        return False
    elif player_input == 'north' and dungeon_map[player['row'] - 1][
            player['column']] not in unwalkable_terrain:
        character.set_row(player['row'] - 1)
        return False
    elif player_input == 'south' and dungeon_map[player['row'] + 1][
            player['column']] not in unwalkable_terrain:
        character.set_row(player['row'] + 1)
        return False
    # User tried to move toward an un-walkable terrain, prints error
    else:
        print('You cant move in that direction')
        return True
Ejemplo n.º 8
0
def adjacent_door_check(player_input: str) -> bool:
    """if user tries to interact with a door, checks if the door is adjacent

    PARAM player a correctly formatted dictionary
    PARAM dungeon_map a list of lists
    PARAM player_input a string
    PRECONDITION player is a correctly formatted dictionary
    PRECONDITION dungeon_map is a list of lists with 12 elements each
    PRECONDITION player_input is a string
    POSTCONDITION Prints nothing or an error message if input is incorrect
    RETURN True if error in input and False if no error
    """
    dungeon_map = map.get_map()
    player = character.get_character_info()
    # if user inputs unlock door, has a key, and there is a locked door then the door opens
    if player_input == 'unlock door' and dungeon_map[player['row']][player['column'] - 1] == ' L ' \
            and 'key' in player['inventory']:
        dungeon_map[player['row']][player['column'] - 1] = '   '
        return False

    # if user inputs open door and there is a door then the door opens
    elif player_input == 'open door' and dungeon_map[player['row']][
            player['column'] + 1] == ' D ':
        dungeon_map[player['row']][player['column'] + 1] = '   '
        return False

    # if user inputs unlock door but has no key the prints an error message
    elif player_input == 'unlock door' and dungeon_map[player['row']][player['column'] - 1] == ' L ' \
            and 'key' not in player['inventory']:
        print('You do not have a key to open that door')
        return True

    # user input was incorrect so prints an error message
    else:
        print('i dont understand')
        return True