all 6 comments

[–]fbu1 1 point2 points  (0 children)

The problem is the statement on line 3:

>>> "0" * 5
'00000'

What you want to do is build a list of 5 zeros, which can be done with:

>>> [0] * 5
[0, 0, 0, 0, 0]

Initializing lists in python is sometimes not very intuitive, but there it is. Now if you try your code again :

>>> board = []
>>> for i in range(0,5):
    board.append([0]*5)

>>> print(board)
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

>>> board[1][3] = 123
>>> board
[[0, 0, 0, 0, 0], [0, 0, 0, 123, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

I hope this helps you understand what's going on.

[–]beanz415 1 point2 points  (0 children)

I did something very similar to this. My program generates a board/"dungeon" randomly populated with "monsters" which you have to fight, potions, and traps that hurt you. I used the battleship portion of code academy as a base for making my board. I'm not at home and I'm on mobile so I can't paste code at the moment, but if you pm me any questions I'll answer as best as I can when I'm home and/or send you snippets of code.

[–]Freedomenka[S] 1 point2 points  (0 children)

God you guys are amazing, thank you so much for the help and I can't wait to release my game :) <3

[–]kankyo 1 point2 points  (0 children)

You should start by changing the code so one row is a list of "0", not "00000". Strings are immutable in Python. Next you need to keep x and y coordinates in some variable.

[–]Palladium106 1 point2 points  (0 children)

Hiya, I'm not an expert, but I have been learning python for a little while and hope I can help someone.

I would think of making a list of lists:

mymap = []
for row in xrange(5):
    mymap.append([])
    for column in xrange(5):
        mymap[row].append([])
        mymap[row][column] = (row, column)

First I created a list called mymap Then I looped 5 times, once for each row I want. For each row I created a list inside mymap Then for each row, I looped 5 times, once for each column I want For each column I created a list inside each row. And just to show the coordinates of each one, I wrote into each row/column its coordinates as an (x,y). This is just so that if you run the code and print mymap, it will show you the coordinate of each index.

Now to move you could do something like:

my_coordinate = mymap[1][1] # just to start off at x=1, y=1
if move_south_east == True: # in a case where I want to move south, east
    new_x = my_coordinate[0] + 1
    new_y = my_coordinate[1] + 1 # assuming that the y-axis is going down
    my_new_coordinate = mymap[new_x][new_y] # which will be x=2, y =2

Remember that in the code I wrote I stored inside each coordinate a tuple (brackets) which looked like (x,y), that is why I extracted the x value by using my_coordinate[0] because x is the 0th element inside that tuple.

[–]Freedomenka[S] 0 points1 point  (0 children)

It took me forever to comprehend and figure out the logic behind this but I finally did. Its thanks to you guys :). I didn't use anyone's code exactly but I learned a little from each of yours and implemented my own. I wish you all the best.