コード例 #1
0
 def select_target(self):
     """ Generates a Menu that asks user to select hero
         or enemy attribute and returns choice.
     """
     print_centre("Select target:\n")
     target_menu = Menu.from_list([self.hero, self.enemy])
     target = target_menu.handle_options()
     return target
コード例 #2
0
ファイル: inventory.py プロジェクト: superDross/HonestQuest
 def _check_space(self):
     """ Mark the Inventory as full or not full."""
     if len(self) + 1 <= self.limit:
         self.full = False
     else:
         self.full = True
         print_centre("Inventory limit reached.")
         common.sleep()
コード例 #3
0
    def attack(self, target):
        """ Basic physical attack.

        Args:
            target (Character): object to deduct hp from.
        """
        print_centre("\n{} attacks {}!".format(self.name, target.name))
        target.alter_stat("hp", self.st, "-")
コード例 #4
0
 def transfer_gold_exp(self):
     """ Transfer gold and exp from enemy to hero if enemy is dead."""
     if self.enemy.dead:
         msg = "{} recieved {} exp and {} gold!"
         msg = msg.format(self.hero.name, self.enemy.exp, self.enemy.gold)
         print_centre(msg)
         self.hero.exp += self.enemy.exp
         self.hero.gold += self.enemy.gold
         common.sleep()
コード例 #5
0
    def sell(self, item):
        """ Removes the item from the heros inventory and adds
            the sell price of the item to the players sell attr.

        Args:
            item (Item): item to remove.
        """
        self.hero.inventory.remove_item(item.name)
        self.hero.gold += item.sell
        print_centre("Thank you for selling your {} to me!".format(item.name))
        common.sleep()
コード例 #6
0
ファイル: magic.py プロジェクト: superDross/HonestQuest
 def _reduce_mp(self):
     """ Lower _character mp by a given value."""
     if self._character.mp >= self.mp_cost:
         self._character.mp -= self.mp_cost
         print_centre("{} uses {}!".format(self._character.name,
                                           self.att_name))
         return True
     elif self._character.mp < self.mp_cost:
         print_centre("You don't have enough mp to use {}.\n".format(
             self.att_name))
         return False
コード例 #7
0
 def handle_options(self):
     """ Extract and execute a method from self.options."""
     try:
         print_centre(self.choices)
         choice = input(">> ")
         item = self.options[choice]
         return item
     except KeyError:
         msg = "{} is not a valid choice. Try again.\n"
         print_centre(msg.format(choice))
         sleep()
         return self.handle_options()
コード例 #8
0
 def _determine_new_magic(self, before_mglv):
     """ Communicate new spell learned after leveling up.
     Args:
         before_mglv (HeroMagic): magic class before level up.
     """
     if type(before_mglv) != type(self.magic):
         new_spells = set(dir(self.magic)) - set(dir(before_mglv))
         if len(new_spells) > 1:
             raise ValueError("More than one new spell: {}".format(new_spells))
         new_spell = list(new_spells)[0].replace("_", " ").title()
         print_centre("\nLearned {}!\n".format(new_spell))
         time.sleep(3)
コード例 #9
0
    def _communicate_stat_change(self, stat, operator, value):
        """ Print character stat changes.

        Args:
            stat (str): hp, mp, st or ag.
            operator (str): '+' or '-'.
            value (int): number to alter the stat by.
        """
        upordown = "increases" if operator == "+" else "decreases"
        msg = "{} {} {} by {}\n".format(self.name, stat.upper(), upordown,
                                        value)
        print_centre(msg)
        sleep()
コード例 #10
0
 def _determine_level(self):
     """ Determine level based upon exp value."""
     before_mglv = self.magic
     next_level_exp = self.leveling.get(self.lv + 1)
     for leveled, experience in self.leveling.items():
         if self._exp >= next_level_exp:
             if experience > self._exp:
                 self.lv = leveled - 1
                 msg = "{} has reached level {}!".format(self.name, self.lv)
                 self._determine_stats()
                 print_centre(msg)
                 time.sleep(3)
                 self._determine_new_magic(before_mglv)
                 break
