CascadiaGen1 / app.py
awacke1's picture
Update app.py
091bf0d
raw
history blame
2.52 kB
import streamlit as st
import random
import pandas as pd
# Cascadia Game Components
habitat_tiles = ['🌲', '🏞️', '🌊', '🌡', 'πŸŒ„']
wildlife_tokens = ['🐻', 'πŸ¦…', '🐟', '🦌', '🐿️']
players = ['Player 1', 'Player 2']
save_file = 'cascadia_game_state.txt'
# Initialize or load game state
def initialize_game():
st.session_state['habitat_stack'] = random.sample(habitat_tiles * 10, 50)
st.session_state['wildlife_stack'] = random.sample(wildlife_tokens * 10, 50)
st.session_state['players'] = {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
if 'habitat_stack' not in st.session_state:
initialize_game()
# Streamlit Interface
st.title("🌲 Cascadia Lite 🌲")
# Function to draw habitat and wildlife
def draw_habitat_and_wildlife(player):
habitat = st.session_state['habitat_stack'].pop()
wildlife = st.session_state['wildlife_stack'].pop()
st.session_state['players'][player]['habitat'].append(habitat)
st.session_state['players'][player]['wildlife'].append(wildlife)
# Display players' areas
for player in players:
st.write(f"## {player}'s Play Area")
player_data = pd.DataFrame({'Habitat Tiles': st.session_state['players'][player]['habitat'],
'Wildlife Tokens': st.session_state['players'][player]['wildlife']})
st.dataframe(player_data)
# Drafting Phase
if st.button(f"{player}: Draw Habitat and Wildlife"):
draw_habitat_and_wildlife(player)
# Tile Placement
tile_placement = st.selectbox(f"{player}: Place Habitat Tile", options=['Select Position'] + list(range(1, len(st.session_state['players'][player]['habitat']) + 1)))
# Wildlife Placement
wildlife_placement = st.selectbox(f"{player}: Place Wildlife Token", options=['Select Habitat'] + list(range(1, len(st.session_state['players'][player]['wildlife']) + 1)))
# Nature Tokens
if st.session_state['players'][player]['nature_tokens'] > 0:
if st.button(f"{player}: Use a Nature Token"):
st.session_state['players'][player]['nature_tokens'] -= 1
# Logic for swapping wildlife tokens or other actions
st.write(f"{player} used a nature token. Remaining: {st.session_state['players'][player]['nature_tokens']}")
# Save game state
with open(save_file, 'w') as file:
json.dump(st.session_state, file)
# Game Controls and Instructions
st.write("## Game Controls")
st.write("Use the buttons and select boxes to play the game!")