File size: 4,336 Bytes
0432453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68c2962
0432453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b745733
 
 
 
 
 
c4f372c
b745733
 
 
68c2962
b745733
 
 
0432453
b745733
 
 
 
 
0432453
b745733
 
 
 
 
 
 
 
 
 
0432453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import streamlit as st
import random
import pandas as pd
import os

# Cascadia Game Components
habitat_tiles = ['🌲', '🏞️', '🌊', '🌡', 'πŸŒ„']
wildlife_tokens = ['🐻', 'πŸ¦…', '🐟', '🦌', '🐿️']
players = ['Player 1', 'Player 2']
save_file = 'cascadia_game_state.csv'

# Function to load game state from CSV
def load_game_state():
    if os.path.exists(save_file):
        df = pd.read_csv(save_file)
        game_state = {
            'habitat_stack': df['habitat_stack'].dropna().tolist(),
            'wildlife_stack': df['wildlife_stack'].dropna().tolist(),
            'players': {}
        }
        for player in players:
            game_state['players'][player] = {
                'habitat': df[player + '_habitat'].dropna().tolist(),
                'wildlife': df[player + '_wildlife'].dropna().tolist(),
                'nature_tokens': int(df[player + '_nature_tokens'][0])
            }
        return game_state
    else:
        return None

# Function to save game state to CSV
def save_game_state(game_state):
    data = {
        'habitat_stack': pd.Series(game_state['habitat_stack']),
        'wildlife_stack': pd.Series(game_state['wildlife_stack'])
    }
    for player in players:
        player_state = game_state['players'][player]
        data[player + '_habitat'] = pd.Series(player_state['habitat'])
        data[player + '_wildlife'] = pd.Series(player_state['wildlife'])
        data[player + '_nature_tokens'] = pd.Series([player_state['nature_tokens']])
    df = pd.DataFrame(data)
    df.to_csv(save_file, index=False)

# Initialize or load game state
game_state = load_game_state()
if game_state is None:
    game_state = {
        'habitat_stack': random.sample(habitat_tiles * 10, 50),
        'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
        'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
    }
    save_game_state(game_state)

# Streamlit Interface
st.title("🌲 Cascadia Lite 🌲")

# Function to draw habitat and wildlife
def draw_habitat_and_wildlife(player, game_state):
    habitat = game_state['habitat_stack'].pop()
    wildlife = game_state['wildlife_stack'].pop()
    game_state['players'][player]['habitat'].append(habitat)
    game_state['players'][player]['wildlife'].append(wildlife)
    save_game_state(game_state)

# Display players' areas and handle actions
col1, col2 = st.columns(2)
for index, player in enumerate(players):
    with (col1 if index == 0 else col2):
        st.write(f"## {player}'s Play Area")
        player_data = pd.DataFrame({
            'Habitat Tiles': game_state['players'][player]['habitat'],
            'Wildlife Tokens': game_state['players'][player]['wildlife']
        })
        st.dataframe(player_data)

        # Drafting Phase
        if st.button(f"{player}: Draw Habitat and Wildlife"):
            draw_habitat_and_wildlife(player, game_state)
            game_state = load_game_state()

        # Tile and Wildlife Placement
        placement_options = ['Place Habitat', 'Place Wildlife', 'Skip']
        placement_choice = st.selectbox(f"{player}: Choose an action", placement_options, key=f'placement_{player}')
        if placement_choice != 'Skip':
            st.write(f"{player} chose to {placement_choice}")

        # Nature Tokens
        nature_tokens = game_state['players'][player]['nature_tokens']
        if st.button(f"{player}: Use a Nature Token ({nature_tokens} left)"):
            if nature_tokens > 0:
                # Logic to use a nature token
                st.write(f"{player} used a Nature Token!")
                game_state['players'][player]['nature_tokens'] -= 1
                save_game_state(game_state)
            else:
                st.warning("No Nature Tokens left!")


# Reset Button
if st.button("Reset Game"):
    os.remove(save_file)  # Delete the save file
    game_state = {
        'habitat_stack': random.sample(habitat_tiles * 10, 50),
        'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
        'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
    }
    save_game_state(game_state)
    st.experimental_rerun()

# Game Controls and Instructions
st.write("## Game Controls")
st.write("Use the buttons and select boxes to play the game!")