Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cli #18

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dnd_data.sqlite
Binary file not shown.
103 changes: 92 additions & 11 deletions lib/cli.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,109 @@
# lib/cli.py

""" MAIN MENU CLI """
from helpers import (
exit_program,
helper_1
create_new_player,
view_all_players,
view_players_in_next_session,
)


def main():
def display_main_menu():
while True:
menu()
main_menu()
choice = input("> ")
if choice == "0":
exit_program()
elif choice == "1":
helper_1()
create_new_player()
elif choice == "3":
view_all_players()
elif choice == "2":
display_profile_menu()
elif choice == "4":
view_players_in_next_session()
# elif choice == "5":
# delete_player()
else:
print("Invalid choice")

print("Invalid choice. Please try again.")

def menu():
print("Please select an option:")
def main_menu():
print("D&D Character Creator:")
print("0. Exit the program")
print("1. Some useful function")
print("1. Create new player")
print("2. View your profile")
print("3. View all players")
print("4. View players attending next session")
# print("5. Delete a player")


""" PLAYER PROFILE CLI """
from helpers import (
player_name,
view_all_characters,
view_active_characters,
delete_player,
delete_character,
rsvp
)
from create_char import (
create_new_char_menu
)

def display_profile_menu():
password = input('Enter your password: ')
if password == '123':
while True:
profile_menu()
choice = input('** ')
if choice == '0':
break
elif choice == '1':
create_new_char_menu()
elif choice == '2':
view_all_characters()
elif choice == '3':
view_active_characters()
elif choice == '4':
rsvp()
elif choice == '5':
delete_character()
elif choice == '6':
delete_player()
else:
print("Invalid choice. Please try again.")
else:
print("Incorrect Password.")

def profile_menu():
"""profile title should include player.name"""
print(f"{player_name}'s Profile:")
print("0. Back to Main Menu")
print("1. Create new character")
print("2. View all characters")
print("3. View your active characters")
print("4. RSVP for next session")
print("5. Delete a character")
print("6. Delete your profile")


if __name__ == "__main__":
main()
display_main_menu()


# import helpers
#
# profile_choice = input("> ")
#
# if profile_choice == '0':
# break
# elif profile_choice in ['1', '2', '3']:
# profile_actions ={
# '1': helpers.create_character,
# '2': helpers.view_characters
# }
# profile_actions[profile_choice]()
#
#
#
#
146 changes: 146 additions & 0 deletions lib/create_char.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import random

character_info = {
'name': '',
'class': '',
'race': '',
'alignment': '',
'abilities': ''
}

states = ['name', 'class', 'race', 'alignment', 'abilities']

def create_new_char_menu():
while True:
current_state = 'name'

while current_state:
if current_state == 'name':
print("Create a name:")
get_name()
current_state = 'class'
elif current_state == 'class':
print('Select a class:')
get_class()
current_state = 'race'
elif current_state == 'race':
print('Select a race:')
get_race()
current_state = 'alignment'
elif current_state == 'alignment':
print("Select an alignment:")
get_alignment()
current_state = 'abilities'
elif current_state == 'abilities':
print("Ability Stats:")
get_abilities()
current_state = None


print(f'☺ {character_info["name"]}\'s Character Sheet ☺')
print(f'→ Class: {character_info["class"]}')
print(f'→ Race: {character_info["race"]}')
print(f'→ Alignment: {character_info["alignment"]}')
print('→ Ability Stats:')
for ability, score in character_info["abilities"].items():
print(f' • {ability}: {score}')
print("Confirm your new character (Y/N)?")
choice = input("> ")
if choice == "Y":
print("✔ ✔ SUCCESS ✔ ✔")
print("Your new character has been saved!")
print("Returning to your profile...")
break
elif choice == "N":
print("✖ ✖ CANCELLED ✖ ✖")
print("Restarting Character Form...")
else:
print("Type Y or N to confirm or restart your new character")
current_state = 'name'


def get_name():
name = input("❯❯ ")
if 3 <= len(name) <= 20:
character_info["name"] = name
print(f'★ Character\'s name: {character_info["name"]} ★')
else:
print('The name must be 3-20 characters long.')

def get_class():
classes = ["Barbarian", "Bard", "Cleric", "Druid", "Fighter", "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Warlock", "Wizard"]

