Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have created a fully functioning grid with player movements in python. Although I need some help placing treasure chests around the map. The user needs to be asked how much treasure chests will be placed into the grid, then that amount of treasure chests will be placed randomly on the map. Could anyone help me with this?

What I have tried:

Python
def setupGrid():
    N = int(input("How big would you like the grid to be?"))
    for x in range(0, N):
        row = []
        for y in range(0, N):
            if x == player_loc[0] and y == player_loc[1]:
                row.append(character)
            else:
                row.append('O')
        grid.append(row)

def moveSouth(n):
    global player_loc
    grid[player_loc[0]][player_loc[1]] = "O"
    grid[player_loc[0] + n][player_loc[1]] = character
    player_loc = (player_loc[0] + n, player_loc[1])

def moveNorth(n):
    global player_loc
    grid[player_loc[0]][player_loc[1]] = "O"
    grid[player_loc[0] - n][player_loc[1]] = character
    player_loc = (player_loc[0] - n, player_loc[1])

def moveEast(n):
    global player_loc
    grid[player_loc[0]][player_loc[1]] = "O"
    grid[player_loc[0]][player_loc[1] + n] = character
    player_loc = (player_loc[0], player_loc[1] + n)

def moveWest(n):
    global player_loc
    grid[player_loc[0]][player_loc[1]] = "O"
    grid[player_loc[0]][player_loc[1] - n] = character
    player_loc = (player_loc[0], player_loc[1] - n)

def gridRunner():
    while True:
        for row in grid:
            print (row)

        switch = {NORTH : moveNorth,
                  SOUTH : moveSouth,
                  EAST  : moveEast,
                  WEST  : moveWest }
        P = input("What direction would you like to move in? North (N), South(S), East(E) or West(W)?").upper()

        if P not in switch:
            print ("invalid move")
            continue

        distance = int(input("How far would you like to move in this direction? (blocks are the units)"))
        switch[P](distance)

setupGrid()
gridRunner()
Posted
Updated 9-Apr-16 4:30am
v2
Comments
Member 12447875 9-Apr-16 8:06am    
Sorry about the indentations, the website would not let me change it.
Richard MacCutchan 9-Apr-16 10:31am    
Fixed it for you; click Improve question and you can see how I did it.

As to your question you need to show where in the code you want the changes/additions.
Member 12447875 9-Apr-16 12:50pm    
Thanks Richard, any chance you know how to add in the treasures though?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900