# How to create a 2D tile-map in python ASCII style

Still learning about python programming and I wanted to create a little map like below but the thing is I know a for loop will draw down not draw across. However, I want to change the size of the area and add new tiles later on. I understand that this might be a really bad question but I cannot wrap my head around this.

posX = 0
posY = 0

tile1 = 'X'
tile2 = 'O'

width = int(12)
height = int(9)

'''

<--- 12 --->
XXXXXXXXXXXX ^
XOOOOOOOOOOX |
XOOOOOOOOOOX |
XOOOOOOOOOOX
XOOOOOOOOOOX 9
XOOOOOOOOOOX
XOOOOOOOOOOX |
XOOOOOOOOOOX |
XXXXXXXXXXXX v

'''

#Draws down and across
for i in range(width):
print(tile1 * width)

• I'm not sure what specific aspect you're having trouble with here. What do you mean by "a for loop will draw down not draw across"? A for loop will do whatever you program it to do. Would you like to show us the for loop code you've tried for this so far, and explain how its behaviour differs from what you want? – DMGregory Aug 5 at 23:51
• To expand the map horizontally, isn't it just a matter of printing longer lines of text? – Vaillancourt Aug 6 at 1:10
• I am trying to create a row and column for each tile. I made it so the top left would be 0, 0 and the bottom right would be 12, 9 this way I can put inside of each row and column a type of tile I want for the area/map I made. Using a for loop for it (I'll update it won't work) – Anonymous Aug 6 at 1:29

tile = ['O','X']

posX = 0
posY = 0

width = int(12)
height = int(9)

'''

<--- 12 --->
XXXXXXXXXXXX ^
XOOOOOOOOOOX |
XOOOOOOOOOOX |
XOOOOOOOOOOX
XOOOOOOOOOOX 9
XOOOOOOOOOOX
XOOOOOOOOOOX |
XOOOOOOOOOOX |
XXXXXXXXXXXX v

'''

map=[]
map.append([1]*12)
map_row=[1]+[0]*10+[1]
map.extend([map_row]*7)
map.append([1]*12)

for y in range(height):
for x in range(width):
print(tile[map[y][x]], end='')
print('')


Or also:

map=[]
map.append(['X']*12)
row=['X']+['O']*10+['X']
map.extend([row]*7)
map.append(['X']*12)

for map_row in map:
for tile in map_row:
print(tile, end='')
print('')

• You should add an explanation instead of just a code snippet. – milk Aug 6 at 15:31