d help fixing this code. I can't collect all the items, plus I need to add a commend to exit the game when users enter "EXIT" def showinstructions(): # Game instruction print("Snow Cave adventure Game ======== Collect All 6 Items To Win. ") print("A GIANT SNOWBALL Is Waiting For You! ") print("Just Go South, go North, go East, go West, Exit. ") print("Get a snow Cone. Get some Wine. Get an Icicle. Get Glasses. ") print("Get Medals. Get Long Underwear. Meet the Giant SNOWBALL. ") def showstatus(currentroom, inventory, rooms):
I need help fixing this code.
I can't collect all the items, plus I need to add a commend to exit the game when users enter "EXIT"
def showinstructions(): # Game instruction
print("Snow Cave adventure Game ======== Collect All 6 Items To Win. ")
print("A GIANT SNOWBALL Is Waiting For You! ")
print("Just Go South, go North, go East, go West, Exit. ")
print("Get a snow Cone. Get some Wine. Get an Icicle. Get Glasses. ")
print("Get Medals. Get Long Underwear. Meet the Giant SNOWBALL. ")
def showstatus(currentroom, inventory, rooms):
print(' ----------------------------') # Just for a new line after each move
print('You are in the ' + currentroom)
print('Inventory: ' + str(inventory))
if "item" in rooms[currentroom]:
print('You have seen the ' + rooms[currentroom]['item'])
def main():
inventory = []
# rooms dictionary
rooms = {
'Ice Hall': {'South': 'TrophyRoom', 'North': 'IcicleRoom', 'East': 'SittingRoom', 'West': 'SnowRoom'},
'TrophyRoom': {'North': 'Ice Hall', 'East': 'Dungeon', 'item': 'Medals'},
'Dungeon': {'West': 'TrophyRoom', 'item': 'Wine'},
'IcicleRoom': {'South': 'Ice Hall', 'East': 'ConeRoom', 'item': 'Icicle'},
'ConeRoom': {'West': 'IcicleRoom', 'item': 'Snow Cone'},
'SittingRoom': {'West': 'Ice Hall', 'North': 'Bedroom', 'item': 'Long Underwear'},
'Bedroom': {'South': 'SittingRoom', 'item': 'Glasses'},
'SnowRoom': {'East': 'Ice Hall', 'item': 'Giant SnowBall'}
}
# Initially user will be present in the main room or the Ice Hall
currentroom = 'Ice Hall'
showinstructions()
while True:
showstatus(currentroom, inventory, rooms)
if 'item' in rooms[currentroom]:
if rooms[currentroom]['item'] == 'Giant SnowBall': # User will get frozen and the game will end
print('You have been Frozen!!!.... GAME OVER!')
print('Thank you for playing the game! ')
print('BYE! BYE! ')
break
if len(inventory) == 6:
print('Congratulation! You have collected all items and now won the game!')
print('Get outside now and warm up.')
break
print(' ------------------------------') # Just for a new line after break
print('Enter your move: ') # Prompting the user to enter an input
move = ''
while move == '':
move = input()
move = move.split()
if len(move) != 2:
print('Invalid input!')
continue
if move[0] == 'go':
if move[1] in rooms[currentroom]:
currentroom = rooms[currentroom][move[1]] # main logic part of the
else:
print("You can't go that way!")
elif move[0] == 'get':
if "item" in rooms[currentroom] and move[1] in rooms[currentroom]['item']:
inventory += [move[1]]
print(move[1] + ' got!')
del rooms[currentroom]['item']
else:
print("Can't get" + move[1] + "!")
else:
print("Invalid move!")
if __name__ == '__main__':
main()
Step by step
Solved in 2 steps