File size: 3,684 Bytes
4632fbc
 
091bf0d
d99eafb
4632fbc
 
091bf0d
 
 
d99eafb
4632fbc
6f39e61
d99eafb
 
 
6f39e61
 
 
 
 
d99eafb
6f39e61
d99eafb
 
6f39e61
d99eafb
6f39e61
 
 
d99eafb
6f39e61
 
d99eafb
6f39e61
 
d99eafb
 
6f39e61
80da3b8
 
 
d99eafb
 
81ae0d1
6f39e61
 
 
 
 
 
 
 
e898f75
81ae0d1
 
4632fbc
81ae0d1
091bf0d
e898f75
 
 
 
 
 
81ae0d1
e898f75
81ae0d1
091bf0d
e898f75
 
091bf0d
 
 
 
e898f75
 
091bf0d
e898f75
 
091bf0d
e898f75
 
81ae0d1
e898f75
 
 
 
 
 
 
 
 
 
4632fbc
091bf0d
4632fbc
091bf0d
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 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
for player in players:
    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()  # Reload game state after update

    # Tile and Wildlife Placement (Placeholders for actual game logic)
    # ... (Add selectbox and logic for tile and wildlife placement)

    # Nature Tokens (Placeholder for actual game logic)
    # ... (Add button and logic for using nature tokens)

# 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!")