title: How to prevent player movement outside of given area map?
body: <p>I have created a 4x6 area map using a dictionary called zonemap. I have nested multiple dictionaries within that dictionary; each one representing an area a player can visit and interact with. I want to be able to restrict player movement to that 4x6 area, and also redisplay the location from where they tried to access the "forbidden" area. This restriction would only occur when the player tries to access areas marked by the empty string. Sample code below:</p>
  
  <pre><code>import cmd
  import textwrap
  import sys
  import os
  import time
  import random
  
  class player:
      def __init__(self):
          self.name = ''
          self.job = ''
          self.hp = 0
          self.mp = 0
          self.stamina = 0
          self.faith = 0
          self.status_effects = []
          self.location = "a2"
          self.gameOver = False
  myPlayer = player()
  
  ZONENAME = ''
  DESCRIPTION = 'description'
  EXAMINATION = 'examine'
  SOLVED = False
  UP = 'up', 'north'
  DOWN = 'down', 'south'
  LEFT = 'left', 'west'
  RIGHT = 'right', 'east'
  
  solved_places = {'a1': False, 'a2': False, # more places}
  
  zonemap = {
      'a1': {
          ZONENAME: "West Mounatains",
          DESCRIPTION: "A mountain range.",
          EXAMINATION: "The slope is too steep to climb.",
          SOLVED: False,
          UP: '',
          DOWN: "Western Forest",
          LEFT: '', 
          RIGHT: "Central Mountains",
      },
      'a2': {
          ZONENAME: "Central Mountains",
          DESCRIPTION: "A mountain range",
          EXAMINATION: "These mountains go on for miles.",
          SOLVED: False,
          UP: '',
          DOWN: "Eastern Forest",
          LEFT: "Western Mountains",
          RIGHT: "Mountain Cave",
      },
      # more dictionaries
  }
  
  def prompt():
      print("\n" + "=========================")
      print("What would you like to do?")
      player_action = input("&gt; ")
      acceptable_actions = ['move', 'go', 'travel', 'walk', 'quit', 'examine', 'inspect', 'interact', 'look']
      while player_action.lower() not in acceptable_actions:
          print("Unknown action, try again.\n")
          player_action = input("&gt; ")
      if player_action.lower() == 'quit':
          sys.exit()
      elif player_action.lower() in ['move', 'go', 'travel', 'walk']:
          player_move(player_action.lower())
      elif player_action.lower() in ['examine', 'inspect', 'interact', 'look']:
          player_examine(player_action.lower())
  
  def player_move(player_action):
      ask = "Where would you like to move?\n"
      dest = input(ask)
      if dest in ['up', 'north']:
          destination = zonemap[myPlayer.location][UP]
          movement_handler(destination)
      elif dest in ['down', 'south']:
          destination = zonemap[myPlayer.location][DOWN]
          movement_handler(destination)
      elif dest in ['left', 'west']:
          destination = zonemap[myPlayer.location][LEFT]
          movement_handler(destination)
      elif dest in ['right', 'east']:
          destination = zonemap[myPlayer.location][RIGHT]
          movement_handler(destination)
  
  def movement_handler(destination):
      print("\n" + "You have moved to the " + destination + ".")
      myPlayer.location = destination
      print_location()
  
  </code></pre>
  
  <p>I'm thinking an if statement would work, but I don't know where to put it. Any help would be appreciated. I can also provide more code, if needed.</p>