lundi 16 mai 2016

Python how to pick item from list containing lists

I have a problem with generating map. It uses several lists which contain list of vectors. There is also list of lists of wall set(which set represent maze in place pointed by vector). So I have problem with random. When I pick random item from list of mazes. Program is going crazy, and creates something which doesn't make much sense. I tried to pick manually each maze and it worked perfectly. I tried to find solution to this problem but there wasn't answer for this kind of problem. There is definitelly something wrong with taking random item from list of mazes in this loop.

def ran_map():
walls_1 = [ [0, 0, 40, 20],
                 [60, 0, 30, 20],
                 [0, 40, 40, 10],
                 [60, 40, 30, 10]
                 ]
walls_2 = [ [0, 0, 60, 10],
                 [40, 10, 20, 10],
                 [0, 30, 20, 20],
                 [20, 40, 70, 10],
                 [80, 0, 10, 40]
                 ]
walls_3 = [ [0, 0, 10, 50],
                 [10, 0, 80, 10],
                 [80, 10, 10, 40],
                 [30, 30, 30, 20]
                 ]
s_maze = [walls_1, walls_2, walls_3]

vectors = [[60, 60], [170, 60], [380, 60], [490, 60], [60, 370], [170, 370], [380, 370], [490, 370]]

for item in vectors:
    v1 = item[0]
    v2 = item[1]
    random_item = random.choice(s_maze)
    for item in random_item:
        w1 = item[0]
        w2 = item[1]
        s1 = w1+ v1
        s2 = w2+ v2
        wall = Wall(s1, s2, item[2], item[3])
        wall_list.add(wall)
        all_sprite_list.add(wall)




Aucun commentaire:

Enregistrer un commentaire