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()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)