Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED HELP CORRECTING THIS CODE in python. I have to be able to move rooms to room, get the items and add it to

I NEED HELP CORRECTING THIS CODE in python. I have to be able to move rooms to room, get the items and add it to inventory, win or lose the game...The first room "main hall" doesn't have no item

#A dictionary linking a room to other rooms #and linking one item for each room except the Start room (Main Hall) and the room containing the villain rooms = { 'Main Hall' : { 'South' : 'Living Room', 'North': 'Garden', 'East' : 'Kitchen', 'West' : 'Attic'}, 'Living Room' : { 'North' : 'Great Hall', 'East' : 'Office', 'Item' : 'Flashlight' }, 'Office' : { 'West' : 'Living Room', 'Item' : 'Gun' }, 'Basement' : { 'South' : 'Kitchen', 'Item' : 'Ogre' }, 'Kitchen' : {'West' : 'Main Hall', 'North' : 'Basement', 'Item' : 'Water' }, 'Garden' : {'South' : 'Main Hall', 'East': 'Workout Room', 'Item': ' Rock' }, 'Attic' : {'East' : 'Main Hall', 'Item': ' knife' }, 'Workout Room' : {'West' : 'Garden', 'Item': 'Mace' } } state = 'Main Hall' # function def get_new_state(state, direction): new_state = state # declaraing for i in rooms: # loop if i == state: # if if direction in rooms[i]: # if new_state=rooms[i][direction] #assigning new_state return new_state # return def get_item(state): print(state) return rooms[state]['Item'] #returning Item value #function showing the goal of the game and move commands def show_instructions(): #print a main menu and the commands print("Ogre in the Basement! Text-Based Adventure Game") print("Collect 6 items to win the game or be eaten by the Ogre.") print("Move commands: go South, go North, go East, go West") print("Add to Inventory: get 'item name'") show_instructions() #calling function inventory=[] while (1): # gameplay loop print('You are in ', state) # printing state print('Inventory:',inventory) #printing inventory item=get_item(state) #calling get_item function print('You see a',item) #print if item=='Ogre': #if print('NOM NOM...GAME OVER!') exit(0) direction = input('Enter your move: ') # asking user if (direction == 'go East' or direction == 'go West' or direction == 'go North' or direction == 'go South'): # if direction=direction[3:] new_state = get_new_state(state, direction) # calling function if new_state == state: # if print('The room has wall in that direction enter other direction!') # print else: state = new_state # changing state value to new_state elif direction==str('get '+item): #if if item in inventory: #if item already present in inventory print('Item already taken go to another room!!') else: inventory.append(item) #appending else: print('Invalid direction!!') # print if len(inventory)==6: print('Congratulations! You have collected all items and defeated the Ogre!') #print exit(0) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions