File size: 3,818 Bytes
ae46e18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import streamlit as st
import random
import numpy as np

# Initialize or reset the game state with all features
def initialize_state():
    st.session_state.update({
        'character': None,
        'knowledge': 0,
        'inventory': [],
        'map_position': (2, 2),  # Center position in a 5x5 grid
        'current_location': 'forest edge',
        'initialized': True
    })

if 'initialized' not in st.session_state:
    initialize_state()

# Characters and descriptions
characters = {
    "Wizard": {"emoji": "πŸ§™β€β™‚οΈ", "knowledge": 5, "description": "Wise and powerful, connected to magical forces."},
    "Witch": {"emoji": "πŸ§™β€β™€οΈ", "knowledge": 5, "description": "Cunning, skilled in potions and spells."}
}

# Locations and emoji grid maps
locations = {
    'forest edge': np.array([["🌲", "🌳", "πŸƒ", "🌲", "🌿"], ["πŸ„", "πŸƒ", "🌳", "πŸƒ", "πŸ„"], ["🌲", "🚢", "🌿", "πŸƒ", "🌳"], ["🌳", "πŸƒ", "πŸ„", "🌿", "🌲"], ["🌲", "πŸƒ", "🌳", "πŸƒ", "🌿"]]),
    'deep forest': np.array([["🌲", "🌿", "πŸƒ", "🌳", "πŸ„"], ["🌿", "🌳", "πŸƒ", "🌲", "🌿"], ["πŸ„", "πŸƒ", "🚢", "πŸƒ", "🌳"], ["🌳", "🌲", "πŸƒ", "πŸ„", "🌿"], ["πŸƒ", "πŸƒ", "🌳", "🌲", "🌿"]]),
    # Add other locations with corresponding maps
}

# Actions and movement
directions = {"North": (-1, 0), "South": (1, 0), "West": (0, -1), "East": (0, 1)}

# Main Streamlit application
def main():
    st.title("The Magic Workshop In The Great Tree 🌳✨")
    if st.session_state.character is None:
        choose_character()
    else:
        display_character_info()
        navigate_world()

def choose_character():
    st.header("Choose your character πŸ§™β€β™‚οΈπŸ§™β€β™€οΈ")
    character = st.selectbox("Select your character", options=list(characters.keys()), format_func=lambda x: f"{x} {characters[x]['emoji']}")
    if st.button("Choose"):
        st.session_state.character = characters[character]
        st.experimental_rerun()

def display_character_info():
    char = st.session_state.character
    st.subheader(f"Character: {char['description']}")
    st.write(f"Knowledge: {char['knowledge']}")
    if st.session_state.inventory:
        st.write(f"Inventory: {', '.join(st.session_state.inventory)}")
    else:
        st.write("Inventory: Empty")

def navigate_world():
    st.header("Explore the World")
    location = st.session_state.current_location
    st.write(f"You are in the {location}.")
    display_map(location)
    move_direction = st.selectbox("Which direction would you like to go?", options=list(directions.keys()))
    if st.button("Move"):
        move_player(move_direction)
        handle_location_change()

def display_map(location):
    map_with_player = locations[location]
    map_display = "\n".join(["".join(row) for row in map_with_player])
    st.text(map_display)

def move_player(direction):
    dx, dy = directions[direction]
    x, y = st.session_state.map_position
    nx, ny = x + dx, y + dy
    if 0 <= nx < 5 and 0 <= ny < 5:  # Ensure new position is within bounds
        # Update map position
        st.session_state.map_position = (nx, ny)
        # Update the character's position on the map
        update_map_position(st.session_state.current_location, st.session_state.map_position)

def update_map_position(location, new_position):
    # Remove old position
    locations[location][st.session_state.map_position] = "πŸƒ"  # Replace with default terrain
    # Set new position
    st.session_state.map_position = new_position
    locations[location][new_position] = "🚢"

def handle_location_change():
    # This function can be expanded to include logic for handling encounters, finding items, etc., based on the new location
    pass

if __name__ == "__main__":
    main()