-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscript.py
More file actions
200 lines (184 loc) · 5.58 KB
/
script.py
File metadata and controls
200 lines (184 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python3
# This is so stupid but it helped kill an hour
import json
import random
import textwrap
from pick import pick
import os
class SpellClass:
bard = "Bard"
cleric = "Cleric"
druid = "Druid"
paladin = "Paladin"
ranger = "Ranger"
sorcerer = "Sorcerer"
warlock = "Warlock"
wizard = "Wizard"
class Color:
PURPLE = "\033[95m"
CYAN = "\033[96m"
DARKCYAN = "\033[36m"
BLUE = "\033[94m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RED = "\033[91m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
END = "\033[0m"
# Input: class name
# Process: Filter json by class (user input)
# Select random spell from new list
# Output: spell name
def choose_spell(class_name):
# Load the data from the local spells.json file
with open("spells.json") as f:
in_list = True
while in_list is True:
data = json.load(f)
# Filter the data by class
filteredData = [spell for spell in data if class_name in spell["class"]]
# Select random spell
randomSpell = filteredData[random.randint(0, len(filteredData) - 1)]
# Checks if in list of used spells
in_list = check_spell_in_list(randomSpell["name"])
if in_list:
print("This has been used before")
break
# Splits spell description into a list
chosenSpellList = randomSpell["desc"].split(".")
# Takes first two elements (first two sentences) and adds them to string
chosenSpellString = (chosenSpellList[0]) + ". " + chosenSpellList[1] + "."
# Removing every instance of <p> and </p> from the spell description
chosenSpellString = (
chosenSpellString.replace("<p>", "").replace("</p>", "").lstrip()
)
return (
Color.BOLD
+ "How about "
+ Color.GREEN
+ randomSpell["name"]
+ Color.END
+ Color.BOLD
+ "?\n"
+ Color.END
+ textwrap.fill(chosenSpellString, width=100),
randomSpell["name"],
)
# Print out list of all SpellClass variables
# Then take user input for class
# Return class name
def choose_class():
options = [
"Bard - An inspiring magician",
"Cleric - A priestly champion",
"Druid - A priest of the Old Faith",
"Paladin - A holy warrior",
"Ranger - A warrior",
"Sorcerer - A spellcaster",
"Warlock - A wielder of magic",
"Wizard - A scholarly magic-user",
]
title = "Choose a class: "
option, index = pick(options, title)
optionString = option.split(" ")[0]
class_name = optionString
print(*options, sep="\n")
print("\n" + len(class_name) * "=" + "================")
print(Color.BOLD + "You have chosen " + class_name + Color.END)
print(len(class_name) * "=" + "================")
# Return class name
return class_name
# This adds a spell to a list of already used spells
def add_spell_to_list(chosen_spell):
file = open("used_spells.txt", "a+")
file_info = file.read().split(",")
if chosen_spell not in file_info:
file.write(chosen_spell + ",")
file.close()
# Checks if spell is in list of used spells
def check_spell_in_list(spell_name):
file = open("used_spells.txt", "r")
file_info = file.read().split(",")
file.close()
if spell_name in file_info:
return True
else:
return False
if __name__ == "__main__":
# Title
print()
title = Color.BOLD + "SOARCERER'S SPELLBOOK" + Color.END
sparkle = Color.GREEN + "+" + Color.END + Color.RED + "=" + Color.END
print(sparkle * int(len(title) / 2))
print((" " * int(len(title) / 8)) + title)
print(sparkle * int(len(title) / 2))
status = True
print()
os.system('afplay "sound_effects/soarcerers_spellbook.wav"')
begin = input(
Color.GREEN
+ "+=+= "
+ Color.BOLD
+ Color.RED
+ "HIT ENTER TO BEGIN"
+ Color.GREEN
+ " =+=+\n"
+ Color.END
)
# Main Loop
while status is True:
# Print random entry
chosen_spell = choose_spell(choose_class())
if "wind" in chosen_spell[0].lower():
os.system('afplay "sound_effects/fart.wav"')
print("\n" + Color.BOLD + chosen_spell[0] + Color.END + "\n")
# Check if already used this spell before
used_spell = input(
Color.BOLD
+ "Has This Spell Been Cast Before?"
+ Color.END
+ " ["
+ Color.GREEN
+ "y"
+ Color.END
+ "/"
+ Color.RED
+ "n"
+ Color.END
+ "]"
+ "\n"
).lower()
if used_spell == "y":
add_spell_to_list(chosen_spell[1])
# Continue loop or break
v = input(
Color.BOLD
+ "Choose Another?"
+ Color.END
+ " ["
+ Color.GREEN
+ "y"
+ Color.END
+ "/"
+ Color.RED
+ "n"
+ Color.END
+ "]"
+ "\n"
).lower()
print()
if v == "n":
print(
Color.GREEN
+ "+=+= "
+ Color.RED
+ Color.BOLD
+ "May the sprint begin!"
+ Color.GREEN
+ "+=+= \n"
+ Color.END
)
os.system('afplay "sound_effects/let_the_sprint_begin.wav"')
break
if v == "y":
continue