def exec(self, context: GameContext): room = context.get_current_room() if self.name in room._exits: context.current_room = room._exits['zapad'] context.get_current_room().show() context.history.append(self.name) else: print('Tam sa nedá ísť.')
def exec(self, context:GameContext): """ Enter the room on east from current room. If there is no exit to the east, then no change. The new room will be returned from the function. :param world: the world the player is in :param current_room: the name of current room player is in :return: the name of new room on the east """ room = context.get_current_room() if self.name in room._exits: context.current_room = room._exits['vychod'] context.get_current_room().show() context.history.append(self.name) else: print('Tam sa nedá ísť.')
def exec(self, context: GameContext): try: item = context.backpack.remove_item(self.params) room = context.get_current_room() room['items'].append(item) print(f'{item.name} si vyložil z batohu.') context.history.append(f'{self.name} {self.params}') except ItemNotFoundException: print('Taký predmet u seba nemáš.')
def main(): # inicializacia hry context = GameContext() context.init_game() context.backpack = Backpack(2) context.backpack.add_item(Whip()) context.world = world commands = [ About(), LookAround(), Inventory(), Quit(), North(), South(), East(), West(), Down(), # Up(), UseItem(), DropItem(), TakeItem(), ExamineItem(), Save() ] commands.append(Commands(commands)) commands.append(Help(commands)) parser = Parser(commands) print("Indiana Jones") context.get_current_room().show() while context.state == 'playing': line = input('> ') try: command = parser.parse(line) command.exec(context) except UnknownCommandException: print('Taký príkaz nepoznám.')
def exec(self, context: GameContext): room = context.get_current_room() items = room['items'] + context.backpack for item in items: if item.name == self.params: if not isinstance(item, UsableMixin): print('Tento predmet sa nedá použiť') return context.history.append(f'{self.name} {item.name}') item.use(context) print('Taký predmet tu nikde nevidím.')
def exec(self, context: GameContext): room = context.get_current_room() for item in room['items']: if item.name == self.params: if not isinstance(item, MovableMixin): print('Tento predmet sa nedá vziať.') elif len(context.backpack) >= 1: print('Batoh je plný.') else: context.backpack.add_item(item) room['items'].remove(item) print(f'{item.name} si vložil do batohu.') context.history.append('f{self.name} {item.name}') break # return else: print('Taký predmet tu nikde nevidím.')
def exec(self, context: GameContext): name = self.params # search in backpack if name in context.backpack: print(context.backpack[name].description) return room = context.get_current_room() items = room['items'] for item in items: if item.name == self.params: print(item.description) return print('Taký predmet tu nikde nevidím.')
def exec(self, context: GameContext): context.get_current_room().show()