Map generator for a text-based role-playing gameCharacter creator for a role-playing gameListing skills for role-playing charactersSetting the scene for a role-playing gameText-based RPG using OOPCustom resistance system for role playing gamesFind the longest rectilinear path in a matrix with descending entriesText-Based RPG Dungeon Game in JavaItem implementation for a role-playing gameBacktracking maze traversalPython 3 text adventure game

What would happen to a modern skyscraper if it rains micro blackholes?

Why is consensus so controversial in Britain?

Languages that we cannot (dis)prove to be Context-Free

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Was any UN Security Council vote triple-vetoed?

How old can references or sources in a thesis be?

How to move a thin line with the black arrow in Illustrator?

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

Convert two switches to a dual stack, and add outlet - possible here?

Can I make popcorn with any corn?

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

Which country benefited the most from UN Security Council vetoes?

Why can't I see bouncing of switch on oscilloscope screen?

How much RAM could one put in a typical 80386 setup?

Are astronomers waiting to see something in an image from a gravitational lens that they've already seen in an adjacent image?

How do I deal with an unproductive colleague in a small company?

How much of data wrangling is a data scientist's job?

Can a monk's single staff be considered dual wielded, as per the Dual Wielder feat?

Maximum likelihood parameters deviate from posterior distributions

Did Shadowfax go to Valinor?

Why doesn't H₄O²⁺ exist?

Two films in a tank, only one comes out with a development error – why?

Can I ask the recruiters in my resume to put the reason why I am rejected?

Theorems that impeded progress



Map generator for a text-based role-playing game


Character creator for a role-playing gameListing skills for role-playing charactersSetting the scene for a role-playing gameText-based RPG using OOPCustom resistance system for role playing gamesFind the longest rectilinear path in a matrix with descending entriesText-Based RPG Dungeon Game in JavaItem implementation for a role-playing gameBacktracking maze traversalPython 3 text adventure game






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3












$begingroup$


I am semi new to coding and have been following a tutorial on making a "text based RPG" on CodeClub.



Here is the full code:



#!/bin/python3

# Replace RPG starter project with this code when new instructions are live

def showInstructions():
#print a main menu and the commands
print('''
RPG Game
========

Get to the Garden with a key, a knife and a matchbox
But beware of the monsters!

Commands:
go [direction]
get [item]
''')

def showStatus():
#print the player's current status
print('---------------------------')
print('You are in the ' + currentRoom)
#print the current inventory
print('Inventory : ' + str(inventory))
#print an item if there is one
if "item" in rooms[currentRoom]:
print('You see a ' + rooms[currentRoom]['item'])
print("---------------------------")

#an inventory, which is initially empty
inventory = []

#a dictionary linking a room to other rooms
rooms =

'Hall' :
'south' : 'Kitchen',
'east' : 'Dining Room',
'item' : 'key'
,

'Kitchen' :
'north' : 'Hall',
'east' : 'Living Room',
'item' : 'knife'
,
'Dining Room' :
'west' : 'Hall',
'south' : 'Living Room',
'east' : 'Garden',
'item' : 'matchbox'
,
'Living Room' :
'north' : 'Dining Room',
'west' : 'Kitchen',
'item' : 'monster'
,
'Garden' :
'west' : 'Dining Room'




# Displays a map of all the accesable rooms from the current room.
def room_map():

# Makes sure that a variable defaults to an empty string...
# ...if the current room doesnt link to another room in that direction.
try:
north = rooms[currentRoom]['north']
except:
north = ""
try:
south = rooms[currentRoom]['south']
except:
south = ""
try:
east = rooms[currentRoom]['east']
except:
east = ""
try:
west = rooms[currentRoom]['west']
except:
west = ""

# Prints the map
n = "N"
s = "S"
vert_line = "|"
hzt_line = "-- W -- X -- E --"
print(north.center(30))
print("")
print(vert_line.center(30))
print(n.center(30))
print(vert_line.center(30))
print(west + hzt_line.center(30 - len(west) * 2) + east)
print(vert_line.center(30))
print(s.center(30))
print(vert_line.center(30))
print("")
print(south.center(30))
print("")

