def get_hit(self, dmg): if randint(1, 100) in range(self.chance['dodge Atk']) and self.armor < dmg: self.hlt -= dmg - self.armor print(f'get damage: {dmg - self.armor}') smart_input({Key.enter: None}) else: print('miss') smart_input({Key.enter: None})
def act(self, obj): ''' Open it ''' for count in range(len(list(self.inv))): count += 1 if self.inventory[i]: print(i, self.inventory[i].name) else: print(i, 'None') choices = [(str(num), num) for num in range(1, len(list(self.inventory)) + 1)] choices.append((Key.esc, 'esc')) choices.append(('e', 'esc')) choice = smart_input(choices) if not choice == 'esc': self.object.add_to_inventory(self.inventory[int(choice)]) self.inventory[int(choice)] = None if item: print() try: print(item.name) except AttributeError: pass try: print(item.type) except AttributeError: pass try: print(item.rarity) except AttributeError: pass try: print(item.desc) except AttributeError: pass else: print('None') print('\nGet?') choices = {Key.enter: 'yes', Key.esc: 'no'} second_choice = smart_input(choices) if second_choice == 'yes': obj.add_to_inventory([item()]) self.items_[choice] = None
def open_inventory(self): ''' Shows the contents of the inventory, allows the player to view the data on the desired item, as well as to use this item ''' idx = 0 slot= None while True: item, idx, lst, esc = choice_of(self.backpack, idx=idx, slot=slot, obj=self, inv=True) self.check() if esc: break choices = {Key.enter: True, Key.esc: False} use = smart_input(choices) if use: if type(item) is list: item[0].using(self) elif item: item.using(self) elif self.select: self.select.stop_using(self)
def turn(avatar): if avatar.choice: avatar.check() choice = avatar.choice effect() if choice == 'esc': links.esc = True elif choice == 'skills': avatar.skill_tree() elif choice == 'inv': avatar.open_inventory() elif not links.res: if choice in ['North', 'East', 'South', 'West', 'up', 'down']: distributor(avatar, choice, 'mov') else: distributor( avatar, smart_input({ Key.up: 'North', Key.right: 'East', Key.down: 'South', Key.left: 'West', Key.space: 'up', Key.ctrl_l: 'down' }), choice) avatar.check() else: links.res = False avatar.check()
def act(self, obj): index = 0 while True: system('cls') print('Здравствуй, одинокий путник! С чем ты ко мне пожаловал?') questions = ['Что у тебя есть на продажу?', 'Есть ли для меня задание?'] for qun in questions: if index == questions.index(qun): mark = ' <' else: mark = str() print(f'{qun}{mark}') choices = {Key.up: 'up', Key.down: 'down', Key.enter: 'select', Key.esc: 'esc'} choice = smart_input(choices) if choice == 'esc': break elif choice == 'up': if index > 0: index -= 1 elif choice == 'down': if index < len(questions)-1: index += 1 elif choice == 'select': if index == 0: pass
def skill_tree(self, idx=False): skl_nams = ['Atk', 'MAtk', 'Agi', 'Vit', 'Int', 'Dcs', 'Luc'] skls = [self.Atk, self.MAtk, self.Agi, self.Vit, self.Int, self.Dcs, self.Luc] count = 0 for skl in skl_nams: dub_dot = ': ' if len(skl) == 3 else ': ' mark = ' <' if count == idx else '' print(f'{skl}{dub_dot}{skls[skl_nams.index(skl)]}{mark}') count += 1 if not idx: smart_input({Key.enter: None})
def act(self, obj): self.recepts = [] index = len(obj.backpack) + 1 while True: obj.check() clear() obj.print_inventory(index, prints=self.print_recepts( index - len(obj.backpack) - 1, obj)) choices = { Key.up: 'up', Key.down: 'down', Key.left: 'left', Key.right: 'right', Key.enter: 'select', Key.esc: 'esc' } choice = smart_input(choices) if choice == 'esc': break elif choice == 'up': if len(obj.backpack) + 1 < index: index -= 1 elif choice == 'down': if index < len(obj.backpack) + len(self.recepts): index += 1 elif choice == 'select': selected_recept = self.recepts[index - len(obj.backpack) - 1] chk = True for key in selected_recept.keys(): try: if not key in ('place', 'result'): if self.resources_in_backpack[ key] < selected_recept[key]: chk = False except KeyError: chk = False if chk: for resource in selected_recept.keys(): var = True for slot in obj.backpack: if type(slot) is list and var: if len(slot) > 0: if type(slot[0]) == resource: for _ in range( selected_recept[resource]): del slot[0] var = False break obj.add_to_inventory(selected_recept['result']) else: print('\nyou don\'t have enough resources') sleep(0.8)
def choice_of(items, items2=False, idx=0, slot=None, obj=None, inv=False, coast=False): if inv: clothes = ['rings', 'shoes', 'feet', 'wings', 'torso', 'head'] if obj.select: clothes.append('select') while True: clear() for string in gen_strings(items, idx, items2=items2, obj=obj, inv=inv, slot=slot, coast=coast): print(string) choices = { Key.up: 'up', Key.down: 'down', Key.left: 'left', Key.right: 'right', Key.shift_r: 'details', Key.enter: 'select', Key.esc: 'esc' } choice = smart_input(choices) if choice == 'esc': return None, None, None, True elif choice == 'details': tmp = items[idx] if idx < len(items) else items2[idx - len(items)] item = tmp[0] if type(tmp) is list else tmp print() if item: item.print_details() smart_input({ Key.enter: None, Key.esc: None, Key.shift_r: None }) continue if not inv: if choice == 'up': if idx == 0: idx = len(items) - 1 elif idx == len(items): idx = len(items) + len(items2) - 1 else: idx -= 1 elif choice == 'down': if idx == len(items) - 1: idx = 0 elif items2: if idx == len(items) + len(items2) - 1: idx = len(items) else: idx += 1 else: idx += 1 elif choice == 'left' and items2: if not idx - len(items) < 0: idx -= len(items) elif choice == 'right' and items2: if idx > len(items2): idx = len(items) + len(items2) - 1 elif idx < len(items): idx += len(items) elif choice == 'select': if idx < len(items): item = items[idx] lst = 'fst' else: idx -= len(items) item = items2[idx] lst = 'sec' return item, idx, lst, False else: if choice == 'up': if ( obj.select and slot == 'select') or \ (not obj.select and slot == 'head'): idx = len(items) - 1 slot = None elif idx < 1: idx -= 1 slot = clothes[abs(idx) - 1] else: idx -= 1 solt = None elif choice == 'down': if idx < -1: idx += 1 slot = clothes[abs(idx) - 1] elif idx == len(items) - 1: idx = -len(clothes) + 1 slot = clothes[abs(idx)] else: idx += 1 slot = None elif choice == 'select': if idx > 0: item = items[idx] return item, idx, slot, False
def get_hit(self, dmg, obj): print('Taked domage:', dmg) smart_input({Key.enter: None})
print(player.area.name) var = False fall_var2 = False while True: if esc: clear() print('exit?') choices = {Key.enter: True, Key.esc: False} choice = smart_input(choices) if choice: break links.esc = False if var: print(player.area.name) sleep(1) var = False clear() player.stat() print(player.lay, player.row, player.elm) print()
def act(self, arg): ''' Shows the inscription on the plate ''' print(self.text + '\n') smart_input({Key.enter: None})
def act(self, obj): slot = 1 while True: obj.check() clear() obj.print_inventory(slot, prints=self.gen_slots(slot, obj)) print() choices = { Key.up: 'up', Key.down: 'down', Key.left: 'left', Key.right: 'right', Key.enter: 'select', Key.esc: 'esc' } choice = smart_input(choices) if choice == 'esc': break elif choice == 'up': if 1 < slot: slot -= 1 elif choice == 'down': if slot < len(obj.backpack) + len(self.slots): slot += 1 elif choice == 'left': if slot > len(obj.backpack): slot -= len(obj.backpack) elif choice == 'right': if slot < len(obj.backpack): if slot > len(self.slots): slot = len(obj.backpack) + len(self.slots) else: slot += len(obj.backpack) elif choice == 'select': if slot - 1 in range(len(obj.backpack)): item = obj.backpack[slot - 1] if type(item) is list: if isinstance(item[0], Resource): lenght = len(item) - 1 for index in range(len(item)): item[lenght - index].remelting( self, obj, slot - 1) elif slot < len(self.slots) + len(obj.backpack): item = self.slots[slot - len(obj.backpack) - 1] if item: obj.add_to_inventory(item) self.slots[self.slots.index(item)] = []
def skill_up(self): clear() skl_nams = ['Atk', 'MAtk', 'Agi', 'Vit', 'Int', 'Dcs', 'Luc'] skls = [self.Atk, self.MAtk, self.Agi, self.Vit, self.Int, self.Dcs, self.Luc] idx = 0 while self.Skill_points > 0: print(f'Skill points: {self.Skill_points}') self.skill_tree(idx) choices = {Key.up: 'up', Key.down: 'down', Key.enter: 'select', Key.esc: 'esc'} choice = smart_input(choices) if choice == 'esc': break elif choice == 'up': if idx > 0: idx -= 1 elif choice == 'down': if idx < len(skl_nams)-1: idx += 1 elif choice == 'select': choice = skl_nams[idx] if choice == 'Atk': self.Atk += 1 if self.Atk % 10 == 0: self.mid_dmg += 20 elif choice == 'MAtk': self.MAtk += 1 self.mid_m_dmg += 100 elif choice == 'Agi': self.Agi += 1 elif choice == 'Vit': self.Vit += 1 if self.Vit % 10 == 0: self.hlt += 10 elif choice == 'Int': self.Int += 1 if self.Int % 10 == 0: self.mid_m_dmg += 5 elif choice == 'Dcs': self.Dcs += 1 elif choice == 'Luc': self.Luc += 1 self.Skill_points -= 1 clear() clear() self.skill_tree() clear()
def choice_item(self, obj): index = 1 while True: clear() obj.print_inventory(index, prints=self.print_items(index, obj)) choices = {Key.up: 'up', Key.down: 'down', Key.left: 'left', Key.right: 'right', Key.enter: 'select', Key.esc: 'esc'} choice = smart_input(choices) if choice == 'esc': break elif choice == 'up': if 1 < index and not index == len(obj.backpack)+1: index -= 1 elif choice == 'down': if index < len(obj.backpack) + len(self.items) and not index == len(obj.backpack): index += 1 elif choice == 'left': if index > len(obj.backpack): index -= len(obj.backpack) elif choice == 'right': if index < len(obj.backpack): if index > len(self.items): index = len(obj.backpack) + len(self.items) else: index += len(obj.backpack) elif choice == 'select': if index > len(obj.backpack)-1: item = self.items[index-len(obj.backpack)-1] if type(item) is list: print() item[0].print_details() elif item: print() item.print_details() else: print('\nNone') continue print('\nGet?') choices = {Key.enter: True, Key.esc: False} answer = smart_input(choices) if answer: obj.add_to_inventory(item) self.items[index-len(obj.backpack)-1] = None else: item = obj.backpack[index-1] if None in self.items: self.items[self.items.index(None)] = item obj.backpack[index-1] = None obj.gold += item.cost