Why doesn't my changes apply?

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!

I’m not sure that you need a class for Player1 (or for any Player for that matter), but I could be wrong.

My thoughts: the Dict for the locations seems reasonable enough and I’m guessing that it holds the coordinates for each location? Could you not track the movements of the players by having a Player associated variable that holds and updates the coordinates of said Player? Logically, if those coordinates become the same as the fixed coordinates of any location, then that’s where said Player will be.

Sorry, if I misunderstood you.
But I only have one player and…uhh…the Dict for the locations doesn’t hold the coordinates for every location. I find some by the labels on the map Bathroom, Living Room, Garden....
For example:


        if player.position in map[b]:
            e = map[b].index(player.position)
            object = list(map[b][e])
            num = len(object)
            c = num // 2
            c = round(c)
            d = (' ' * (c - 1)) + '@' + ' ' * (num - len(' ' * c))
            map[b][e] = d
            b = b + 1

No, that’s fine; your approach to this differs from one which I would have taken and maybe for very good reason, as I’ve never even tried to do what you are doing and as such, your approach could very well be the correct one.

I don’t think that I can really add anything of value here as my thought process seems to be at odds with yours, which again is fine and only natural: we all think in different ways about the same topic.

All the best with it :slight_smile:

Thanks for contributing your thoughts to my topic, it was very nice to meet you. Your opinions opened me to a bigger view of this problem. I appreciate you very much. I hope that I can have the chance to learn from you more in the future.:smiley:

1 Like

@Python_And_Ladders

I’m not sure if this will be of any use to you, but I’ve been having a think about how I would start to code a room based game that can be displayed in a terminal and I’ve got a basic ‘room’, well, a box really. I’m unsure how x-platform this would be (I don’t have access to a MS Windows box as I’m a Linux user) and I don’t know what OS you’re using.

Anyway, this is the code:

#!/usr/bin/python3

draw = {
    'h'  : '\u2500',    # Horizontal
    'v'  : '\u2502',    # Vertical
    'dr' : '\u250C',    # Down & Right
    'dl' : '\u2510',    # Down & Left
    'ur' : '\u2514',    # Up & Right
    'ul' : '\u2518',    # UP & Left
    }

width = 12
height = 8

room1 = draw ['dr']
for x in range(width):
    room1 += draw['h']

room1 += draw['dl']
room1 += '\n'

for y in range(height):
    room1 += draw['v']
    for x in range(width):
        room1 += ' '
    room1 += draw['v']
    room1 += '\n'

room1 += draw['ur']

for x in range(width):
    room1 += draw['h']

room1 += draw['ul']

print(room1)

You can change the width / height to whatever you want, within reason.

This is what I see…

┌────────────┐
│            │
│            │
│            │
│            │
│            │
│            │
│            │
│            │
└────────────┘

… aside from the gaps between the verticals.

I’m not sure if I’m going to hit a design floor later on, but anyway, I thought I’d share what I’ve done, which may or may not be of interest to you.

p.s: I know it does not address your question; sorry.

Thanks for the recommendation! :grin:
I’ll try to implement it to my project.

1 Like