awacke1 commited on
Commit
e3400e8
Β·
verified Β·
1 Parent(s): c6b9bfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -76
app.py CHANGED
@@ -1,111 +1,97 @@
1
  import streamlit as st
2
  import random
3
 
4
- # Initialize or reset game state
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 detailed attributes
19
  characters = {
20
- "Wizard": {"emoji": "πŸ§™β€β™‚οΈ", "knowledge": 5, "description": "Wise and powerful, with a deep connection to magical forces."},
21
- "Witch": {"emoji": "πŸ§™β€β™€οΈ", "knowledge": 5, "description": "Cunning and resourceful, skilled in potions and spells."}
22
  }
23
 
24
- # Enhanced story acts with more detailed descriptions
25
- acts = [
26
- {"name": "Introduction", "description": "Embark on your journey to find the Great Tree."},
27
- {"name": "The Quest", "description": "Navigate the enchanted forest to discover the tree and its hidden workshop."},
28
- {"name": "The Light and Shadow", "description": "Learn the secrets of the workshop and master magical crafts."},
29
- {"name": "The Final Battle", "description": "Confront the looming threat to save the tree's magic."},
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
- st.header("Choose your character πŸ§™β€β™‚οΈπŸ§™β€β™€οΈ")
40
- character = st.selectbox("Select your character", options=list(characters.keys()), format_func=lambda x: f"{x} {characters[x]['emoji']}")
41
- st.write(characters[character]["description"])
42
- if st.button("Choose"):
43
- st.session_state.character = character
44
- st.session_state.knowledge += characters[character]["knowledge"]
45
- st.experimental_rerun()
46
 
47
- # Display current act and description
48
- act = acts[st.session_state.current_act - 1]
49
- st.header(f"Act {st.session_state.current_act}: {act['name']}")
50
- st.subheader(act["description"])
 
 
 
 
51
 
52
- # Act-specific interactions
53
- if st.session_state.current_act == 1:
54
- quest_for_tree()
55
- elif st.session_state.current_act == 2:
56
- enter_workshop()
57
- elif st.session_state.current_act == 3:
58
- final_battle()
59
- elif st.session_state.current_act == 4:
60
- conclusion()
61
 
62
- # Restart option
63
- if st.session_state.current_act > 1 and st.button("Restart the adventure"):
64
- initialize_state()
65
- st.experimental_rerun()
 
 
 
66
 
67
- def quest_for_tree():
68
- if st.button("Search for the Great Tree πŸ”"):
69
- if roll_dice() > 3:
70
- st.success("You've found the Great Tree! 🌳")
71
- st.session_state.current_act += 1
72
  else:
73
- st.error("You wander but find nothing. Try again!")
 
 
 
74
 
75
- def enter_workshop():
76
- if not st.session_state.has_solved_puzzles:
77
- if st.button("Solve puzzles to enter the workshop 🧩"):
78
- if roll_dice() + st.session_state.knowledge > 7:
79
- st.success("You solved the puzzles and entered the workshop! πŸ”“βœ¨")
80
- st.session_state.has_solved_puzzles = True
81
- else:
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 final_battle():
90
- if not st.session_state.defeated_threat:
91
- if st.button("Confront the threat πŸ—‘οΈπŸ›‘οΈ"):
92
- if roll_dice(2) + st.session_state.knowledge > 10:
93
- st.success("You've defeated the threat and saved the tree's magic! 🌳✨")
94
- st.session_state.defeated_threat = True
95
- st.session_state.current_act += 1
96
- else:
97
- st.error("You are not yet strong enough. Seek more knowledge and try again.")
98
  else:
99
- st.session_state.current_act += 1
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()