gch23-344's picture
Create app.py
544a2f5 verified
import streamlit as st
def main():
st.title("Text-Based Adventure Game")
# Initialize session state
if 'location' not in st.session_state:
st.session_state.location = 'start'
# Define the game's scenes
scenes = {
'start': {
'description': "You find yourself at the edge of a dark forest. Paths lead north and east.",
'options': {
'Go North': 'cave',
'Go East': 'river'
}
},
'cave': {
'description': "You enter a dimly lit cave. It's quiet... too quiet.",
'options': {
'Explore deeper': 'treasure',
'Return to forest edge': 'start'
}
},
'river': {
'description': "A wide river blocks your path. There's a rickety bridge and a boat.",
'options': {
'Cross the bridge': 'bridge',
'Take the boat': 'boat',
'Return to forest edge': 'start'
}
},
'treasure': {
'description': "You discover a hidden treasure chest filled with gold!",
'options': {
'Take the treasure and return': 'start'
}
},
'bridge': {
'description': "The bridge collapses! You fall into the river and swim back to shore.",
'options': {
'Return to forest edge': 'start'
}
},
'boat': {
'description': "The boat carries you safely across. You find a path leading to a village.",
'options': {
'Enter the village': 'village',
'Return to forest edge': 'start'
}
},
'village': {
'description': "The villagers welcome you. You've found a new home. The adventure ends here.",
'options': {}
}
}
# Display current scene
scene = scenes[st.session_state.location]
st.markdown(f"**{scene['description']}**")
# Display options
for option, next_scene in scene['options'].items():
if st.button(option):
st.session_state.location = next_scene
st.experimental_rerun()
if __name__ == "__main__":
main()