awacke1 commited on
Commit
0432453
Β·
1 Parent(s): 7c8043b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+ import pandas as pd
4
+ import os
5
+
6
+ # Cascadia Game Components
7
+ habitat_tiles = ['🌲', '🏞️', '🌊', '🌡', 'πŸŒ„']
8
+ wildlife_tokens = ['🐻', 'πŸ¦…', '🐟', '🦌', '🐿️']
9
+ players = ['Player 1', 'Player 2']
10
+ save_file = 'cascadia_game_state.csv'
11
+
12
+ # Function to load game state from CSV
13
+ def load_game_state():
14
+ if os.path.exists(save_file):
15
+ df = pd.read_csv(save_file)
16
+ game_state = {
17
+ 'habitat_stack': df['habitat_stack'].dropna().tolist(),
18
+ 'wildlife_stack': df['wildlife_stack'].dropna().tolist(),
19
+ 'players': {}
20
+ }
21
+ for player in players:
22
+ game_state['players'][player] = {
23
+ 'habitat': df[player + '_habitat'].dropna().tolist(),
24
+ 'wildlife': df[player + '_wildlife'].dropna().tolist(),
25
+ 'nature_tokens': int(df[player + '_nature_tokens'][0])
26
+ }
27
+ return game_state
28
+ else:
29
+ return None
30
+
31
+ # Function to save game state to CSV
32
+ def save_game_state(game_state):
33
+ data = {
34
+ 'habitat_stack': pd.Series(game_state['habitat_stack']),
35
+ 'wildlife_stack': pd.Series(game_state['wildlife_stack'])
36
+ }
37
+ for player in players:
38
+ player_state = game_state['players'][player]
39
+ data[player + '_habitat'] = pd.Series(player_state['habitat'])
40
+ data[player + '_wildlife'] = pd.Series(player_state['wildlife'])
41
+ data[player + '_nature_tokens'] = pd.Series([player_state['nature_tokens']])
42
+ df = pd.DataFrame(data)
43
+ df.to_csv(save_file, index=False)
44
+
45
+ # Initialize or load game state
46
+ game_state = load_game_state()
47
+ if game_state is None:
48
+ game_state = {
49
+ 'habitat_stack': random.sample(habitat_tiles * 10, 50),
50
+ 'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
51
+ 'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
52
+ }
53
+ save_game_state(game_state)
54
+
55
+ # Streamlit Interface
56
+ st.title("🌲 Cascadia Lite 🌲")
57
+
58
+ # Function to draw habitat and wildlife
59
+ def draw_habitat_and_wildlife(player, game_state):
60
+ habitat = game_state['habitat_stack'].pop()
61
+ wildlife = game_state['wildlife_stack'].pop()
62
+ game_state['players'][player]['habitat'].append(habitat)
63
+ game_state['players'][player]['wildlife'].append(wildlife)
64
+ save_game_state(game_state)
65
+
66
+ # Display players' areas and handle actions
67
+ for player in players:
68
+ st.write(f"## {player}'s Play Area")
69
+ player_data = pd.DataFrame({'Habitat Tiles': game_state['players'][player]['habitat'],
70
+ 'Wildlife Tokens': game_state['players'][player]['wildlife']})
71
+ st.dataframe(player_data)
72
+
73
+ # Drafting Phase
74
+ if st.button(f"{player}: Draw Habitat and Wildlife"):
75
+ draw_habitat_and_wildlife(player, game_state)
76
+ game_state = load_game_state() # Reload game state after update
77
+
78
+ # Tile and Wildlife Placement (Placeholders for actual game logic)
79
+ # ... (Add selectbox and logic for tile and wildlife placement)
80
+
81
+ # Nature Tokens (Placeholder for actual game logic)
82
+ # ... (Add button and logic for using nature tokens)
83
+
84
+ # Reset Button
85
+ if st.button("Reset Game"):
86
+ os.remove(save_file) # Delete the save file
87
+ game_state = {
88
+ 'habitat_stack': random.sample(habitat_tiles * 10, 50),
89
+ 'wildlife_stack': random.sample(wildlife_tokens * 10, 50),
90
+ 'players': {player: {'habitat': [], 'wildlife': [], 'nature_tokens': 3} for player in players}
91
+ }
92
+ save_game_state(game_state)
93
+ st.experimental_rerun()
94
+
95
+ # Game Controls and Instructions
96
+ st.write("## Game Controls")
97
+ st.write("Use the buttons and select boxes to play the game!")