def __init__(self): import random from bestiary import Bestiary lett = ['k', 'f', 'x', 'p', 'h', 'c'] namelis = [lett[random.randint(0, x)] for x in range(1, len(lett))] self._name = namelis[1].capitalize() + ''.join(namelis[1:]) self._description = Bestiary.getDescription() self._attack = Bestiary.getAttack() self._death = Bestiary.getDeath() self._pointsTaken = random.randint(-10, 0)
def __init__(self): import random from bestiary import Bestiary lett = ['k', 'f', 'x', 'p', 'h', 'c'] namelis = [lett[random.randint(0, x)] for x in range(1,len(lett))] self._name = namelis[1].capitalize() + ''.join(namelis[1:]) self._description = Bestiary.getDescription() self._attack = Bestiary.getAttack() self._death = Bestiary.getDeath() self._pointsTaken = random.randint(-10, 0)
class Game(): def __init__(self): self.bestiary = Bestiary() name = ask_question("What is your hero's name?'") self.hero = Hero(name) self.monster = self.bestiary.get_a_monster_for_level(self.hero.level)
def ui_attack(self, attacker: bestiary.Bestiary): targets = [ player for player in self.participants if isinstance(player, (hero.Warrior, hero.Mage, hero.Rogue)) ] if len(targets) >= 2: target = targets[1] else: target = random.choice(targets) attack_name, min_att, max_att = attacker.get_attack_info( attacker.attack_info) attack_num = random.randint(min_att, max_att) for participant in self.participants: if participant == target: target.actual_hp -= attack_num print( f'{attacker.name} did {attack_num} by {attack_name} to {target.name}. And he got {target.actual_hp} HP remaining' ) if participant.actual_hp <= 0: print(f'Attack of {attacker.name} had killed {target.name}.' ) # !!!! Vyřešit - píše se stále dokola při mrtvém enemy
def __init__(self): self.bestiary = Bestiary() name = ask_question("What is your hero's name?'") self.hero = Hero(name) self.monster = self.bestiary.get_a_monster_for_level(self.hero.level)
def test_getMobsProducesCatOnFive(self): bestiary = Bestiary() bestiary.rng = (lambda: 5) mobs = bestiary.get_random_mobs([]) self.assertEqual(1, len(mobs)) self.assertEqual("cat", mobs[0].name)
def test_getMobsProducesNothingWhenNotModFive(self): bestiary = Bestiary() bestiary.rng = (lambda: 2) mobs = bestiary.get_random_mobs([]) self.assertEqual(0, len(mobs))
# import random from hero import Hero # from monster import Monster from commands import Commands from game_object import GameObject from bestiary import Bestiary from colors import bcolors # import sys # from item import Item from potion_heal import Potion_heal # initialize game command_obj = Commands() bestiary = Bestiary("monsters.txt") def getInput(): if (game_obj.HERO.hp / game_obj.HERO.hp_max) > 0.66: hp_color = bcolors.FG_BOLD_GREEN elif (game_obj.HERO.hp / game_obj.HERO.hp_max) > 0.33: hp_color = bcolors.FG_BOLD_YELLOW else: hp_color = bcolors.FG_BOLD_RED prompt = bcolors.BOLD + game_obj.HERO.name + bcolors.ENDC +\ " - lvl: [" + str(game_obj.HERO.level) + "]" +\ " - hp: " + hp_color + "[" + str(game_obj.HERO.hp) + "/" + str(game_obj.HERO.hp_max) + "]" + bcolors.ENDC +\ " .... " + \ bcolors.FG_MAGENTA + game_obj.MONSTER.name + bcolors.ENDC +\ " - hp: [" + str(game_obj.MONSTER.hp) + "]" +\