Forum Archive

3D Level help

ELECTRO8888

Hey, so I did a post like this before, but does anybody know how to make an expandable list with 3 numbers: 0 1 and 2, create a 3D game level? And if so, please explain how so people like me can understand it

Edit: and how to make 0 an empty space 1 a block and 2 A coin or something that opens the next file which is the next game when walked into?

Ex:# 1 = wall, 0 = empty 2=finish
level = [[1,1,1,1,1,1,1,1],
[1,1,1,2,0,0,1,1],
[1,1,1,1,1,0,0,1],
[1,1,1,0,0,1,0,1],
[1,1,1,0,0,1,0,1],
[1,1,1,0,1,1,0,1],
[1,1,1,0,0,0,0,1],
[1,1,1,1,1,1,1,1]]

ccc

A naive first attempt...

Also see https://forum.omz-software.com/topic/3261/instead-of-a-question-i-d-like-to-share-my-accomplishments

from random import choice

level = [[1,1,1,1,1,1,1,1],
         [1,1,1,2,0,0,1,1],
         [1,1,1,1,1,0,0,1],
         [1,1,1,0,0,1,0,1],
         [1,1,1,0,0,1,0,1],
         [1,1,1,0,1,1,0,1],
         [1,1,1,0,0,0,0,1],
         [1,1,1,1,1,1,1,1]]


def new_level(maze_size=8):
    level = [[choice((0, 1)) for x in range(maze_size)] for y in range(maze_size)]
    level[choice(range(maze_size))][choice(range(maze_size))] = 2  # add the goal
    return level


def print_level(level):
    print('\n'.join(str(row) for row in level) + '\n')


print_level(level)
print_level(new_level())
ELECTRO8888

Thank you that is very helpful, I will try to use it now 😄