awacke1 commited on
Commit
0d15259
Β·
verified Β·
1 Parent(s): a0c5d9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -89
app.py CHANGED
@@ -1,98 +1,97 @@
1
  import streamlit as st
 
2
  import numpy as np
3
- import time
4
-
5
- # Helper functions for number theory-based emoji placement
6
-
7
- def is_prime(n):
8
- if n <= 1:
9
- return False
10
- for i in range(2, int(n**0.5) + 1):
11
- if n % i == 0:
12
- return False
13
- return True
14
-
15
- def fib_sequence(n):
16
- fib_seq = [0, 1]
17
- while fib_seq[-1] + fib_seq[-2] <= n:
18
- fib_seq.append(fib_seq[-1] + fib_seq[-2])
19
- return fib_seq[2:] # Exclude first two numbers for this use case
20
-
21
- # Expanded set of emojis for landscape elements
22
-
23
- emoji_set = ["🌲", "🌳", "πŸƒ", "🌲", "🌿", "πŸ„", "🏠", "🏰", "πŸ—Ό", "πŸ›€οΈ", "🌊", "🏞️", "🌁", "🌾", "🏜️", "🏝️", "πŸ›–", "πŸ›€οΈ", "πŸ›£οΈ", "πŸ•οΈ", "πŸŒ‹", "⛰️", "🧱", "🌡", "🍁", "🌼", "🌻", "🌺", "🏑", "πŸ—ΊοΈ", "πŸŒ…", "πŸŒ„", "πŸ™οΈ", "πŸ”οΈ", "πŸ—»", "πŸ–οΈ", "🏟️", "🏯", "πŸ—οΈ", "πŸŒ‡", "πŸŒ†", "πŸŒƒ", "πŸ™οΈ"]
24
-
25
- # Locations and emoji grid maps initialization
26
-
27
- def initialize_locations(size):
28
- """Initialize different locations with unique emoji grids."""
29
- # Placeholder for location initialization logic
30
- # Randomly fill grids with emojis from emoji_set for each location
31
- np.random.seed(42) # Optional: for reproducible emoji distributions
32
- locations = {
33
- 'forest edge': np.random.choice(emoji_set, (size, size)),
34
- 'deep forest': np.random.choice(emoji_set, (size, size)),
35
- 'mountain range': np.random.choice(emoji_set, (size, size)),
36
- 'coastal town': np.random.choice(emoji_set, (size, size)),
37
- 'desert oasis': np.random.choice(emoji_set, (size, size)),
38
- }
39
- return locations
40
-
41
- # Directions for movement
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}
44
 
45
- # Movement and emoji map update functions
46
-
47
- def move_emojis(locations, current_location, direction, velocity):
48
- """Shift emojis in the specified direction with wrap-around for the current location."""
49
- dx, dy = [coord * velocity for coord in directions[direction]]
50
- locations[current_location] = np.roll(locations[current_location], shift=(dx, dy), axis=(0, 1))
51
- return locations
52
-
53
- # Streamlit application setup
54
-
55
  def main():
56
- st.title("Explore the Emoji World")
57
- size = st.sidebar.slider("Grid Size", 5, 40, 10)
58
- velocity = st.sidebar.slider("Velocity (emojis/sec)", 1, 10, 1)
59
-
60
- if 'locations' not in st.session_state:
61
- st.session_state.locations = initialize_locations(size)
62
  else:
63
- st.session_state.locations = initialize_locations(size)
64
-
65
- if 'direction' not in st.session_state:
66
- st.session_state.direction = "None"
67
-
68
- current_location = st.sidebar.selectbox("Select location", options=list(st.session_state.locations.keys()))
69
- emoji_map = st.session_state.locations[current_location]
70
- map_str = "\n".join(["".join(row) for row in emoji_map])
71
- st.text(map_str)
72
-
73
- col1, col2, col3 = st.columns(3)
74
-
75
- with col1:
76
- if st.button("West"):
77
- st.session_state.direction = "West"
78
-
79
- with col2:
80
- if st.button("North"):
81
- st.session_state.direction = "North"
82
- if st.button("Stop"):
83
- st.session_state.direction = "None"
84
- if st.button("South"):
85
- st.session_state.direction = "South"
86
-
87
- with col3:
88
- if st.button("East"):
89
- st.session_state.direction = "East"
90
-
91
- if st.session_state.direction != "None":
92
- st.session_state.locations = move_emojis(st.session_state.locations, current_location, st.session_state.direction, velocity)
93
-
94
- time.sleep(1)
95
- st.experimental_rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  if __name__ == "__main__":
98
- 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()