コード例 #11
0
    def purchase(self, item):
        """ Transfers the item to the hero inventory and deducts
            the cost from the players gold attr.

        Args:
            item (Item): item to transfer.
        """
        deduction = self.hero.gold - item.cost
        if deduction >= 0:
            self.hero.inventory.add_items(item)
            if self.hero.inventory.full is False:
                self.hero.gold = deduction
                print_centre("Enjoy your {}!".format(item.name))
                common.sleep()
        else:
            print_centre("You don't have enough gold to purchase that!")
            common.sleep()
コード例 #12
0
    def _adjust_value_around_max(self, stat, value):
        """ Adjusts the parsed value such that it cannot increase
            the stat value above its maximum limit.

        Args:
            stat (str): hp, mp, st or ag.
            value (int): number to increase the stat by.
        """
        max_stat = getattr(self, "_max_{}".format(stat))
        current_stat = getattr(self, stat)
        if current_stat == max_stat:
            msg = "{} is already at the maximum value\n"
            print_centre(msg.format(stat.upper()))
            sleep()
            return 0
        elif value + current_stat > max_stat:
            return max_stat - current_stat
        else:
            return value
コード例 #13
0
 def construct_store_screen(self):
     """ Clears screen and input, prints store owner & available gold."""
     common.clear()
     print_centre(animations.get("Shopkeep"))
     print_centre("{}:\t{} gold".format(self.hero.name, self.hero.gold))
     print_centre("Welcome to my store! How may I serve you today?\n")
     common.flush_input()
コード例 #14
0
 def flee(self):
     """ Attempt to run from battle."""
     print_centre("{} attempts to flee!".format(self.hero.name))
     common.sleep()
     # 20% chance of fleeing
     weighted_success = {True: 2, False: 8}
     flee_success = common.weighted_choice(weighted_success)
     if flee_success:
         print_centre("{} successfully ran away!\n".format(self.hero.name))
         common.sleep()
         return True
     else:
         print_centre("{} couldn't get away!\n".format(self.hero.name))
         common.sleep()
         return False
コード例 #15
0
ファイル: items.py プロジェクト: superDross/HonestQuest
 def _use_msg(self):
     print_centre("You shrieked into a {}!!!\n".format(self.name))
     sleep()
コード例 #16
0
 def gold(self, amount):
     if amount < 0:
         print_centre("You do not have enough gold.")
         sleep()
     else:
         self._gold = amount
コード例 #17
0
 def _death(self):
     """ Communicate death to user and changes dead attribute."""
     print_centre("{} is dead!".format(self.name))
     self.dead = True
     sys.exit()
コード例 #18
0
 def construct_battle_screen(self):
     """ Clears screen and input, prints characters stats and animations."""
     common.clear()
     print_centre(self.enemy.animation)
     print_centre("\n{}\n{}\n".format(self.hero, self.enemy))
     common.flush_input()
コード例 #19
0
ファイル: items.py プロジェクト: superDross/HonestQuest
 def _use_msg(self):
     print_centre("You threw a {}!\n".format(self.name))
     sleep()
コード例 #20
0
ファイル: items.py プロジェクト: superDross/HonestQuest
 def _use_msg(self):
     print_centre("Lets BRO DOWN with a {}!\n".format(self.name))
     sleep()
コード例 #21
0
ファイル: items.py プロジェクト: superDross/HonestQuest
 def _use_msg(self):
     print_centre("{} has been used!\n".format(self.name.title()))
     sleep()
コード例 #22
0
ファイル: items.py プロジェクト: superDross/HonestQuest
 def _use_msg(self):
     print_centre("You uncorked a bottle of {}.\n".format(self.name))
     sleep()
コード例 #23
0
 def death(self):
     """ Communicate death to user and change state."""
     print_centre("{} is dead!\n".format(self.name))
     self.dead = True
コード例 #24
0
ファイル: items.py プロジェクト: superDross/HonestQuest
 def _use_msg(self):
     print_centre("You slammed a {}!\n".format(self.name[:-1]))
     sleep()