Created
June 16, 2025 21:52
-
-
Save Pinacolada64/7fa1e550a78de403b723fe4214411e2c to your computer and use it in GitHub Desktop.
Shows a data structure for abbreviating statistic names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from enum import Enum, auto | |
# We only need one Enum to represent the stats internally. | |
class PlayerStat(Enum): | |
CHARISMA = auto() | |
CONSTITUTION = auto() | |
DEXTERITY = auto() | |
INTELLIGENCE = auto() | |
STRENGTH = auto() | |
WISDOM = auto() | |
# Step 1: Create a consolidated data dictionary. | |
# The key is the PlayerStat member. | |
# The value is another dictionary containing: | |
# 1) the statistic name tuple in the form ("long name", "short name") | |
# 2) the display name and the phrases to display if the player's Expert Mode is disabled. | |
STAT_DATA = { | |
PlayerStat.CHARISMA: { | |
"name": ("Charisma", "Cha"), | |
"phrases": ("less influential", "more influential") | |
}, | |
PlayerStat.CONSTITUTION: { | |
"name": ("Constitution", "Con"), | |
"phrases": ("less hearty", "more hearty") | |
}, | |
PlayerStat.DEXTERITY: { | |
"name": ("Dexterity", "Dex"), | |
"phrases": ("less agile", "more agile") | |
}, | |
PlayerStat.INTELLIGENCE: { | |
"name": ("Intelligence", "Int"), | |
"phrases": ("dumber", "smarter") | |
}, | |
PlayerStat.STRENGTH: { | |
"name": ("Strength", "Str"), | |
"phrases": ("weaker", "stronger") | |
}, | |
PlayerStat.WISDOM: { | |
"name": ("Wisdom", "Wis"), | |
"phrases": ("less wise", "wiser") | |
}, | |
} | |
def adjust_stat(stat: PlayerStat, adjustment: int, verbose: bool=True, abbreviate: bool=True): | |
""" | |
Adjusts a player's statistic and prints the outcome. | |
:param stat: The statistic to be adjusted. | |
:param adjustment: The adjustment to stat. | |
:param verbose: Whether to tell about it or not (TODO: based on Expert Mode) | |
:param abbreviate: whether to use short (True) or long (False) statistic names | |
""" | |
# Step 1: Look up all data for the given stat | |
if verbose: | |
stat_info = STAT_DATA[stat] | |
stat_name = stat_info["name"][abbreviate] | |
# Get the correct phrase based on the adjustment being positive or negative, using the 'is_positive' boolean | |
# as an index into the STAT_INFO dict: | |
is_positive = adjustment > 0 | |
# print(f'{is_positive=}') | |
phrase = stat_info["phrases"][is_positive] | |
# Step 2: Display the updated outcome to the player | |
print(f"You feel {phrase}. ({stat_name} {adjustment:+})") | |
if __name__ == '__main__': | |
# --- Example Usage --- | |
# The function calls are the same, but the output is more descriptive. | |
print("--- Adjusting Stats ---") | |
for stat in PlayerStat: | |
# determine the numeric adjustment: | |
adjustment = random.randint(1, 10) | |
# 50% chance of being positive or negative: | |
is_positive = random.random() < 0.5 | |
if not is_positive: | |
adjustment = -adjustment | |
# 50% chance to abbreviate statistic name: | |
abbreviate_probability = random.random() < 0.5 | |
adjust_stat(stat, adjustment, True, abbreviate_probability) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment