Question: class Player ( object ) : def _ _ init _ _ ( self , name, place ) : Create a player

class Player(object): def __init__(self, name, place): """Create a player object.""" self.name = name self.place = place self.backpack =[] def look(self): self.place.look() #RQ2 def go_to(self, direction): """Go to direction if it's among the exits of player's current place. >>> swift= Place('Swift Hall', 'You are at Swift Hall', [],[])>>> bcc = Place('Bearcat Cafe', 'You are at Bearcat Cafe', [],[])>>> swift.add_exits([bcc])>>> bcc.add_exits([swift])>>> me = Player('player', swift)>>> me.go_to('Bearcat Cafe') You are at Bearcat Cafe >>> me.place.name 'Bearcat Cafe' >>> me.go_to('Bearcat Cafe') Can't go to Bearcat Cafe from Bearcat Cafe. Try looking around to see where to go.>>> me.go_to('Swift Hall') You are at Swift Hall """"*** YOUR CODE HERE ***" #RQ3 def talk_to(self, person): """Talk to person if person is at player's current place. >>> robert = Character('Robert', 'Have to run for lecture!')>>> sather_gate = Place('Sather Gate', 'You are at Sather Gate', [robert],[])>>> me = Player('player', sather_gate)>>> me.talk_to(robert) Person has to be a string. >>> me.talk_to('Robert') Robert says: Have to run for lecture! >>> me.talk_to('Albert') Albert is not here. """ if type(person)!= str: print('Person has to be a string.') return None # Replace this line #RQ4 def take(self, thing): """Take a thing if thing is at player's current place >>> hotdog = Thing('Hotdog', 'A hot looking hotdog')>>> bcc = Place('BCC', 'You are at Bearcat Cafe', [],[hotdog])>>> me = Player('Player', bcc)>>> me.backpack []>>> me.take(hotdog) Thing should be a string. >>> me.take('dog') dog is not here. >>> me.take('Hotdog') Player takes the Hotdog >>> me.take('Hotdog') Hotdog is not here. """ if type(thing)!= str: print('Thing should be a string.') return None # Replace this line def check_backpack(self): """Print each item with its description and return a list of item names. >>> cookie = Thing('Cookie', 'A huge cookie')>>> donut = Thing('Donut', 'A huge donut')>>> cupcake = Thing('Cupcake', 'A huge cupcake')>>> bcc = Place('BCC', 'You are at Bearcat Cafe', [],[cookie, donut, cupcake])>>> me = Player('Player', bcc)>>> me.check_backpack() In your backpack: there is nothing. []>>> me.take('Cookie') Player takes the Cookie >>> me.check_backpack() In your backpack: Cookie - A huge cookie ['Cookie']>>> me.take('Donut') Player takes the Donut >>> food = me.check_backpack() In your backpack: Cookie - A huge cookie Donut - A huge donut >>> food ['Cookie', 'Donut']""" print('In your backpack:') if not self.backpack: print(' there is nothing.') else: for item in self.backpack: print('', item.name, '-', item.description) return [item.name for item in self.backpack] class Character(object): def __init__(self, name, message): self.name = name self.message = message def talk(self): return self.message class Thing(object): def __init__(self, name, description): self.name = name self.description = description class Place(object): def __init__(self, name, description, characters, things): self.name = name self.description = description self.characters ={character.name: character for character in characters} self.things ={thing.name: thing for thing in things} self.exits ={} # {'name': (exit, 'description')} def look(self): print('You are currently at '+ self.name +'. You take a look around and see:') print('Characters:') if not self.characters: print(' no one in particular') else: for character in self.characters: print('', character) print('Things:') if not self.things: print(' nothing in particular') else: for thing in self.things.values(): print('', thing.name, '-', thing.description) self.check_exits() def exit_to(self, exit): if type(exit)!= str: print('Exit has to be a string.') return self elif exit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!