for i, class_name in enumerate(classes, 1):
print(f"{i}. {class_name}")
choice = int(input('❯❯ '))
if 1 <= choice <= len(classes):
character_info["class"] = classes[choice - 1]
print(f'★ You chose: {character_info["class"]} ★')
else:
print("Invalid choice. Please try again.")


def get_race():
races = ["Dragonborn", "Dwarf", "Elf", "Gnome", "Goblin", "Halfling", "Human", "Orc", "Tiefling"]
for i, race in enumerate(races, 1):
print(f"{i}. {race}")
choice = int(input('❯❯ '))
if 1 <= choice <= len(races):
character_info["race"] = races[choice - 1]
print(f'★ You chose: {character_info["race"]} ★')
else:
print("Invalid choice. Please try again.")

""" creates an even grid of alignments using left-justify at a width of the max char length of alignment strs. prompts users to select alignment using rows and columns as indices, row being the different lists of alignments and columns being the alignments in each list
"""
def get_alignment():
alignments = [
["Lawful Good", "Lawful Neutral", "Lawful Evil"],
["Neutral Good", "True Neutral", "Neutral Evil"],
["Chaotic Good", "Chaotic Neutral", "Chaotic Evil"]
]
max_length = max(len(alignment) for row in alignments for alignment in row)
for row in alignments:
alignment_row = "| " + " | ".join(alignment.ljust(max_length) for alignment in row) + " |"
print(alignment_row)

row_choice = int(input('❯❯ Enter the row number: ')) - 1
col_choice = int(input('❯❯ Enter the column number: ')) - 1
if 0 <= row_choice < 3 and 0 <= col_choice < 3:
alignment = alignments[row_choice][col_choice]
character_info['alignment'] = alignment
print(f'★ You chose: {character_info["alignment"]} ★')
else:
print("Invalid choice. Please try again.")

"""returns a list of 3 random numbers between 1-6. adds the 3 numbers and assigns it to a variable 'ability score'
"""
def roll_3d6():
print("Rolling 3 d6...")
dice_rolls = [random.randint(1, 6) for _ in range(3)]
print(f"Dice results: {dice_rolls}")
ability_score = sum(dice_rolls)
return ability_score

"""returns the list of abilities, user can select an ability and invoke roll_3d6. adds ability: score pair to dictionary and removes ability from list of abilities. loops until ability list is empty
"""
def get_abilities():
abilities = ['Strength', 'Dexterity', 'Constitution', 'Intelligence', 'Wisdom', 'Charisma']
ability_scores = {}
while abilities:
print("Roll for: ")
for i, ability in enumerate(abilities, 1):
print(f"{i}. {ability}")
choice = int(input('❯❯ '))
if 1 <= choice <= len(abilities):
selected_ability = abilities.pop(choice - 1)
input(f'❯❯ Press Enter to roll for {selected_ability}')
ability_scores[selected_ability] = roll_3d6()
print(f'★ {selected_ability} Score: {ability_scores[selected_ability]} ★')
else:
print("Invalid choice. Please try again.")
print(f'★ {character_info["name"]}\'s Ability Stats ★')
character_info["abilities"] = ability_scores
for ability, score in ability_scores.items():
print(f'{ability}: {score}')

1 change: 1 addition & 0 deletions lib/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import ipdb



ipdb.set_trace()
40 changes: 38 additions & 2 deletions lib/helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
# lib/helpers.py

def helper_1():
print("Performing useful function#1.")
"""VARIABLES"""
player_name = "Toaster"
char_name = "Gary the Goblin"

"""Main Menu Helpers"""

def create_new_player():
print("Creating new player...")

def view_all_players():
print("Viewing all players...")

def view_profile_menu():
print("Enter your password:")

def view_players_in_next_session():
print("Players attending next session")


def exit_program():
print("Goodbye!")
exit()


"""Profile Menu Helpers"""

def create_new_character():
print("Creating new character...")

def view_all_characters():
print("Viewing all characters...")

def view_active_characters():
print("Viewing Active Characters...")

def delete_player():
print(f"Deleting {player_name}'s profile")

def delete_character():
print(f"Deleting {char_name}")

def rsvp():
print("See you next session!")
4 changes: 3 additions & 1 deletion lib/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import sqlite3

CONN = sqlite3.connect('company.db')

CONN = sqlite3.connect('dnd_data.sqlite')

CURSOR = CONN.cursor()
4 changes: 4 additions & 0 deletions lib/models/characters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __init__ import CURSOR, CONN

class Character:
pass
Empty file removed lib/models/model_1.py
Empty file.
Loading