def go(self, direction: str) -> Location: dest_info = self.location.destinations.get(direction, None) dest = None print('***', self.location.name, direction, dest_info) while not dest: if isinstance(dest_info, str): dest = game.locations.get(dest_info) elif isinstance(dest_info, tuple): if isinstance(dest_info[0], str): dest = game.locations.get(dest_info[0]) default_dest_info = self.location.destinations.get( 'default', None) if dest_info[0] == 'MESSAGE': Util.print_message(dest_info[1]) if dest_info[2]: if dest_info[2][0] == 'PROPERTY (must not be)': item = game.objects[dest_info[2][1]] if item.prop == dest_info[2][2]: dest_info, dest = default_dest_info, None elif dest_info[2][0] == 'REQUIRED_OBJECT_IN_ROOM': if not (self.location.is_item_present( dest_info[2][1]) or self.has_item(dest_info[2][1])): dest_info, dest = default_dest_info, None else: return else: if dest_info[1][0] == 'PROPERTY (must not be)': item = game.objects[dest_info[1][1]] if item.prop == dest_info[1][2]: dest_info, dest = default_dest_info, None elif dest_info[1][0] == 'REQUIRED_OBJECT': item = game.objects[dest_info[1][1]] if not self.has_item(item.name): dest_info, dest = default_dest_info, None elif dest_info[1][0] == 'PROBABILITY': # TODO replace None with Util.pct(dest_info[1][1]) after test if None: dest_info, dest = default_dest_info, None elif dest_info[1][0] == 'REQUIRED_OBJECT_IN_ROOM': if not (self.location.is_item_present( dest_info[1][1]) or self.has_item(dest_info[1][1])): dest_info, dest = default_dest_info, None else: raise NotImplemented( 'The move is not implemented!') else: break if not dest: Util.color_print('WARN', "You can't go that way.") return if self.location != dest: self.location = dest self.trajectory.append(self.location.name) return self.location
def run(self) -> None: while True: locations[self.player.location.name].print_info( objects['lantern'], self.player) # available_exists = {dest for dir, dest in locations[self.player.location.name].destinations.items()} # direction = input(f"Available exits are:\n{available_exists}\n:").casefold() direction = input(":").casefold() from colorama import Fore, Style print(Fore.YELLOW, direction, Style.RESET_ALL) # remove non-alph from the import and interpret each word what_to_do = [] for d in direction.split(): word = re.sub(r'[^a-zA-Z]', '', d)[:6] if w := Util.get_word_info(word): what_to_do.append(w) if what_to_do: vocab_type, value = what_to_do[0] # if the first word is a TYPE_MOTION, ignore the rest if vocab_type == TYPE_MOTION: self.player.go(value) else: action_vocab = '' item_vocabs = [] for vocab_type, value in what_to_do: if vocab_type == TYPE_ACTION: action_vocab = value elif vocab_type == TYPE_OBJECT: item_vocabs.append(value) if action_vocab and not item_vocabs: getattr(Command, action_vocab)(player=self.player) elif item_vocabs: for item_name in item_vocabs: if action_vocab: getattr(Command, action_vocab)(player=self.player, item=objects[item_name]) # elif vocab_type == TYPE_SPECIAL_CASE: # # special case verb # print(arbitrary_messages[value]) else: print("Please enter a valid input")
def manage_dwarves(self): global dwarf_activation_level loc = self.player.location if not (loc.is_forced() or loc.bitset(3)): for d in self.dwarves: if d.old_loc == loc.name and d.seen: Util.print_message(2) break if loc.is_forced() or loc.bitset(3): loc.print_desc(self.player) elif dwarf_activation_level != 0: if dwarf_activation_level == 1: # WHEN WE ENCOUNTER THE FIRST DWARF, WE KILL 0, 1, OR 2 OF THE 5 DWARVES. # TODO replace `loc.index < 15` with `loc.index < 15 or Util.pct(95)` after test if loc.index < 15: loc.print_desc(self.player) else: dwarf_activation_level = 2 for d in random.sample(self.dwarves, 2): if Util.pct(50): d.loc = None for d in self.dwarves: if d.loc == loc.name: d.old_loc = d.loc d.loc = 'nugget_room' Util.print_message(3) loc.add_item(objects['axe']) loc.print_desc(self.player) else: loc.print_desc(self.player) # print('#6010') elif dwarf_activation_level == 0 and loc.index >= 15: dwarf_activation_level = 1 loc.print_desc(self.player) else: loc.print_desc(self.player)
def print_info(self, lamp, player): # print('----- ', self.name, self.abb_desc_no) if not self.short_description or (self.abb_desc_no % ABBNUM == 0): desc = self.description else: desc = self.short_description if self.is_forced() or not self.is_dark(lamp, player): if player.has_item('bear'): Util.print_message(141) elif game.locations[player.trajectory[-1]].is_dark( lamp, player) and Util.pct(35): Util.print_message(23) # 90 HE'S DEAD. LET'S GET ON WITH IT. return else: desc = 16 if player.has_item('bear'): Util.print_message(141) Util.print_message(desc) desc = None # IF(FORCED(LOC))GOTO 8 # IF(LOC.EQ.33.AND.PCT(25).AND..NOT.CLOSNG)CALL RSPEAK(8) if desc: self.abb_desc_no += 1 Util.color_print('LOC_INFO', desc)
def print_message(self, prop: int = None) -> None: prop_msg = prop if prop else self.prop if (msg := self.messages[prop_msg]) != '>$<': Util.color_print('ITEM_INFO', msg)