improving, adding some party mechanisms
This commit is contained in:
53
main.py
53
main.py
@@ -15,44 +15,44 @@ class PlayerCharacter:
|
|||||||
base_attr = self.__dict__.copy()
|
base_attr = self.__dict__.copy()
|
||||||
del base_attr['constitution']
|
del base_attr['constitution']
|
||||||
del base_attr['charisma']
|
del base_attr['charisma']
|
||||||
# of those grab the highest
|
# of those grab the highest, found this at https://stackoverflow.com/a/280156
|
||||||
max_base_attr = max(base_attr, key=base_attr.get) # https://stackoverflow.com/a/280156
|
max_base_attr = max(base_attr, key=base_attr.get)
|
||||||
# use that to pick the best possible base class
|
# use that to pick the best possible base class
|
||||||
best_class = { "strength" : "Fighter", "intelligence" : "Magic User", "wisdom" : "Cleric", "dexterity" : "Thief" }
|
best_class = { "strength" : "Fighter", "intelligence" : "Magic User", "wisdom" : "Cleric", "dexterity" : "Thief" }
|
||||||
best_base_class = best_class[max_base_attr]
|
best_base_class = best_class[max_base_attr]
|
||||||
# create a list of possible classes
|
# create a list of possible classes
|
||||||
possible_classes = []
|
possible_classes = [ best_base_class ]
|
||||||
possible_classes.append(best_base_class)
|
|
||||||
# check if player qualifies for other classes
|
# check if player qualifies for other classes
|
||||||
if self.constitution >= 9:
|
if self.constitution >= 9 : possible_classes.append("Dwarf")
|
||||||
possible_classes.append("Dwarf")
|
if self.intelligence >= 9 : possible_classes.append("Elf")
|
||||||
if self.intelligence >= 9:
|
if self.constitution >= 9 and self.dexterity >= 9 : possible_classes.append("Halfling")
|
||||||
possible_classes.append("Elf")
|
# randomly select class
|
||||||
if self.constitution >= 9 and self.dexterity >= 9:
|
selected_class = random.choice(possible_classes)
|
||||||
possible_classes.append("Dwarf")
|
return f"{selected_class}"
|
||||||
return f"{possible_classes}"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Fighter(PlayerCharacter):
|
class Fighter(PlayerCharacter):
|
||||||
|
prime_requisite = "strength"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes: dict) -> None:
|
||||||
PlayerCharacter.__init__(self, attributes)
|
PlayerCharacter.__init__(self, attributes)
|
||||||
self.player_class = "fighter"
|
self.player_class = "fighter"
|
||||||
self.hp = roll_dice(1, 8)
|
self.hp = roll_dice(1, 8)
|
||||||
|
|
||||||
class MagicUser(PlayerCharacter):
|
class MagicUser(PlayerCharacter):
|
||||||
|
prime_requisite = "intelligence"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes: dict) -> None:
|
||||||
PlayerCharacter.__init__(self, name, attributes)
|
PlayerCharacter.__init__(self, name, attributes)
|
||||||
self.player_class = "magic-user"
|
self.player_class = "magic-user"
|
||||||
self.hp = roll_dice(1, 4)
|
self.hp = roll_dice(1, 4)
|
||||||
|
|
||||||
class Cleric(PlayerCharacter):
|
class Cleric(PlayerCharacter):
|
||||||
|
prime_requisite = "wisdom"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes: dict) -> None:
|
||||||
PlayerCharacter.__init__(self, name, attributes)
|
PlayerCharacter.__init__(self, name, attributes)
|
||||||
self.player_class = "cleric"
|
self.player_class = "cleric"
|
||||||
self.hp = roll_dice(1, 6)
|
self.hp = roll_dice(1, 6)
|
||||||
|
|
||||||
class Thief(PlayerCharacter):
|
class Thief(PlayerCharacter):
|
||||||
|
prime_requisite = "dexterity"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes: dict) -> None:
|
||||||
PlayerCharacter.__init__(self, name, attributes)
|
PlayerCharacter.__init__(self, name, attributes)
|
||||||
self.player_class = "thief"
|
self.player_class = "thief"
|
||||||
@@ -63,18 +63,21 @@ def roll_dice(count, sides):
|
|||||||
return sum(random.randint(1,sides) for _ in range(count))
|
return sum(random.randint(1,sides) for _ in range(count))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
new_player = PlayerCharacter()
|
adventurer_party = []
|
||||||
|
expected_party_size = 4
|
||||||
|
while len(adventurer_party) < expected_party_size:
|
||||||
|
new_player = PlayerCharacter()
|
||||||
|
selected_class = None
|
||||||
|
attempts = 0
|
||||||
|
while selected_class not in adventurer_party:
|
||||||
|
attempts += 1
|
||||||
|
selected_class = new_player.class_selector()
|
||||||
|
if selected_class not in adventurer_party:
|
||||||
|
adventurer_party.append(selected_class)
|
||||||
|
# i couldnt randomly generate a scenario where a character couldn't be added, but it seems possible, so this is the hard cut off
|
||||||
|
elif attempts > 10:
|
||||||
|
adventurer_party.append(selected_class)
|
||||||
|
|
||||||
print(new_player.__dict__)
|
print(f"{adventurer_party}")
|
||||||
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()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user