Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
It's a text based game and I just need help untangling my code. The code I have is complete but things are happening before or
It's a text based game and I just need help untangling my code. The code I have is complete but things are happening before or after they are supposed to. Starting in the living room there is no item so you should not be asked to pickup anything, but it does ask. And when you enter a room with an item, it should say "you see a ____, pick it up?" first. Instead it asks you to pickup the item after you have typed a new direction. Should be a simple fix, however I have been staring at this code for weeks and I'm burned out. Please help!
# Game Instructions print('Welcome to the Charlie Brown Text Based Adventure Game!!!') print('Your mission is to finally kick the football before Lucy') print('pulls it away. Gather all your supplies before meeting') print('Lucy outside to win!') print('Move by typing: North, South, East, West') print("Pickup items by typing 'yes' or 'no'") print("To exit type 'Exit'") rooms = { 'The Living Room': {'South': 'The Study', 'North': 'The Garage', 'West': 'The Porch', 'East': 'The Kitchen'}, 'The Study': {'North': 'The Living Room', 'East': 'Your Bedroom'}, 'Your Bedroom': {'West': 'The Study'}, 'The Porch': {'East': 'The Living Room'}, 'The Garage': {'South': 'The Living Room', 'East': 'a Football Field'}, 'The Basement': {'South': 'The Kitchen'}, 'The Kitchen': {'North': 'The Basement', 'West': 'The Living Room'} } items = { 'The Living Room': '', 'The Study': 'a Book,How to Kick a Football', 'Your Bedroom': 'a Record, Schroeder Plays Beethoven', 'The Porch': 'a Helmet', 'The Garage': 'a Football', 'The Basement': 'a Pair of Shoulder Pads', 'The Kitchen': 'Bag of Peanuts', 'a Football Field': 'Lucy' } status = 'The Living Room' inventory = [] def get_new_status(status, direction): new_status = status for i in rooms: if i == status: if direction in rooms[i]: new_status = rooms[i][direction] return new_status # return while 1: # gameplay loop print('You are in', status) if status == 'a Football Field': print('You see Lucy holding the football', end='') for i in range(50): for j in range(1000000): pass print(".", end='', flush=True) print() if len(inventory) == 6: print('You kicked the football! Way to go Charlie Brown!!') else: print('AAAHHGG, you missed again you blockhead!!') break # Take input and capitalize it direction = input('What should we do? ') direction = direction.capitalize() # Condition to pickup item if items[status] != '': print("You see", items[status]) print("You've got", inventory) if direction in rooms[status]: pickup = input("Do you want to pickup item? yes/no ") pickup = pickup.capitalize() if pickup == 'Yes': if items[status] != '': if items[status] not in inventory: inventory.append(items[status]) if direction == 'Exit': print("See ya later Charlie Brown") exit(0) if direction == 'East' or direction == 'West' or direction == 'North' or direction == 'South': new_status = get_new_status(status, direction) if new_status == status: print("You can't go that way you blockhead!!") else: status = new_status else: print("You can't go that way you blockhead!!")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started