def _create_thief(self, thief_level=None): """ Проверка на появление вора. :param thief_level: Начальный уровень вора. Если не указан, то уровень определяется исходя из Дурной славы. """ # Если уровень вора не указан, то идет стандартная проверка на появление. if thief_level is None and random.choice(range(1, 5 + (self.dragon.reputation.level + 1), 1)) in \ range(self.dragon.reputation.level + 1): thief_level = Thief.start_level(self.dragon.reputation.level) if thief_level > 0: self.thief = Thief(level=thief_level, treasury=self.lair.treasury, game_ref=self) else: self.thief = None
def __init__(self): """Start the game and create resources""" pygame.init() self.party = Party(self, abyss_temple, 1, 1) self.stats = GameStats(self) self.fighter = Fighter() self.mage = Mage() self.thief = Thief() self.abyss = abyss_temple() self.death_farm = death_farm() self.cuddle_cavern = cuddle_cavern() # self.characters = [Fighter(), Mage(), Thief()] # self.party_member = random.choice(self.characters) self.characters = [Fighter(), Mage(), Thief()] FPS = 30 fpsClock = pygame.time.Clock() fpsClock.tick(FPS) pygame.display.set_caption("Guild Master")
def _create_thief(self, thief_level=None): """ Check for thief appearance. :param thief_level: Starting level of thief. If not specified, then determined from reputation level. """ # If thief's level is not specified, then it is a standart test on thief appearance. if thief_level is None and random.choice(range(1, 5 + (self.dragon.reputation.level + 1), 1)) in \ range(self.dragon.reputation.level + 1): thief_level = Thief.start_level(self.dragon.reputation.level) if thief_level > 0: self.thief = Thief(level=thief_level, treasury=self.lair.treasury, game_ref=self) else: self.thief = None
import random class Character: def __init__(self, name, **kwargs): self.name = name for key, value in kwargs.items(): setattr(self, key, value) class Thief(Character): sneaky = True def pickpocket(self): return self.sneaky and bool(random.randint(0, 1)) def hide(self, light_level): return self.sneaky and light_level < 10 if __name__ == '__main__': from characters import Thief nagalot = Thief("Charles") ans = "No" print("Character Name: {}".format(nagalot.name)) if nagalot.sneaky: ans = "Yes" print("Is this a sneaky character: {}".format(ans))
class Thief: # use TitleCase by convention sneaky = True pass from characters import Thief Joel = Thief() # call Joel <characters.Thief object at {} > # {} spot in memory # string # added sneaky # call Joel = Thief() # dot syntax # call Joel.sneaky True Joel.sneaky = False but Thief.sneaky is still True del Joel get a name error