From 6b03659ec97790a7f623874e5162fc038f85b652 Mon Sep 17 00:00:00 2001 From: Zachary Watts Date: Sat, 18 Apr 2026 12:25:45 -0400 Subject: [PATCH] adding in better classes and methods --- main.py | 95 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/main.py b/main.py index 8f49419..e83a3f1 100755 --- a/main.py +++ b/main.py @@ -12,60 +12,105 @@ class Adventurer: self.constitution = attributes.get('constitution', roll_dice(3,6)) self.charisma = attributes.get('charisma', roll_dice(3,6)) self.player_class = None + + def __str__(self): + return f"{self.player_class}" + + def get_attributes(self): + attribute_list = ['strength', 'intelligence', 'wisdom', 'dexterity', 'constitution', 'charisma'] + return {k: self.__dict__[k] for k in attribute_list} + + def get_best_prime_attribute(self): + attribute_list = [ 'strength', 'intelligence', 'wisdom', 'dexterity' ] + prime_attributes = {k: self.__dict__[k] for k in attribute_list} + # of those remaining, return highest, found this at https://stackoverflow.com/a/280156 + return max(prime_attributes, key=prime_attributes.get) + + def roll_equipment(self): + print("testing!") + class Fighter(Adventurer): prime_requisite = "strength" - def __init__(self, attributes: dict) -> None: - PlayerCharacter.__init__(self, attributes) + def __init__(self, attributes={}) -> None: + Adventurer.__init__(self, attributes) self.player_class = "fighter" self.hp = roll_dice(1, 8) class MagicUser(Adventurer): prime_requisite = "intelligence" - def __init__(self, attributes: dict) -> None: - PlayerCharacter.__init__(self, name, attributes) + def __init__(self, attributes={}) -> None: + Adventurer.__init__(self, attributes) self.player_class = "magic-user" self.hp = roll_dice(1, 4) class Cleric(Adventurer): prime_requisite = "wisdom" - def __init__(self, attributes: dict) -> None: - PlayerCharacter.__init__(self, name, attributes) + def __init__(self, attributes={}) -> None: + Adventurer.__init__(self, attributes) self.player_class = "cleric" self.hp = roll_dice(1, 6) class Thief(Adventurer): prime_requisite = "dexterity" - def __init__(self, attributes: dict) -> None: - PlayerCharacter.__init__(self, name, attributes) + def __init__(self, attributes={}) -> None: + Adventurer.__init__(self, attributes) self.player_class = "thief" + self.hp = roll_dice(1, 4) + +class Dwarf(Adventurer): + prime_requisite = "strength" + requirements = {'constitution' : 9 } + def __init__(self, attributes={}) -> None: + Adventurer.__init__(self, attributes) + self.player_class = "dwarf" + self.hp = roll_dice(1, 8) + +class Elf(Adventurer): + prime_requisite = "intellgence" + requirements = {'intelligence' : 9 } + def __init__(self, attributes={}) -> None: + Adventurer.__init__(self, attributes) + self.player_class = "elf" + self.hp = roll_dice(1, 6) + +class Halfling(Adventurer): + prime_requisite = "dexterity" + requirements = {'constitution' : 9, 'dexterity' : 9 } + def __init__(self, attributes={}) -> None: + Adventurer.__init__(self, attributes) + self.player_class = "halfling" self.hp = roll_dice(1, 6) # Player Class Selector class ClassSelector(): def __init__(self, player: Adventurer) -> None: self.player = player - self.prime_requisites = { "strength" : "Fighter", "intelligence" : "Magic User", "wisdom" : "Cleric", "dexterity" : "Thief" } + self.available_classes = [ Fighter(), MagicUser(), Cleric(), Thief() ] + self.classes_with_reqs = [ Dwarf(), Elf(), Halfling() ] self.selected_class = self.selection() - def get_best_prime_attribute(self): - attributes = self.player.__dict__.copy() - del attributes['player_class'] - # we should not evaluate these two stats - del attributes['constitution'] - del attributes['charisma'] - # of those remaining, return highest, found this at https://stackoverflow.com/a/280156 - return max(attributes, key=attributes.get) + def return_class_by_best_attribute(self): + # for adventurer classes in available classes, return the one where that classes' prime requisite is equal to the players best attribute + return [adv_class for adv_class in self.available_classes if adv_class.prime_requisite == self.player.get_best_prime_attribute()][0] + + def return_classes_with_requirements(self): + p_attrs = self.player.get_attributes() + possible_classes = [] + for c in self.classes_with_reqs: + match_count = 0 + for r in c.requirements: + if p_attrs[r] >= c.requirements[r]: + match_count += 1 + if match_count >= len(c.requirements): + possible_classes.append(c) + return possible_classes def selection(self): - best_prime_attribute = self.get_best_prime_attribute() + best_prime_attribute = self.player.get_best_prime_attribute() # create an array of possible player classes, add the best choice per player's best core attributes - class_to_add = self.prime_requisites[best_prime_attribute] - possible_classes = [class_to_add] - # check if player qualifies for other classes - if self.player.constitution >= 9 : possible_classes.append("Dwarf") - if self.player.intelligence >= 9 : possible_classes.append("Elf") - if self.player.constitution >= 9 and self.player.dexterity >= 9 : possible_classes.append("Halfling") + possible_classes = [ self.return_class_by_best_attribute() ] + possible_classes += self.return_classes_with_requirements() # randomly select class selected_class = random.choice(possible_classes) return f"{selected_class}" @@ -81,7 +126,7 @@ class PartyGenerator(): attempts = 0 while new_player.player_class not in self.adventurers: attempts += 1 - my_adv = ClassSelector(new_player).selected_class + my_adv = ClassSelector(new_player).selection() new_player.player_class = my_adv if new_player.player_class not in self.adventurers: self.adventurers.append(new_player.player_class)