Question: Hello! I am programming a text game for a Python project and the objective is to have 8 rooms with 6 items and a villain
Hello! I am programming a text game for a Python project and the objective is to have rooms with items and a "villain" spread throughout. In order to complete the game, you must collect all items and move to the boss. But every time I try to pick up an item in a room, it gives me the message that its the wrong item and 'not in the room' when it clearly is Could someone please help me figure out why Im unable to pick up the item that corresponds to the correct room? Thank you! Here is my code: I went a little silly with the theme, sorry!
# Skeleton Lord's Revengence
# Collect items to win the game, or be trapped with Skeleton Lord for eternity.
# Move commands: go South, go North, go East, go West
# Add to Inventory: get 'item name'
import random
# Define the game map as a dictionary linking rooms to other rooms and items to their corresponding rooms.
gamemap
'Main Cell': South: 'Eternal Fire Pit', 'North': 'Room of Everlasting Despair', 'East': 'Huge Skull Door'
'Eternal Fire Pit': North: 'Main Cell', 'East': 'Forbidden Armory', 'item': 'Flame Sword'
'Forbidden Armory': West: 'Eternal Fire Pit', 'item': 'AntiMagic Armor'
'Room of Everlasting Despair': South: 'Main Cell', 'East': 'Torture Chamber', 'item': 'Cursed Ring'
'Torture Chamber': West: 'Room of Everlasting Despair', 'item': 'Skull Lantern'
'Huge Skull Door': West: 'Main Cell', 'North': 'Skeleton Lords Lair', 'South': 'Bone Storage', 'item': 'Bag o Gold' # Correct linkage to the Bone Storage
'Skeleton Lords Lair': North: 'Huge Skull Door', 'item': 'Skeleton Lord' # villain
'Bone Storage': North: 'Huge Skull Door', 'item': 'Skull Door Key' # New room with the 'Skull Door Key' item
# Define the player's starting position and inventory.
currentroom 'Main Cell'
inventory
# Define the items that the player needs to collect.
itemstocollect Flame Sword', 'AntiMagic Armor', 'Cursed Ring', 'Skull Lantern', 'Bag of Gold', 'Skull Door Key'
def showinstructions:
printSkeleton Lord's Revengence"
printCollect items to win the game, or be trapped with Skeleton Lord for eternity."
printMove commands: go South, go North, go East, go West"
printAdd to Inventory: get 'item name'"
print
def showstatus:
printfYou are in the currentroom
printfInventory: inventory
if 'item' in gamemapcurrentroom:
printfYou see a gamemapcurrentroomitem
print
def getitemitemname:
if 'item' in gamemapcurrentroom and itemname gamemapcurrentroomitem:
inventory.appenditemname
printfYou got the itemname
del gamemapcurrentroomitem
else:
printItem not found in this room!"
def main:
global currentroom # Declare currentroom as global
showinstructions
# Gameplay loop
while True:
showstatus
command inputEnter your move type 'exit' to quit: striplower
# Handle exit command
if command 'exit':
break
# Handle move commands
if command.startswithgo :
direction command.splitcapitalize # Convert the direction to title case
if direction in gamemapcurrentroom:
currentroom gamemapcurrentroomdirection
else:
printYou can't go that way!"
# Handle get item commands
elif command.startswithget :
itemname command.splitcapitalize # Extract the item name and convert to title case
getitemitemname
# Handle invalid commands
else:
printInvalid command. Please try again!"
# Check if the player has won or lost the game
if leninventory lenitemstocollect:
printCongratulations You have collected all items and defeated the Skeleton Lord!"
break
if currentroom 'Skeleton Lords Lair':
printYOU FOOL! I SENTENCE YOU TO OBLITERATION!", You are reduced to ashes instantly with a snap of bony fingers
break
printBetter luck next time, Adventurer!"
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
