diff --git a/main.py b/main.py new file mode 100755 index 0000000..70fddd7 --- /dev/null +++ b/main.py @@ -0,0 +1,80 @@ +#!/usr/bin/python3 +import random + +class PlayerCharacter: + def __init__(self, attributes={}) -> None: + self.strength = roll_dice(3,6) if not attributes else attributes['strength'] + self.intelligence = roll_dice(3,6) if not attributes else attributes['intelligence'] + self.wisdom = roll_dice(3,6) if not attributes else attributes['wisdom'] + self.dexterity = roll_dice(3,6) if not attributes else attributes['dexterity'] + self.constitution = roll_dice(3,6) if not attributes else attributes['constitution'] + self.charisma = roll_dice(3,6) if not attributes else attributes['charisma'] + + def class_selector(self): + # take the 4 primary attribtues + base_attr = self.__dict__.copy() + del base_attr['constitution'] + del base_attr['charisma'] + # of those grab the highest + max_base_attr = max(base_attr, key=base_attr.get) # https://stackoverflow.com/a/280156 + # use that to pick the best possible base class + best_class = { "strength" : "Fighter", "intelligence" : "Magic User", "wisdom" : "Cleric", "dexterity" : "Thief" } + best_base_class = best_class[max_base_attr] + # create a list of possible classes + possible_classes = [] + possible_classes.append(best_base_class) + # check if player qualifies for other classes + if self.constitution >= 9: + possible_classes.append("Dwarf") + if self.intelligence >= 9: + possible_classes.append("Elf") + if self.constitution >= 9 and self.dexterity >= 9: + possible_classes.append("Dwarf") + return f"{possible_classes}" + + + +class Fighter(PlayerCharacter): + def __init__(self, attributes: dict) -> None: + PlayerCharacter.__init__(self, attributes) + self.player_class = "fighter" + self.hp = roll_dice(1, 8) + +class MagicUser(PlayerCharacter): + def __init__(self, attributes: dict) -> None: + PlayerCharacter.__init__(self, name, attributes) + self.player_class = "magic-user" + self.hp = roll_dice(1, 4) + +class Cleric(PlayerCharacter): + def __init__(self, attributes: dict) -> None: + PlayerCharacter.__init__(self, name, attributes) + self.player_class = "cleric" + self.hp = roll_dice(1, 6) + +class Thief(PlayerCharacter): + def __init__(self, attributes: dict) -> None: + PlayerCharacter.__init__(self, name, attributes) + self.player_class = "thief" + self.hp = roll_dice(1, 6) + +# functions +def roll_dice(count, sides): + return sum(random.randint(1,sides) for _ in range(count)) + +def main(): + new_player = PlayerCharacter() + + print(new_player.__dict__) + print(new_player.class_selector()) + quit() + + # change class to fighter if strength is the highest + if (new_player.strength > new_player.intelligence) and (new_player.strength > new_player.wisdom): + attributes = new_player.__dict__.copy() + new_player = Fighter(attributes) + print(f'fighter\n{new_player.__dict__}') + else: + print('not fighter') + +main()