Update app.py
Browse filescombine and condense all features. use static lists of emoji grids and lego like primitives to control the data. Show full code listing and dont miss any of the features we have so far
app.py
CHANGED
@@ -1,97 +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 |
-
'location': 'forest edge',
|
9 |
'character': None,
|
10 |
'knowledge': 0,
|
11 |
'inventory': [],
|
12 |
-
'
|
13 |
-
'
|
14 |
-
'
|
15 |
})
|
16 |
|
17 |
if 'initialized' not in st.session_state:
|
18 |
initialize_state()
|
19 |
-
st.session_state.initialized = True
|
20 |
|
21 |
-
# Characters
|
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 |
-
#
|
28 |
-
|
29 |
-
'forest edge': ["
|
30 |
-
'deep forest': ["
|
31 |
-
# Add
|
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 |
-
|
42 |
-
|
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
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
def
|
60 |
-
|
61 |
-
|
62 |
-
|
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
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
st.session_state.
|
76 |
-
st.experimental_rerun()
|
77 |
|
78 |
-
def
|
79 |
-
#
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
# More effects can be added here
|
85 |
|
86 |
-
def
|
87 |
-
|
88 |
-
|
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()
|
|
|
1 |
import streamlit as st
|
2 |
import random
|
3 |
+
import numpy as np
|
4 |
|
5 |
+
# Initialize or reset the game state with all features
|
6 |
def initialize_state():
|
7 |
st.session_state.update({
|
|
|
|
|
8 |
'character': None,
|
9 |
'knowledge': 0,
|
10 |
'inventory': [],
|
11 |
+
'map_position': (2, 2), # Center position in a 5x5 grid
|
12 |
+
'current_location': 'forest edge',
|
13 |
+
'initialized': True
|
14 |
})
|
15 |
|
16 |
if 'initialized' not in st.session_state:
|
17 |
initialize_state()
|
|
|
18 |
|
19 |
+
# Characters and descriptions
|
20 |
characters = {
|
21 |
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful, connected to magical forces."},
|
22 |
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning, skilled in potions and spells."}
|
23 |
}
|
24 |
|
25 |
+
# Locations and emoji grid maps
|
26 |
+
locations = {
|
27 |
+
'forest edge': np.array([["π²", "π³", "π", "π²", "πΏ"], ["π", "π", "π³", "π", "π"], ["π²", "πΆ", "πΏ", "π", "π³"], ["π³", "π", "π", "πΏ", "π²"], ["π²", "π", "π³", "π", "πΏ"]]),
|
28 |
+
'deep forest': np.array([["π²", "πΏ", "π", "π³", "π"], ["πΏ", "π³", "π", "π²", "πΏ"], ["π", "π", "πΆ", "π", "π³"], ["π³", "π²", "π", "π", "πΏ"], ["π", "π", "π³", "π²", "πΏ"]]),
|
29 |
+
# Add other locations with corresponding maps
|
30 |
}
|
31 |
|
32 |
+
# Actions and movement
|
33 |
+
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
|
34 |
+
|
35 |
# Main Streamlit application
|
36 |
def main():
|
37 |
st.title("The Magic Workshop In The Great Tree π³β¨")
|
|
|
38 |
if st.session_state.character is None:
|
39 |
choose_character()
|
40 |
else:
|
41 |
+
display_character_info()
|
42 |
+
navigate_world()
|
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 |
if st.button("Choose"):
|
48 |
+
st.session_state.character = characters[character]
|
|
|
49 |
st.experimental_rerun()
|
50 |
|
51 |
+
def display_character_info():
|
52 |
+
char = st.session_state.character
|
53 |
+
st.subheader(f"Character: {char['description']}")
|
54 |
+
st.write(f"Knowledge: {char['knowledge']}")
|
55 |
+
if st.session_state.inventory:
|
56 |
+
st.write(f"Inventory: {', '.join(st.session_state.inventory)}")
|
57 |
+
else:
|
58 |
+
st.write("Inventory: Empty")
|
59 |
+
|
60 |
+
def navigate_world():
|
61 |
+
st.header("Explore the World")
|
62 |
+
location = st.session_state.current_location
|
63 |
+
st.write(f"You are in the {location}.")
|
64 |
+
display_map(location)
|
65 |
+
move_direction = st.selectbox("Which direction would you like to go?", options=list(directions.keys()))
|
66 |
+
if st.button("Move"):
|
67 |
+
move_player(move_direction)
|
68 |
+
handle_location_change()
|
69 |
|
70 |
+
def display_map(location):
|
71 |
+
map_with_player = locations[location]
|
72 |
+
map_display = "\n".join(["".join(row) for row in map_with_player])
|
73 |
+
st.text(map_display)
|
|
|
|
|
|
|
74 |
|
75 |
+
def move_player(direction):
|
76 |
+
dx, dy = directions[direction]
|
77 |
+
x, y = st.session_state.map_position
|
78 |
+
nx, ny = x + dx, y + dy
|
79 |
+
if 0 <= nx < 5 and 0 <= ny < 5: # Ensure new position is within bounds
|
80 |
+
# Update map position
|
81 |
+
st.session_state.map_position = (nx, ny)
|
82 |
+
# Update the character's position on the map
|
83 |
+
update_map_position(st.session_state.current_location, st.session_state.map_position)
|
|
|
84 |
|
85 |
+
def update_map_position(location, new_position):
|
86 |
+
# Remove old position
|
87 |
+
locations[location][st.session_state.map_position] = "π" # Replace with default terrain
|
88 |
+
# Set new position
|
89 |
+
st.session_state.map_position = new_position
|
90 |
+
locations[location][new_position] = "πΆ"
|
|
|
91 |
|
92 |
+
def handle_location_change():
|
93 |
+
# This function can be expanded to include logic for handling encounters, finding items, etc., based on the new location
|
94 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
if __name__ == "__main__":
|
97 |
main()
|