May assignment is asking me to build a program in PyChart that makes it possible for the player to visit each room and select the items in that room to fight a giant at the end. In order to win the game you have to collect all of the items from all of the rooms. When I run the code this is the result: Text Adventure Game  *************************** Welcome to the Giant text game, Collect all of the items to defeat the Giant! To move: South, North, East, West To get items: get ’item name’  *************************** You are in the Basement Item:   You see Armor Enter a move:  When I input the direction to go north the next result comes up correctly. However when I tell it to get and item (which is the command written into the code I get this: Invalid direction! Please enter a valid direction.  *************************** You are in the Basement Item:   You see Armor Enter a move:  This is my complete program code, can someone please tell me what I am doing wrong. #Functions showing goal of game and move commands def show_instructions(): #print a main menu and the commands print(" Welcome to the Giant Text Game") print("Collect 7 items to win the game, or be eaten by the giant.") print("Move commands: go South, go North, go East, go West") print("Add to Inventory: get 'item name'") #A dictionary to link a room to other rooms rooms = { 'Basement': {'West': 'Entertainment Room', 'North': 'Living Room', 'East': 'Bedroom', 'North': 'Bathroom', 'South': 'Bedroom', 'West': 'Living Room', 'West': 'Study', 'East': 'Living Room', 'North': 'Guest Room', 'East': 'Attic'}, 'Basement': {'West': 'Entertainment Room', 'item': 'Armor'}, 'Entertainment Room': {'North': 'Living Room', 'item': 'Shield'}, 'Living Room': {'East': 'Bedroom', 'item': 'Potion'}, 'Bedroom': {'North': 'Bathroom', 'item': 'Sword'}, 'Bathroom': {'South': 'Bedroom', 'West': 'Living Room', 'West': 'Study', 'item': 'Elixir'}, 'Study': {'East': 'Living Room', 'North': 'Guest Room', 'item': 'Bow & Arrow'}, 'Guest Room': {'East': 'Attic', 'item': 'Giant'} #villian } room = 'Basement' # Function for getting location def get_new_room(room, direction): # Set new location new_room = room # Loop and if valid direction # assign new room for i in rooms: if i == room: if direction in rooms[room]: new_room = rooms[room][direction] # Return new location return new_room def get_item(room): items = { 'Bedroom': 'Potion', 'Entertainment Room': 'Armor', 'Living Room': 'Shield', 'Study': 'Elixir', 'Bathroom': 'Sword', 'Guest Room': 'Bow & Arrow', 'Attic': 'Giant', 'Basement': 'Empty', } return items[room] def instructions(): # Output main menu and instructions print('Text Adventure Game\n' ' ***************************\n' 'Welcome to the Giant text game, ' 'Collect all of the items to defeat the Giant!\n' 'To move: South, North, East, West\n' 'To get items: get ’item name’') # call instructions function instructions() # set blank inventory item = [] # Start gameplay loop while (1): # Output current position and inventory print(' ***************************') print('You are in the', room) print('Item: ', '') if 'item' in rooms[room]: print('You see ' + rooms[room]['item']) if len(item) != 6 and 'item' == 'Giant!': print("If you come at the Giant, you best not miss...YOU LOSE!") exit(0) if len(item) == 6 and 'item' == 'Giant!': print("Congratulations! You have defeated the Giant!") exit(0) # Prompt user to enter direction direction = input('Enter a move: \n'). lower() directions = ['North', 'East', 'South', 'West'] directions = ['get Armor', 'get Shield', 'get Potion', 'get Elixir', 'get Bow & Arrow', 'get Sword'] # Initialize loop to check for valid movement between rooms if direction == 'East' or direction == 'West' or direction == 'North' or direction == 'South': new_room = get_new_room(room, direction.capitalize()) # If invalid direction, prompt for new direction if new_room == room: print('There is no doorway, please enter a new direction!') # if valid direction change room else: room = new_room elif direction == str('Get' + 'item'): if rooms[room]['item'] in inventory: print('You have already retrieved this item!! Pick another direction!') else: inventory.append(rooms[room]['item']) # If invalid command, prompt user to enter new direction else: print('Invalid direction! Please enter a valid direction.')

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question

May assignment is asking me to build a program in PyChart that makes it possible for the player to visit each room and select the items in that room to fight a giant at the end. In order to win the game you have to collect all of the items from all of the rooms. When I run the code this is the result:

Text Adventure Game
 ***************************
Welcome to the Giant text game, Collect all of the items to defeat the Giant!
To move: South, North, East, West
To get items: get ’item name’
 ***************************
You are in the Basement
Item:  
You see Armor
Enter a move: 

When I input the direction to go north the next result comes up correctly. However when I tell it to get and item (which is the command written into the code I get this:

Invalid direction! Please enter a valid direction.
 ***************************
You are in the Basement
Item:  
You see Armor
Enter a move: 

This is my complete program code, can someone please tell me what I am doing wrong.

#Functions showing goal of game and move commands



def show_instructions():
#print a main menu and the commands
print(" Welcome to the Giant Text Game")
print("Collect 7 items to win the game, or be eaten by the giant.")
print("Move commands: go South, go North, go East, go West")
print("Add to Inventory: get 'item name'")

#A dictionary to link a room to other rooms
rooms = {
'Basement': {'West': 'Entertainment Room', 'North': 'Living Room', 'East': 'Bedroom', 'North': 'Bathroom', 'South': 'Bedroom', 'West': 'Living Room', 'West': 'Study', 'East': 'Living Room', 'North': 'Guest Room', 'East': 'Attic'},
'Basement': {'West': 'Entertainment Room', 'item': 'Armor'},
'Entertainment Room': {'North': 'Living Room', 'item': 'Shield'},
'Living Room': {'East': 'Bedroom', 'item': 'Potion'},
'Bedroom': {'North': 'Bathroom', 'item': 'Sword'},
'Bathroom': {'South': 'Bedroom', 'West': 'Living Room', 'West': 'Study', 'item': 'Elixir'},
'Study': {'East': 'Living Room', 'North': 'Guest Room', 'item': 'Bow & Arrow'},
'Guest Room': {'East': 'Attic', 'item': 'Giant'} #villian
}

room = 'Basement'
# Function for getting location
def get_new_room(room, direction):
# Set new location
new_room = room
# Loop and if valid direction
# assign new room
for i in rooms:
if i == room:
if direction in rooms[room]:
new_room = rooms[room][direction]
# Return new location
return new_room

def get_item(room):
items = {
'Bedroom': 'Potion',
'Entertainment Room': 'Armor',
'Living Room': 'Shield',
'Study': 'Elixir',
'Bathroom': 'Sword',
'Guest Room': 'Bow & Arrow',
'Attic': 'Giant',
'Basement': 'Empty',

}
return items[room]

def instructions():
# Output main menu and instructions
print('Text Adventure Game\n'
' ***************************\n'
'Welcome to the Giant text game, '
'Collect all of the items to defeat the Giant!\n'
'To move: South, North, East, West\n'
'To get items: get ’item name’')
# call instructions function
instructions()
# set blank inventory
item = []

# Start gameplay loop
while (1):
# Output current position and inventory
print(' ***************************')
print('You are in the', room)
print('Item: ', '')
if 'item' in rooms[room]:
print('You see ' + rooms[room]['item'])
if len(item) != 6 and 'item' == 'Giant!':
print("If you come at the Giant, you best not miss...YOU LOSE!")
exit(0)
if len(item) == 6 and 'item' == 'Giant!':
print("Congratulations! You have defeated the Giant!")
exit(0)
# Prompt user to enter direction
direction = input('Enter a move: \n'). lower()
directions = ['North', 'East', 'South', 'West']
directions = ['get Armor', 'get Shield', 'get Potion', 'get Elixir', 'get Bow & Arrow', 'get Sword']
# Initialize loop to check for valid movement between rooms
if direction == 'East' or direction == 'West' or direction == 'North' or direction == 'South':
new_room = get_new_room(room, direction.capitalize())
# If invalid direction, prompt for new direction
if new_room == room:
print('There is no doorway, please enter a new direction!')
# if valid direction change room
else:
room = new_room
elif direction == str('Get' + 'item'):
if rooms[room]['item'] in inventory:
print('You have already retrieved this item!! Pick another direction!')
else:
inventory.append(rooms[room]['item'])
# If invalid command, prompt user to enter new direction
else:
print('Invalid direction! Please enter a valid direction.')

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning