1
\$\begingroup\$

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)
\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – DMGregory Aug 5 at 23:51
  • \$\begingroup\$ To expand the map horizontally, isn't it just a matter of printing longer lines of text? \$\endgroup\$ – Vaillancourt Aug 6 at 1:10
  • \$\begingroup\$ 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) \$\endgroup\$ – Anonymous Aug 6 at 1:29
0
\$\begingroup\$
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('')
| improve this answer | |
\$\endgroup\$
  • 2
    \$\begingroup\$ You should add an explanation instead of just a code snippet. \$\endgroup\$ – milk Aug 6 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.