initial commit

This commit is contained in:
Zachary Watts
2026-04-17 17:28:22 -04:00
parent 89c358e90e
commit 18aaa30857

80
main.py Executable file
View File

@@ -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()