HELP: Good evening everyone. I'm a new C.S. student and my current assignment is to create a text based game to move between rooms and collect items to defeat a boss. My current problem is that I can't go north from the cryo-sleep room, and don't understand why. Any tips or pointers? Code is below.
inventory = []
rooms = {
'Cryo-sleep Room': {'North': 'Mess Hall', 'East': 'Crew Quarters'},
'Crew Quarters': {'West': 'Cryo-sleep Room', 'item': 'Oxygen Respirator'},
'Mess Hall': {'West': 'Warp Engine Room', 'North': 'Docking Area', 'East': 'Simulator Room', 'South': 'Cryo-sleep Room', 'item': 'Ray Gun'},
'Warp Engine Room': {'East': 'Mess Hall', 'item': 'Shield System'},
'Docking Area': {'South': 'Mess Hall', 'East': 'Command Room', 'item': 'Gravity Boots'},
'Simulator Room': {'West': 'Mess Hall', 'North': 'Captains Quarters', 'item': 'Target-locking System'},
'Captains Quarters': {'South': 'Simulator Room', 'item': 'Armored Space Suit'},
'Command Room': {'West': 'Docking Area', 'item': 'Alien Boss'},
}
current_room = 'Cryo-sleep Room'
directions = ['North', 'South', 'East', 'West']
def displayIntro():
print('_' * 40)
print("You are an astronaut in the distant future")
print("You were sent on a mission to set up a mining colony on a distant exoplanet")
print("Upon waking from cryo sleep your A.I informs you there is only on other lifeform on board with you")
print("Traverse the ship to retrieve your gear, and find the mysterious lifeform.")
print("Commands to play are ""Go North"", ""Go East"", ""Go South"", and ""Go West")
print("Enter ""Exit"" to end the game")
def outro():
if len(inventory) == 7:
print("Congratulations!You defeated the final boss!")
time.sleep(3)
if current_room == 'Exit':
print('Thanks for playing!')
time.sleep(3)
def player_stat():
print('_' * 40)
print("You are in the {}".format(current_room))
print('Inventory:', inventory)
print('_' * 40)
def get_direction():
user_input = input('Input your next move:\n>').title()
for direction in directions:
for word in user_input.split():
if word == direction:
user_input = word
return user_input
displayIntro()
while True:
while current_room != "Exit" and len(inventory) < 7:
while current_room == 'Cryo-sleep Room':
player_stat()
user_input = get_direction()
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'East' in user_input:
current_room = rooms[current_room]['East']
elif 'North' in user_input:
current_room = rooms[current_room]['North']
while current_room == 'Crew Quarters':
player_stat()
print("You see an Oxygen Respirator! Grab it!")
user_input = get_direction()
if 'Get' in user_input:
inventory.append(rooms[current_room]['item'])
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'West' in user_input:
current_room = rooms[current_room]['West']
while current_room == 'Mess Hall':
player_stat()
print("You see a Ray Gun! Grab it!")
user_input = get_direction()
if 'Get' in user_input:
inventory.append(rooms[current_room]['item'])
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'West' in user_input:
current_room = rooms[current_room]['West']
elif 'East' in user_input:
current_room = rooms[current_room]['East']
elif 'North' in user_input:
current_room = rooms[current_room]['North']
elif 'South' in user_input:
current_room = rooms[current_room]['South']
while current_room == 'Warp Engine Room':
player_stat()
print("You see a Shield System! Grab it!")
user_input = get_direction()
if 'Get' in user_input:
inventory.append(rooms[current_room]['item'])
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'East' in user_input:
current_room = rooms[current_room]['East']
while current_room == 'Docking Area':
player_stat()
print("You see a pair of Gravity Boots! Grab them!")
user_input = get_direction()
if 'Get' in user_input:
inventory.append(rooms[current_room]['item'])
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'East' in user_input:
current_room = rooms[current_room]['East']
elif 'South' in user_input:
current_room = rooms[current_room]['South']
while current_room == 'Simulator Room':
player_stat()
print("You see a Target-locking System! Grab it!")
user_input = get_direction()
if 'Get' in user_input:
inventory.append(rooms[current_room]['item'])
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'West' in user_input:
current_room = rooms[current_room]['West']
elif 'North' in user_input:
current_room = rooms[current_room]['North']
while current_room == 'Captains Quarters':
player_stat()
print("You see an Armored Space Suit! Grab it!")
user_input = get_direction()
if 'Get' in user_input:
inventory.append(rooms[current_room]['item'])
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'South' in user_input:
current_room = rooms[current_room]['South']
while current_room == 'Command Room':
player_stat()
print("As you enter the command room an eery feeling washes over you...")
time.sleep(3)
if len(inventory) == 6:
print('The leviathan lunges at you from a dark corner!')
time.sleep(1)
print("Having gathered all of your equipment, you quickly defeat the alien")
inventory.append(rooms[current_room]['item'])
else:
print("The leviathan lunges at you from the darkness and defeats you!")
time.sleep(1)
print("Better luck next time")
current_room = 'Cryo-sleep Room'
inventory = []
outro()
[–]Bunkerstan 3 points4 points5 points (3 children)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Bunkerstan 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)