def act(self, obj): ''' The first time creates in the chest of random things, depending on the rarity of the chest. Open it. ''' if not self.open: self.generator() self.open = True self.des = colored('c', 'yellow') idx = 0 clear() print(f'\n{self.rarity}\n') sleep(0.5) while True: item, idx, lst, esc = choice_of(obj.backpack, self.items, idx) if esc: break if lst == 'sec': obj.add_to_inventory(item) self.items[idx] = None elif None in self.items: self.items[self.items.index(None)] = item obj.backpack[idx] = None
def link(update, context): user_id = update.message.chat.id args = context.args try: if len(args) == 0 or (len(args) == 1 and args[0] in ["list", "show"]): message = links.show_list(user_id) elif args[0] == "add": name, url = parse_add_link(args[1:]) message = links.add(user_id, name, url) elif len(args) == 2 and args[0] == "remove": message = links.remove(user_id, args[1]) elif len(args) == 1 and args[0] == "clear": message = links.clear(user_id) elif len(args) == 1: message = links.get(user_id, args[0]) else: raise ValueError("I couldn't understand you :(") context.bot.send_message( chat_id=update.effective_chat.id, text=message, parse_mode=telegram.ParseMode.MARKDOWN, ) except ValueError as e: context.bot.send_message(chat_id=update.effective_chat.id, text=str(e))
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
import Dungeon ID = uuid4() player = create_player(str(ID)) 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
def generator(self): ''' Create features on the map ''' links.ses_area = self clear() print(self.name) print('\ncreate a big dummy') self.map = Map([ Map([ Map([NewInt() for elm in range(self.ELMS)]) for row in range(self.ROWS) ]) for lay in range(self.LAYS) ]) self.chank_map = Map([ Map([ Map([ Chank(lay, row, elm, self, length=self.LEN_OF_CHANK) for elm in range(-int(self.ELMS / (self.LEN_OF_CHANK * 2)), int(self.ELMS / (self.LEN_OF_CHANK * 2))) ]) for row in range(-int(self.ROWS / (self.LEN_OF_CHANK * 2)), int(self.ROWS / (self.LEN_OF_CHANK * 2))) ]) for lay in range(-int(self.LAYS / (self.LEN_OF_CHANK * 2)), int(self.LAYS / (self.LEN_OF_CHANK * 2))) ]) self.vector_map = Map([ Map([[] for elm in range(ceil(self.ELMS / self.LEN_OF_CHANK))]) for row in range(ceil(self.ROWS / self.LEN_OF_CHANK)) ]) map_ = Map([ Map([ None for elm in range(ceil(self.ELMS / self.LEN_OF_CHANK + 2)) ]) for row in range(ceil(self.ROWS / self.LEN_OF_CHANK + 2)) ]) vector_row = -ceil(len(self.vector_map) / 2) for row in range(-map_.RADIUS, map_.RADIUS): vector_elm = -ceil(len(self.vector_map[0]) / 2) for elm in range(-map_[0].RADIUS, map_[0].RADIUS): map_[row][elm] = Vector(vector_elm, vector_row) vector_elm += 1 vector_row += 1 vector_row = -ceil(len(self.vector_map) / 2) + 1 for row in range(-map_.RADIUS, map_.RADIUS - 1): vector_elm = -ceil(len(self.vector_map[0]) / 2) + 1 for elm in range(-map_[0].RADIUS, map_[0].RADIUS - 1): vector_list = self.vector_map[vector_row][vector_elm] vector_list.append(map_[row][elm]) vector_list.append(map_[row][elm + 1]) vector_list.append(map_[row + 1][elm + 1]) vector_list.append(map_[row + 1][elm]) vector_elm += 1 vector_row += 1 del map_ chank = self.chank_map[0][0][0] chank.generator() chank.msg() clear() print(self.name) print('\ncreate the boundaries of the world') for lay in self.map: for row in lay: row[-int(len(self.map) / 2)] = Wall() row[int(len(self.map) / 2) - 1] = Wall() for elm in range(-int(len(self.map[0][0]) / 2), int(len(self.map[0][0]) / 2) - 1): lay[-int(len(self.map) / 2)][elm] = Wall() lay[int(len(self.map) / 2) - 5][elm] = Wall() clear() print(self.name) print('\ncreate the final room')
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()