Update app.py
Browse files
app.py
CHANGED
@@ -1,111 +1,97 @@
|
|
1 |
import streamlit as st
|
2 |
import random
|
3 |
|
4 |
-
#
|
5 |
def initialize_state():
|
6 |
st.session_state.update({
|
7 |
'current_act': 1,
|
|
|
8 |
'character': None,
|
9 |
'knowledge': 0,
|
|
|
10 |
'has_solved_puzzles': False,
|
11 |
-
'defeated_threat': False
|
|
|
12 |
})
|
13 |
|
14 |
if 'initialized' not in st.session_state:
|
15 |
initialize_state()
|
16 |
st.session_state.initialized = True
|
17 |
|
18 |
-
# Characters with more
|
19 |
characters = {
|
20 |
-
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful,
|
21 |
-
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning
|
22 |
}
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
{"name": "Conclusion", "description": "Celebrate your victory and reflect on the journey."}
|
31 |
-
]
|
32 |
|
33 |
# Main Streamlit application
|
34 |
def main():
|
35 |
st.title("The Magic Workshop In The Great Tree π³β¨")
|
36 |
|
37 |
-
# Character selection and description
|
38 |
if st.session_state.character is None:
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
st.session_state.character = character
|
44 |
-
st.session_state.knowledge += characters[character]["knowledge"]
|
45 |
-
st.experimental_rerun()
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
st.
|
50 |
-
st.
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
elif st.session_state.current_act == 3:
|
58 |
-
final_battle()
|
59 |
-
elif st.session_state.current_act == 4:
|
60 |
-
conclusion()
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
-
def
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
else:
|
73 |
-
st.
|
|
|
|
|
|
|
74 |
|
75 |
-
def
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
st.error("The puzzles baffle you. Perhaps there's something you're missing?")
|
83 |
-
else:
|
84 |
-
st.write("You're inside the workshop, learning its secrets. πβοΈ")
|
85 |
-
if st.button("Learn the final secret"):
|
86 |
-
st.session_state.knowledge += 5
|
87 |
-
st.session_state.current_act += 1
|
88 |
|
89 |
-
def
|
90 |
-
if
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
else:
|
97 |
-
st.error("You are not yet strong enough. Seek more knowledge and try again.")
|
98 |
else:
|
99 |
-
|
100 |
-
|
101 |
-
def conclusion():
|
102 |
-
st.header("Congratulations! ππ")
|
103 |
-
st.write("You've completed 'The Magic Workshop In The Great Tree'.")
|
104 |
-
st.write("Through your journey, you've learned the value of knowledge, bravery, and sacrifice.")
|
105 |
-
|
106 |
-
# Helper function for dice rolls
|
107 |
-
def roll_dice(number_of_dice=1, sides=6):
|
108 |
-
return sum([random.randint(1, sides) for _ in range(number_of_dice)])
|
109 |
|
110 |
if __name__ == "__main__":
|
111 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import random
|
3 |
|
4 |
+
# Function to initialize or reset the game state
|
5 |
def initialize_state():
|
6 |
st.session_state.update({
|
7 |
'current_act': 1,
|
8 |
+
'location': 'forest edge',
|
9 |
'character': None,
|
10 |
'knowledge': 0,
|
11 |
+
'inventory': [],
|
12 |
'has_solved_puzzles': False,
|
13 |
+
'defeated_threat': False,
|
14 |
+
'sightings': []
|
15 |
})
|
16 |
|
17 |
if 'initialized' not in st.session_state:
|
18 |
initialize_state()
|
19 |
st.session_state.initialized = True
|
20 |
|
21 |
+
# Characters, locations, and sightings with more RPG-like elements
|
22 |
characters = {
|
23 |
+
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful, connected to magical forces."},
|
24 |
+
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning, skilled in potions and spells."}
|
25 |
}
|
26 |
|
27 |
+
# Random sightings for each area to add to the story's atmosphere
|
28 |
+
area_sightings = {
|
29 |
+
'forest edge': ["a fluttering butterfly", "a distant owl hoot", "rustling leaves", "a mysterious fog", "glimmering fireflies", "a fallen, ancient tree", "a curious squirrel", "a shadowy figure in the distance", "a sparkling brook", "footprints leading off the path"],
|
30 |
+
'deep forest': ["a deer darting away", "a whispering breeze", "a hidden pond", "a canopy of interlocking branches", "a sudden chill", "the call of a raven", "a circle of mushrooms", "an abandoned nest", "a ray of sunlight breaking through", "a moss-covered rock"],
|
31 |
+
# Add similar lists for other locations
|
32 |
+
}
|
|
|
|
|
33 |
|
34 |
# Main Streamlit application
|
35 |
def main():
|
36 |
st.title("The Magic Workshop In The Great Tree π³β¨")
|
37 |
|
|
|
38 |
if st.session_state.character is None:
|
39 |
+
choose_character()
|
40 |
+
else:
|
41 |
+
display_sightings()
|
42 |
+
navigate_story()
|
|
|
|
|
|
|
43 |
|
44 |
+
def choose_character():
|
45 |
+
st.header("Choose your character π§ββοΈπ§ββοΈ")
|
46 |
+
character = st.selectbox("Select your character", options=list(characters.keys()), format_func=lambda x: f"{x} {characters[x]['emoji']}")
|
47 |
+
st.write(characters[character]["description"])
|
48 |
+
if st.button("Choose"):
|
49 |
+
st.session_state.character = character
|
50 |
+
st.session_state.knowledge += characters[character]["knowledge"]
|
51 |
+
st.experimental_rerun()
|
52 |
|
53 |
+
def display_sightings():
|
54 |
+
current_location = st.session_state.location
|
55 |
+
if current_location in area_sightings:
|
56 |
+
sightings = random.sample(area_sightings[current_location], 3) # Display 3 random sightings
|
57 |
+
st.write(f"As you explore, you notice: {', '.join(sightings)}.")
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
def navigate_story():
|
60 |
+
location = locations[st.session_state.location]
|
61 |
+
st.subheader(location['description'])
|
62 |
+
for choice in location['choices']:
|
63 |
+
if st.button(choice['text']):
|
64 |
+
outcome = roll_dice('d20') # Roll a d20 for major choices
|
65 |
+
handle_choice(choice, outcome)
|
66 |
|
67 |
+
def handle_choice(choice, outcome):
|
68 |
+
# Example: Adjust logic based on dice roll outcome
|
69 |
+
if 'effect' in choice:
|
70 |
+
if outcome > 10: # Adjust thresholds as needed for game balance
|
71 |
+
apply_effect(choice['effect'])
|
72 |
else:
|
73 |
+
st.write("Your attempt was not successful this time.")
|
74 |
+
if 'next' in choice:
|
75 |
+
st.session_state.location = choice['next']
|
76 |
+
st.experimental_rerun()
|
77 |
|
78 |
+
def apply_effect(effect):
|
79 |
+
# Example: Implement effect handling logic, like finding items or getting lost
|
80 |
+
if effect == "find item":
|
81 |
+
item = random.choice(["mysterious key", "ancient coin", "magic potion"])
|
82 |
+
st.session_state.inventory.append(item)
|
83 |
+
st.write(f"You found a {item}!")
|
84 |
+
# More effects can be added here
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
def roll_dice(dice_type):
|
87 |
+
if dice_type == 'd20':
|
88 |
+
return random.randint(1, 20)
|
89 |
+
elif dice_type == 'd10':
|
90 |
+
return random.randint(1, 10)
|
91 |
+
elif dice_type == 'd6':
|
92 |
+
return random.randint(1, 6)
|
|
|
|
|
93 |
else:
|
94 |
+
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
if __name__ == "__main__":
|
97 |
main()
|