Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Single User Dungeon
#3
Some points on your code. You ask about printing the room contents. The join method would be useful there:
>>> ', '.join(['spam', 'spam', 'eggs'])
'spam, spam, eggs'
You have a lot of if statements like:
if choice == 'N' or choice == 'n':
    direction = 0
Note that this can be simplified:
if choice.lower() == 'n':
    direction = 0
That's the standard way to do a case-insensitive comparison in Python. However, I note that you are mapping to indexes for another list. This can be done easily with the find method of strings:
direction = 'nswe'.find(choice.lower())
Find will return the index in 'nswe' of choice, which is lower cased to match 'nswe'. So, if choice is 's', find will return 1. If choice is not in 'nswe', find will return -1, which is what your code is expecting.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Single User Dungeon - by kython - Mar-01-2017, 04:35 PM
RE: Single User Dungeon - by nilamo - Mar-01-2017, 05:09 PM
RE: Single User Dungeon - by ichabod801 - Mar-01-2017, 11:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Single User Dungeon tckay 1 3,108 Apr-30-2017, 09:23 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020