Python - Dungeon Crawler Game - Moving one place through a list
<p>I'm writing a basic dungeon crawler and I'm having a problem with navigating around the map. I have a map that is stored in a list of lists, like this:</p>

<pre><code>map = [
    [0,0,0,0,0],
    [0,1,1,1,0],
    [0,1,0,1,0],
    [0,1,1,1,0],
    [0,0,0,0,0]
]
</code></pre>

<p>All the 1s stand for rooms, the 0s for walls.</p>

<p>My code to move around the map states a player position as an X,Y coordinate, then passes the map as an argument to a function, using the X,Y coordinates as the index reference. (So Y would be which list to reference, X would be which item in that list)</p>

<p>So my code: states player position on X,Y axis; asks for player input for up, down, left, right by passing the map and X,Y as arguments; checks if an index position + 1 isn't a 0; and then updates the player position accordingly by 1 if it's free. This is the whole thing below:</p>

<pre><code>playerPosX = 1
playerPosY = 1

map = [
    [0,0,0,0,0],
    [0,1,1,1,0],
    [0,1,0,1,0],
    [0,1,1,1,0],
    [0,0,0,0,0]
]

def goRight(posX, posY, map):
    if map[posY][posX + 1] == 0:
        print('You can\'t go that way.')
    else:
        posX += 1
    return posX

def goLeft(posX, posY, map):
    if map[posY][posX - 1] == 0:
        print('You can\'t go that way.')
    else:
        posX -= 1
    return posX

def goDown(posX, posY, map):
    if map[posY + 1][posX] == 0:
        print('You can\'t go that way.')
    else:
        posY += 1
    return posY

def goUp(posX, posY, map):
    if map[posY - 1][posX] == 0:
        print('You can\'t go that way.')
    else:
        posY -= 1
    return posY

while True:
    print(playerPosX, playerPosY)
    print('North(n), South(s), West(w), East(e), or Quit(q)?')
    direction = input()
    if direction == 'w':
        playerPosX = goLeft(playerPosX, playerPosY, map)
    elif direction == 'e':
        playerPosX = goRight(playerPosX, playerPosY, map)
    elif direction == 'n':
        playerPosY = goUp(playerPosX, playerPosY, map)
    elif direction == 's':
        playerPosY == goDown(playerPosX, playerPosY, map)
    elif direction == 'q':
        print('Thank you for playing!')
        break
    else:
        print('I didn\'t catch that.')
</code></pre>

<p>The problem I'm having is that all of the code is working as it should apart from the goDown function. The Y index position of lists isn't incrementing by 1. I added print function that displays the player's position, so you can see it works in every other direction.</p>

<p>Does anyone spot what I'm doing wrong? I'm fairly new to programming so it could be a fundamental error or could even just be a typo. I've been stuck for ages!</p>

<p>Thanks</p>