#start the player in the Hall
currentRoom = 'Hall'

showInstructions()

#loop forever
while True:
room_map()
showStatus()

#get the player's next 'move'
#.split() breaks it up into an list array
#eg typing 'go east' would give the list:
#['go','east']
move = ''
while move == '':
move = input('>')

move = move.lower().split()

#if they type 'go' first
if move[0] == 'go':
#check that they are allowed wherever they want to go
if move[1] in rooms[currentRoom]:
#set the current room to the new room
currentRoom = rooms[currentRoom][move[1]]
#there is no door (link) to the new room
else:
print('You can't go that way!')

#if they type 'get' first
if move[0] == 'get' :
#if the room contains an item, and the item is the one they want to get
if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']:
#add the item to their inventory
inventory += [move[1]]
#display a helpful message
print(move[1] + ' got!')
#delete the item from the room
del rooms[currentRoom]['item']
#otherwise, if the item isn't there to get
else:
#tell them they can't get it
print('Can't get ' + move[1] + '!')
# player loses if they enter a room with a monster
if 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
print('A monster has got you....GAME OVER!')
break

# player wins if they get to the garden with a key, a matchbox and a knife
if currentRoom == 'Garden' and 'key' in inventory and 'matchbox' in inventory and 'knife' in inventory:
print('You escaped the house... YOU WIN!')
break


I have tried to implement my own map/compass to display the players current location in relationship to the accesable rooms.
My code works but is very repetitive and not very efficient.



I am interested in simplifying the room_map() function.



I will eventually go about creating a real map with rooms and walls that can be updated in terms of player location, enemies etc.



The map looks like this and updates when I go to another room:
enter image description here










share|improve this question











$endgroup$


















    3












    $begingroup$


    I am semi new to coding and have been following a tutorial on making a "text based RPG" on CodeClub.



    Here is the full code:



    #!/bin/python3

    # Replace RPG starter project with this code when new instructions are live

    def showInstructions():
    #print a main menu and the commands
    print('''
    RPG Game
    ========

    Get to the Garden with a key, a knife and a matchbox
    But beware of the monsters!

    Commands:
    go [direction]
    get [item]
    ''')

    def showStatus():
    #print the player's current status
    print('---------------------------')
    print('You are in the ' + currentRoom)
    #print the current inventory
    print('Inventory : ' + str(inventory))
    #print an item if there is one
    if "item" in rooms[currentRoom]:
    print('You see a ' + rooms[currentRoom]['item'])
    print("---------------------------")

    #an inventory, which is initially empty
    inventory = []

    #a dictionary linking a room to other rooms
    rooms =

    'Hall' :
    'south' : 'Kitchen',
    'east' : 'Dining Room',
    'item' : 'key'
    ,

    'Kitchen' :
    'north' : 'Hall',
    'east' : 'Living Room',
    'item' : 'knife'
    ,
    'Dining Room' :
    'west' : 'Hall',
    'south' : 'Living Room',
    'east' : 'Garden',
    'item' : 'matchbox'
    ,
    'Living Room' :
    'north' : 'Dining Room',
    'west' : 'Kitchen',
    'item' : 'monster'
    ,
    'Garden' :
    'west' : 'Dining Room'




    # Displays a map of all the accesable rooms from the current room.
    def room_map():

    # Makes sure that a variable defaults to an empty string...
    # ...if the current room doesnt link to another room in that direction.
    try:
    north = rooms[currentRoom]['north']
    except:
    north = ""
    try:
    south = rooms[currentRoom]['south']
    except:
    south = ""
    try:
    east = rooms[currentRoom]['east']
    except:
    east = ""
    try:
    west = rooms[currentRoom]['west']
    except:
    west = ""

    # Prints the map
    n = "N"
    s = "S"
    vert_line = "|"
    hzt_line = "-- W -- X -- E --"
    print(north.center(30))
    print("")
    print(vert_line.center(30))
    print(n.center(30))
    print(vert_line.center(30))
    print(west + hzt_line.center(30 - len(west) * 2) + east)
    print(vert_line.center(30))
    print(s.center(30))
    print(vert_line.center(30))
    print("")
    print(south.center(30))
    print("")

    #start the player in the Hall
    currentRoom = 'Hall'

    showInstructions()

    #loop forever
    while True:
    room_map()
    showStatus()

    #get the player's next 'move'
    #.split() breaks it up into an list array
    #eg typing 'go east' would give the list:
    #['go','east']
    move = ''
    while move == '':
    move = input('>')

    move = move.lower().split()

    #if they type 'go' first
    if move[0] == 'go':
    #check that they are allowed wherever they want to go
    if move[1] in rooms[currentRoom]:
    #set the current room to the new room
    currentRoom = rooms[currentRoom][move[1]]
    #there is no door (link) to the new room
    else:
    print('You can't go that way!')

    #if they type 'get' first
    if move[0] == 'get' :
    #if the room contains an item, and the item is the one they want to get
    if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']:
    #add the item to their inventory
    inventory += [move[1]]
    #display a helpful message
    print(move[1] + ' got!')
    #delete the item from the room
    del rooms[currentRoom]['item']
    #otherwise, if the item isn't there to get
    else:
    #tell them they can't get it
    print('Can't get ' + move[1] + '!')
    # player loses if they enter a room with a monster
    if 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
    print('A monster has got you....GAME OVER!')
    break

    # player wins if they get to the garden with a key, a matchbox and a knife
    if currentRoom == 'Garden' and 'key' in inventory and 'matchbox' in inventory and 'knife' in inventory:
    print('You escaped the house... YOU WIN!')
    break


    I have tried to implement my own map/compass to display the players current location in relationship to the accesable rooms.
    My code works but is very repetitive and not very efficient.



    I am interested in simplifying the room_map() function.



    I will eventually go about creating a real map with rooms and walls that can be updated in terms of player location, enemies etc.



    The map looks like this and updates when I go to another room:
    enter image description here










    share|improve this question











    $endgroup$














      3












      3








      3





      $begingroup$


      I am semi new to coding and have been following a tutorial on making a "text based RPG" on CodeClub.



      Here is the full code:



      #!/bin/python3

      # Replace RPG starter project with this code when new instructions are live

      def showInstructions():
      #print a main menu and the commands
      print('''
      RPG Game
      ========

      Get to the Garden with a key, a knife and a matchbox
      But beware of the monsters!

      Commands:
      go [direction]
      get [item]
      ''')

      def showStatus():
      #print the player's current status
      print('---------------------------')
      print('You are in the ' + currentRoom)
      #print the current inventory
      print('Inventory : ' + str(inventory))
      #print an item if there is one
      if "item" in rooms[currentRoom]:
      print('You see a ' + rooms[currentRoom]['item'])
      print("---------------------------")

      #an inventory, which is initially empty
      inventory = []

      #a dictionary linking a room to other rooms
      rooms =

      'Hall' :
      'south' : 'Kitchen',
      'east' : 'Dining Room',
      'item' : 'key'
      ,

      'Kitchen' :
      'north' : 'Hall',
      'east' : 'Living Room',
      'item' : 'knife'
      ,
      'Dining Room' :
      'west' : 'Hall',
      'south' : 'Living Room',
      'east' : 'Garden',
      'item' : 'matchbox'
      ,
      'Living Room' :
      'north' : 'Dining Room',
      'west' : 'Kitchen',
      'item' : 'monster'
      ,
      'Garden' :
      'west' : 'Dining Room'




      # Displays a map of all the accesable rooms from the current room.
      def room_map():

      # Makes sure that a variable defaults to an empty string...
      # ...if the current room doesnt link to another room in that direction.
      try:
      north = rooms[currentRoom]['north']
      except:
      north = ""
      try:
      south = rooms[currentRoom]['south']
      except:
      south = ""
      try:
      east = rooms[currentRoom]['east']
      except:
      east = ""
      try:
      west = rooms[currentRoom]['west']
      except:
      west = ""

      # Prints the map
      n = "N"
      s = "S"
      vert_line = "|"
      hzt_line = "-- W -- X -- E --"
      print(north.center(30))
      print("")
      print(vert_line.center(30))
      print(n.center(30))
      print(vert_line.center(30))
      print(west + hzt_line.center(30 - len(west) * 2) + east)
      print(vert_line.center(30))
      print(s.center(30))
      print(vert_line.center(30))
      print("")
      print(south.center(30))
      print("")

      #start the player in the Hall
      currentRoom = 'Hall'

      showInstructions()

      #loop forever
      while True:
      room_map()
      showStatus()

      #get the player's next 'move'
      #.split() breaks it up into an list array
      #eg typing 'go east' would give the list:
      #['go','east']
      move = ''
      while move == '':
      move = input('>')

      move = move.lower().split()

      #if they type 'go' first
      if move[0] == 'go':
      #check that they are allowed wherever they want to go
      if move[1] in rooms[currentRoom]:
      #set the current room to the new room
      currentRoom = rooms[currentRoom][move[1]]
      #there is no door (link) to the new room
      else:
      print('You can't go that way!')

      #if they type 'get' first
      if move[0] == 'get' :
      #if the room contains an item, and the item is the one they want to get
      if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']:
      #add the item to their inventory
      inventory += [move[1]]
      #display a helpful message
      print(move[1] + ' got!')
      #delete the item from the room
      del rooms[currentRoom]['item']
      #otherwise, if the item isn't there to get
      else:
      #tell them they can't get it
      print('Can't get ' + move[1] + '!')
      # player loses if they enter a room with a monster
      if 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
      print('A monster has got you....GAME OVER!')
      break

      # player wins if they get to the garden with a key, a matchbox and a knife
      if currentRoom == 'Garden' and 'key' in inventory and 'matchbox' in inventory and 'knife' in inventory:
      print('You escaped the house... YOU WIN!')
      break


      I have tried to implement my own map/compass to display the players current location in relationship to the accesable rooms.
      My code works but is very repetitive and not very efficient.



      I am interested in simplifying the room_map() function.



      I will eventually go about creating a real map with rooms and walls that can be updated in terms of player location, enemies etc.



      The map looks like this and updates when I go to another room:
      enter image description here










      share|improve this question











      $endgroup$




      I am semi new to coding and have been following a tutorial on making a "text based RPG" on CodeClub.



      Here is the full code:



      #!/bin/python3

      # Replace RPG starter project with this code when new instructions are live

      def showInstructions():
      #print a main menu and the commands
      print('''
      RPG Game
      ========

      Get to the Garden with a key, a knife and a matchbox
      But beware of the monsters!

      Commands:
      go [direction]
      get [item]
      ''')

      def showStatus():
      #print the player's current status
      print('---------------------------')
      print('You are in the ' + currentRoom)
      #print the current inventory
      print('Inventory : ' + str(inventory))
      #print an item if there is one
      if "item" in rooms[currentRoom]:
      print('You see a ' + rooms[currentRoom]['item'])
      print("---------------------------")

      #an inventory, which is initially empty
      inventory = []

      #a dictionary linking a room to other rooms
      rooms =

      'Hall' :
      'south' : 'Kitchen',
      'east' : 'Dining Room',
      'item' : 'key'
      ,

      'Kitchen' :
      'north' : 'Hall',
      'east' : 'Living Room',
      'item' : 'knife'
      ,
      'Dining Room' :
      'west' : 'Hall',
      'south' : 'Living Room',
      'east' : 'Garden',
      'item' : 'matchbox'
      ,
      'Living Room' :
      'north' : 'Dining Room',
      'west' : 'Kitchen',
      'item' : 'monster'
      ,
      'Garden' :
      'west' : 'Dining Room'




      # Displays a map of all the accesable rooms from the current room.
      def room_map():

      # Makes sure that a variable defaults to an empty string...
      # ...if the current room doesnt link to another room in that direction.
      try:
      north = rooms[currentRoom]['north']
      except:
      north = ""
      try:
      south = rooms[currentRoom]['south']
      except:
      south = ""
      try:
      east = rooms[currentRoom]['east']
      except:
      east = ""
      try:
      west = rooms[currentRoom]['west']
      except:
      west = ""

      # Prints the map
      n = "N"
      s = "S"
      vert_line = "|"
      hzt_line = "-- W -- X -- E --"
      print(north.center(30))
      print("")
      print(vert_line.center(30))
      print(n.center(30))
      print(vert_line.center(30))
      print(west + hzt_line.center(30 - len(west) * 2) + east)
      print(vert_line.center(30))
      print(s.center(30))
      print(vert_line.center(30))
      print("")
      print(south.center(30))
      print("")

      #start the player in the Hall
      currentRoom = 'Hall'

      showInstructions()

      #loop forever
      while True:
      room_map()
      showStatus()

      #get the player's next 'move'
      #.split() breaks it up into an list array
      #eg typing 'go east' would give the list:
      #['go','east']
      move = ''
      while move == '':
      move = input('>')

      move = move.lower().split()

      #if they type 'go' first
      if move[0] == 'go':
      #check that they are allowed wherever they want to go
      if move[1] in rooms[currentRoom]:
      #set the current room to the new room
      currentRoom = rooms[currentRoom][move[1]]
      #there is no door (link) to the new room
      else:
      print('You can't go that way!')

      #if they type 'get' first
      if move[0] == 'get' :
      #if the room contains an item, and the item is the one they want to get
      if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']:
      #add the item to their inventory
      inventory += [move[1]]
      #display a helpful message
      print(move[1] + ' got!')
      #delete the item from the room
      del rooms[currentRoom]['item']
      #otherwise, if the item isn't there to get
      else:
      #tell them they can't get it
      print('Can't get ' + move[1] + '!')
      # player loses if they enter a room with a monster
      if 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
      print('A monster has got you....GAME OVER!')
      break

      # player wins if they get to the garden with a key, a matchbox and a knife
      if currentRoom == 'Garden' and 'key' in inventory and 'matchbox' in inventory and 'knife' in inventory:
      print('You escaped the house... YOU WIN!')
      break


      I have tried to implement my own map/compass to display the players current location in relationship to the accesable rooms.
      My code works but is very repetitive and not very efficient.



      I am interested in simplifying the room_map() function.



      I will eventually go about creating a real map with rooms and walls that can be updated in terms of player location, enemies etc.



      The map looks like this and updates when I go to another room:
      enter image description here







      python performance beginner role-playing-game






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 18:36









      200_success

      131k17157422




      131k17157422










      asked Nov 19 '18 at 18:08









      Axel SorensenAxel Sorensen

      182




      182




















          3 Answers
          3






          active

          oldest

          votes


















          2












          $begingroup$

          #!/bin/python3


          This is rarely where Python lives. Typically you should instead write



          #!/usr/bin/env python3


          Your rooms dict shouldn't really be a dict. Dicts are good for serialization and web APIs, but in Python they're often abused. You should use a namedtuple, if not an actual class.



          Here:



          # Displays a map of all the accesable rooms from the current room.
          def room_map():


          The convention for function documentation is to use the following format:



          def room_map():
          """
          Displays a map of all the accessible rooms from the current room.
          """


          When you do this:



          try:
          north = rooms[currentRoom]['north']
          except:
          north = ""


          There are several problems. First, your except clause is way, way too broad. You probably want to catch KeyError. However, the saner thing to do is:



          north = rooms.get(currentRoom, ).get('north', '')


          You also have a bunch of code in global scope. This should be reduced - you should move that code into one or more functions.



          'You can't go that way!'


          should simply be



          "You can't go that way!"





          share|improve this answer









          $endgroup$




















            0












            $begingroup$

            Since “Dining Room” (11 characters long) is west of the garden, you probably want



            west.rjust(11) + hzt_line + east


            for your room map. (You’ll have to increase your centering values to accommodate the additional characters.)




            Since ['item'] is often in a room dictionary, the player can type “go item”, moving to the “item” room, crashing the game. You should validate the move directions. One way: instead of move directions stored as keys of the room, store them in a 'exits' dictionary in the room.



            'Kitchen' : {
            'exits' : 'north': 'Hall', 'east': 'Living Room',
            ...



            You can test for many similar conditions using all(...) and list comprehension.



            if currentRoom == 'Garden' and all(item in inventory for item in ('key', 'matchbox', 'knife')):
            ...


            But really you want inventory to be a set. Then you can test:



            if currentRoom == 'Garden' and inventory >= 'key', 'matchbox', 'knife':
            ...





            share|improve this answer











            $endgroup$




















              0












              $begingroup$

              I'm going to assume that you used http://usingpython.com/python-rpg-game/ in order to make this because of the dictionary and the move = input("").lower().split(). No shame in that, it's a useful site. Use it too. Try instead of if item in room and if enemy in room, try if a enemy is in the room.





              share








              New contributor




              repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              $endgroup$













                Your Answer





                StackExchange.ifUsing("editor", function ()
                return StackExchange.using("mathjaxEditing", function ()
                StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
                StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                );
                );
                , "mathjax-editing");

                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "196"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207997%2fmap-generator-for-a-text-based-role-playing-game%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2












                $begingroup$

                #!/bin/python3


                This is rarely where Python lives. Typically you should instead write



                #!/usr/bin/env python3


                Your rooms dict shouldn't really be a dict. Dicts are good for serialization and web APIs, but in Python they're often abused. You should use a namedtuple, if not an actual class.



                Here:



                # Displays a map of all the accesable rooms from the current room.
                def room_map():


                The convention for function documentation is to use the following format:



                def room_map():
                """
                Displays a map of all the accessible rooms from the current room.
                """


                When you do this:



                try:
                north = rooms[currentRoom]['north']
                except:
                north = ""


                There are several problems. First, your except clause is way, way too broad. You probably want to catch KeyError. However, the saner thing to do is:



                north = rooms.get(currentRoom, ).get('north', '')


                You also have a bunch of code in global scope. This should be reduced - you should move that code into one or more functions.



                'You can't go that way!'


                should simply be



                "You can't go that way!"





                share|improve this answer









                $endgroup$

















                  2












                  $begingroup$

                  #!/bin/python3


                  This is rarely where Python lives. Typically you should instead write



                  #!/usr/bin/env python3


                  Your rooms dict shouldn't really be a dict. Dicts are good for serialization and web APIs, but in Python they're often abused. You should use a namedtuple, if not an actual class.



                  Here:



                  # Displays a map of all the accesable rooms from the current room.
                  def room_map():


                  The convention for function documentation is to use the following format:



                  def room_map():
                  """
                  Displays a map of all the accessible rooms from the current room.
                  """


                  When you do this:



                  try:
                  north = rooms[currentRoom]['north']
                  except:
                  north = ""


                  There are several problems. First, your except clause is way, way too broad. You probably want to catch KeyError. However, the saner thing to do is:



                  north = rooms.get(currentRoom, ).get('north', '')


                  You also have a bunch of code in global scope. This should be reduced - you should move that code into one or more functions.



                  'You can't go that way!'


                  should simply be



                  "You can't go that way!"





                  share|improve this answer









                  $endgroup$















                    2












                    2








                    2





                    $begingroup$

                    #!/bin/python3


                    This is rarely where Python lives. Typically you should instead write



                    #!/usr/bin/env python3


                    Your rooms dict shouldn't really be a dict. Dicts are good for serialization and web APIs, but in Python they're often abused. You should use a namedtuple, if not an actual class.



                    Here:



                    # Displays a map of all the accesable rooms from the current room.
                    def room_map():


                    The convention for function documentation is to use the following format:



                    def room_map():
                    """
                    Displays a map of all the accessible rooms from the current room.
                    """


                    When you do this:



                    try:
                    north = rooms[currentRoom]['north']
                    except:
                    north = ""


                    There are several problems. First, your except clause is way, way too broad. You probably want to catch KeyError. However, the saner thing to do is:



                    north = rooms.get(currentRoom, ).get('north', '')


                    You also have a bunch of code in global scope. This should be reduced - you should move that code into one or more functions.



                    'You can't go that way!'


                    should simply be



                    "You can't go that way!"





                    share|improve this answer









                    $endgroup$



                    #!/bin/python3


                    This is rarely where Python lives. Typically you should instead write



                    #!/usr/bin/env python3


                    Your rooms dict shouldn't really be a dict. Dicts are good for serialization and web APIs, but in Python they're often abused. You should use a namedtuple, if not an actual class.



                    Here:



                    # Displays a map of all the accesable rooms from the current room.
                    def room_map():


                    The convention for function documentation is to use the following format:



                    def room_map():
                    """
                    Displays a map of all the accessible rooms from the current room.
                    """


                    When you do this:



                    try:
                    north = rooms[currentRoom]['north']
                    except:
                    north = ""


                    There are several problems. First, your except clause is way, way too broad. You probably want to catch KeyError. However, the saner thing to do is:



                    north = rooms.get(currentRoom, ).get('north', '')


                    You also have a bunch of code in global scope. This should be reduced - you should move that code into one or more functions.



                    'You can't go that way!'


                    should simply be



                    "You can't go that way!"






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 19 '18 at 19:43









                    ReinderienReinderien

                    5,250926




                    5,250926























                        0












                        $begingroup$

                        Since “Dining Room” (11 characters long) is west of the garden, you probably want



                        west.rjust(11) + hzt_line + east


                        for your room map. (You’ll have to increase your centering values to accommodate the additional characters.)




                        Since ['item'] is often in a room dictionary, the player can type “go item”, moving to the “item” room, crashing the game. You should validate the move directions. One way: instead of move directions stored as keys of the room, store them in a 'exits' dictionary in the room.



                        'Kitchen' : {
                        'exits' : 'north': 'Hall', 'east': 'Living Room',
                        ...



                        You can test for many similar conditions using all(...) and list comprehension.



                        if currentRoom == 'Garden' and all(item in inventory for item in ('key', 'matchbox', 'knife')):
                        ...


                        But really you want inventory to be a set. Then you can test:



                        if currentRoom == 'Garden' and inventory >= 'key', 'matchbox', 'knife':
                        ...





                        share|improve this answer











                        $endgroup$

















                          0












                          $begingroup$

                          Since “Dining Room” (11 characters long) is west of the garden, you probably want



                          west.rjust(11) + hzt_line + east


                          for your room map. (You’ll have to increase your centering values to accommodate the additional characters.)




                          Since ['item'] is often in a room dictionary, the player can type “go item”, moving to the “item” room, crashing the game. You should validate the move directions. One way: instead of move directions stored as keys of the room, store them in a 'exits' dictionary in the room.



                          'Kitchen' : {
                          'exits' : 'north': 'Hall', 'east': 'Living Room',
                          ...



                          You can test for many similar conditions using all(...) and list comprehension.



                          if currentRoom == 'Garden' and all(item in inventory for item in ('key', 'matchbox', 'knife')):
                          ...


                          But really you want inventory to be a set. Then you can test:



                          if currentRoom == 'Garden' and inventory >= 'key', 'matchbox', 'knife':
                          ...





                          share|improve this answer











                          $endgroup$















                            0












                            0








                            0





                            $begingroup$

                            Since “Dining Room” (11 characters long) is west of the garden, you probably want



                            west.rjust(11) + hzt_line + east


                            for your room map. (You’ll have to increase your centering values to accommodate the additional characters.)




                            Since ['item'] is often in a room dictionary, the player can type “go item”, moving to the “item” room, crashing the game. You should validate the move directions. One way: instead of move directions stored as keys of the room, store them in a 'exits' dictionary in the room.



                            'Kitchen' : {
                            'exits' : 'north': 'Hall', 'east': 'Living Room',
                            ...



                            You can test for many similar conditions using all(...) and list comprehension.



                            if currentRoom == 'Garden' and all(item in inventory for item in ('key', 'matchbox', 'knife')):
                            ...


                            But really you want inventory to be a set. Then you can test:



                            if currentRoom == 'Garden' and inventory >= 'key', 'matchbox', 'knife':
                            ...





                            share|improve this answer











                            $endgroup$



                            Since “Dining Room” (11 characters long) is west of the garden, you probably want



                            west.rjust(11) + hzt_line + east


                            for your room map. (You’ll have to increase your centering values to accommodate the additional characters.)




                            Since ['item'] is often in a room dictionary, the player can type “go item”, moving to the “item” room, crashing the game. You should validate the move directions. One way: instead of move directions stored as keys of the room, store them in a 'exits' dictionary in the room.



                            'Kitchen' : {
                            'exits' : 'north': 'Hall', 'east': 'Living Room',
                            ...



                            You can test for many similar conditions using all(...) and list comprehension.



                            if currentRoom == 'Garden' and all(item in inventory for item in ('key', 'matchbox', 'knife')):
                            ...


                            But really you want inventory to be a set. Then you can test:



                            if currentRoom == 'Garden' and inventory >= 'key', 'matchbox', 'knife':
                            ...






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 20 '18 at 2:13

























                            answered Nov 20 '18 at 2:03









                            AJNeufeldAJNeufeld

                            6,6241621




                            6,6241621





















                                0












                                $begingroup$

                                I'm going to assume that you used http://usingpython.com/python-rpg-game/ in order to make this because of the dictionary and the move = input("").lower().split(). No shame in that, it's a useful site. Use it too. Try instead of if item in room and if enemy in room, try if a enemy is in the room.





                                share








                                New contributor




                                repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.






                                $endgroup$

















                                  0












                                  $begingroup$

                                  I'm going to assume that you used http://usingpython.com/python-rpg-game/ in order to make this because of the dictionary and the move = input("").lower().split(). No shame in that, it's a useful site. Use it too. Try instead of if item in room and if enemy in room, try if a enemy is in the room.





                                  share








                                  New contributor




                                  repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.






                                  $endgroup$















                                    0












                                    0








                                    0





                                    $begingroup$

                                    I'm going to assume that you used http://usingpython.com/python-rpg-game/ in order to make this because of the dictionary and the move = input("").lower().split(). No shame in that, it's a useful site. Use it too. Try instead of if item in room and if enemy in room, try if a enemy is in the room.





                                    share








                                    New contributor




                                    repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






                                    $endgroup$



                                    I'm going to assume that you used http://usingpython.com/python-rpg-game/ in order to make this because of the dictionary and the move = input("").lower().split(). No shame in that, it's a useful site. Use it too. Try instead of if item in room and if enemy in room, try if a enemy is in the room.






                                    share








                                    New contributor




                                    repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.








                                    share


                                    share






                                    New contributor




                                    repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    answered 2 mins ago









                                    repl userrepl user

                                    1




                                    1




                                    New contributor




                                    repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





                                    New contributor





                                    repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






                                    repl user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Code Review Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        Use MathJax to format equations. MathJax reference.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207997%2fmap-generator-for-a-text-based-role-playing-game%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

                                        Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

                                        Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar