Update app.py
Browse files
app.py
CHANGED
@@ -1,97 +1,41 @@
|
|
1 |
import streamlit as st
|
2 |
-
import random
|
3 |
import numpy as np
|
|
|
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 |
-
'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("
|
38 |
-
|
39 |
-
|
40 |
-
|
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 |
-
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 |
-
|
68 |
-
|
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()
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import numpy as np
|
3 |
+
import random
|
4 |
|
5 |
+
# Expanded set of emojis for landscape elements
|
6 |
+
emojis = ["π³", "π", "π", "π²", "πΏ", "π ", "π°", "πΌ", "π€οΈ", "π", "ποΈ", "π", "πΎ", "ποΈ", "ποΈ", "π", "π€οΈ", "π£οΈ", "ποΈ", "π", "β°οΈ", "πΆ", "π§±", "π΅", "π", "πΌ", "π»", "πΊ", "π‘", "πΊοΈ"]
|
7 |
+
|
8 |
+
def initialize_emoji_map(size):
|
9 |
+
"""Initialize an emoji map with diverse landscape elements."""
|
10 |
+
return np.random.choice(emojis, (size, size))
|
11 |
+
|
12 |
+
def display_emoji_map(emoji_map):
|
13 |
+
"""Convert the emoji map to a string for display."""
|
14 |
+
map_str = "\n".join(["".join(row) for row in emoji_map])
|
15 |
+
st.text(map_str)
|
16 |
+
|
17 |
+
def move_emojis(emoji_map, direction):
|
18 |
+
"""Shift emojis in the specified direction with wrap-around."""
|
19 |
+
if direction == "North":
|
20 |
+
emoji_map = np.roll(emoji_map, 1, axis=0)
|
21 |
+
elif direction == "South":
|
22 |
+
emoji_map = np.roll(emoji_map, -1, axis=0)
|
23 |
+
elif direction == "West":
|
24 |
+
emoji_map = np.roll(emoji_map, 1, axis=1)
|
25 |
+
elif direction == "East":
|
26 |
+
emoji_map = np.roll(emoji_map, -1, axis=1)
|
27 |
+
return emoji_map
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
29 |
def main():
|
30 |
+
st.title("Emoji Landscape Exploration")
|
31 |
+
size = st.slider("Grid Size", 5, 40, 40)
|
32 |
+
if 'emoji_map' not in st.session_state:
|
33 |
+
st.session_state.emoji_map = initialize_emoji_map(size)
|
34 |
+
display_emoji_map(st.session_state.emoji_map)
|
35 |
+
direction = st.selectbox("Move direction", ["North", "South", "East", "West"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
if st.button("Move"):
|
37 |
+
st.session_state.emoji_map = move_emojis(st.session_state.emoji_map, direction)
|
38 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
+
main()
|