BardSeed
August 11th, 2009, 02:36 PM
I'm attempting to make a text-game to be run in IDLE. I've got the bare bones of my first room done, but I've realised that I don't know how to link rooms. I'd like the user to be able to pass back and forth between rooms.
As far as I can tell, classes will be needed, but I'm not very adept with them, having only been learning Python for less than a week. Here's what I have so far.
#Defining my functions.
#The menu function will add 1 to the index number of each entry
#and display them like this: "1) Item".
def menu(list, question):
for entry in list:
print 1 + list.index(entry),
print ") " + entry
return input(question)
#Lists for object in each area.
itemsA = ["beds", "drain", "open door"]
#Brief introduction
print """You awake in a room that is unfamiliar to you.
The harsh light stings your weary eyes. The walls and
floor appear to be composed of thick metal. Looking
around, you see""", len(itemsA), """points of interest:"""
for entry in itemsA:
print entry
print "Please enter the number that corresponds to your choice."
print " "
loop=1
choice = 1
while loop==1:
choice = menu(itemsA, "What would you like to examine?")
if choice == 1:
print " "
print "You see four beds; they seem to have been used recently."
print " "
elif choice == 2:
print " "
print "It looks as if it's been used as a toilet."
print " "
elif choice == 3:
print " "
print "The same sterile light as from this room emanates from the hallway."
print " "
else:
print " "
print "That is not an appropriate action."
print " "
I'd like to offer the player the option to pass through the door when they examine it. So, it would be something like this(although this code doesn't work, it will explain my intentions):
elif choice == 3:
print " "
print "The same sterile light as from this room emanates from the hallway."
input("Would you like to move into the hallway? (1 for yes, 2 for no)")
if input == 1:
Code for new room
print " "
Any help or hints would be greatly appreciated.
As far as I can tell, classes will be needed, but I'm not very adept with them, having only been learning Python for less than a week. Here's what I have so far.
#Defining my functions.
#The menu function will add 1 to the index number of each entry
#and display them like this: "1) Item".
def menu(list, question):
for entry in list:
print 1 + list.index(entry),
print ") " + entry
return input(question)
#Lists for object in each area.
itemsA = ["beds", "drain", "open door"]
#Brief introduction
print """You awake in a room that is unfamiliar to you.
The harsh light stings your weary eyes. The walls and
floor appear to be composed of thick metal. Looking
around, you see""", len(itemsA), """points of interest:"""
for entry in itemsA:
print entry
print "Please enter the number that corresponds to your choice."
print " "
loop=1
choice = 1
while loop==1:
choice = menu(itemsA, "What would you like to examine?")
if choice == 1:
print " "
print "You see four beds; they seem to have been used recently."
print " "
elif choice == 2:
print " "
print "It looks as if it's been used as a toilet."
print " "
elif choice == 3:
print " "
print "The same sterile light as from this room emanates from the hallway."
print " "
else:
print " "
print "That is not an appropriate action."
print " "
I'd like to offer the player the option to pass through the door when they examine it. So, it would be something like this(although this code doesn't work, it will explain my intentions):
elif choice == 3:
print " "
print "The same sterile light as from this room emanates from the hallway."
input("Would you like to move into the hallway? (1 for yes, 2 for no)")
if input == 1:
Code for new room
print " "
Any help or hints would be greatly appreciated.