I was making a map of a game. Where @ represents the player on it.
I would create a class player and dictionary that contains the map.
class player1:
def __init__(self):
self.position = 'garden'
player = player1()
map = {
1: ['_' for _ in range(36)],
2: ['|' + ' ' * 10 + '+' + ' ' * 16 + '|', ' ' * 6, '|'],
3: ['| ', 'Bathroom', ' |' + ' ' * 16 + '|', ' ' * 6, '|'],
4: ['|' + '_' * 10 + '|' + ' ' * 3, 'Living Room', ' ' * 2 + '|' + ' ' * 6 + '|'],
5: ['|' + ' ' * 10 + '|' + ' ' * 16 + '|', 'Garden', '|'],
6: ['| ', 'Kitchen', ' |' + ' ' * 16 + '|' + ' ' * 6 + '|'],
7: ['|' + ' ' * 10 + '|' + '_' * 5 + '+' + '_' * 10 + '|' + ' ' * 6 + '|'],
8: ['|' + '_' * 13 + '+__', '+', '_' * 8, '+', '_|' + ' ' * 6 + '|'],
9: ['|' + ' ' * 14 + '|', ' ' * 3, '|', ' ' * 4, '|', ' ' * 3, '|', ' ' * 6, '|'],
10: ['|' + ' ' * 3, 'Bedroom', ' ' * 4 + '|' + '_' * 3 + '|' + '_' * 5, ' ' * 3, '_' * 7 + '|'],
11: ['|' + '_' * 14 + '|' + ' ' * 11 + '/']
}
Then another dictionary containing possible places the player could be at.
Dict = {
'Hallway': map[8][2],
'Entryway': map[8][4],
'Lumber Room': map[9][2],
'Cement Ground': map[9][4],
'Front Porch': map[9][6],
'Garden': map[10][4]
}
Then I would implement @ to the players current location.(Problem here)
a = len(map)
b = 1
for _ in range(b != a):
if player.position in list(Dict):
num = len(Dict[player.position])
c = num // 2
c = round(c)
d = (' ' * (c - 1)) + '@' + ' ' * (num - len(' ' * c))
A = list(Dict)
B = A.index(player.position) #Finds the index of the key equal to player.position in Dict
A = list(Dict.values())
A[B] = d """This is where I update the map."""
b = b + 1
else:
pass
Finally I print the map
b = 1
while b < a + 1:
print(''.join(map[b]))
b = b + 1
When I update the map why doesn’t it apply?
Is there anything I am missing or are there other methods?
Thanks!