awacke1 commited on
Commit
b36f898
Β·
verified Β·
1 Parent(s): 9fd7787

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -3,6 +3,9 @@ import random
3
  import json
4
  import math
5
 
 
 
 
6
  # Initialize game state
7
  if 'game_state' not in st.session_state:
8
  st.session_state.game_state = {
@@ -31,7 +34,7 @@ SENTENCE_TEMPLATES = {
31
  "Train": "The {property} train sped through with {word}."
32
  }
33
 
34
- # Game of Life rules: Conway-inspired for buildings
35
  def apply_game_of_life(grid):
36
  new_grid = [[cell.copy() for cell in row] for row in grid]
37
  for i in range(len(grid)):
@@ -181,8 +184,7 @@ function mousePressed() {
181
  if (i >= 0 && i < hexGrid.length && j >= 0 && j < hexGrid[0].length && hexGrid[i][j].type === 'empty') {
182
  let emoji = document.getElementById('selected_emoji').innerHTML;
183
  if (!monsterMode) {
184
- if (emoji.startsWith('🏠') || emoji.startsWith('🏑') || emoji.startsWith('🏒') ||
185
- emoji.startsWith('πŸ₯') || emoji.startsWith('🏦')) {
186
  buildings.push({
187
  x: i, y: j, emoji: emoji,
188
  color: [random(100, 255), random(100, 255), random(100, 255)],
@@ -216,12 +218,10 @@ function keyPressed() {
216
  }
217
 
218
  function addStory(type, word) {
219
- let card = st.session_state.deck[st.session_state.drawn_cards % 52];
 
220
  let suit = card[0];
221
- let sentence = SENTENCE_TEMPLATES[type].format(
222
- property: SUIT_PROPERTIES[suit],
223
- word: word
224
- );
225
  story.push(sentence);
226
  st.session_state.drawn_cards += 1;
227
  }
@@ -263,7 +263,7 @@ st.sidebar.subheader("πŸ† Scores")
263
  for p, s in st.session_state.game_state['players'].items():
264
  st.sidebar.write(f"{p}: {s}")
265
 
266
- # Game HTML
267
  game_html = f"""
268
  <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.2/p5.min.js"></script>
269
  <div id="hex_grid" style="display:none">{json.dumps(st.session_state.game_state['hex_grid'])}</div>
@@ -276,13 +276,14 @@ game_html = f"""
276
  <div id="player_id" style="display:none">{player_id}</div>
277
  <div id="selected_emoji" style="display:none">{selected_emoji}</div>
278
  <div id="story" style="display:none">{json.dumps(st.session_state.game_state['story'])}</div>
279
- <script>{p5js_code.replace('SENTENCE_TEMPLATES[type].format', '"A " + SUIT_PROPERTIES[suit] + " event with " + word')}</script>
 
280
  """
281
 
282
  # Main layout
283
  st.title("HexCitySaga: Build, Battle, and Tell Your Tale")
284
  st.write(f"Player: {player_id}. Click to place {selected_emoji}. Keys: M (monster), G/R (monster type), T (train)")
285
- html(game_html, height=500)
286
 
287
  # State update handler
288
  def update_state(data):
@@ -303,4 +304,4 @@ def update_state(data):
303
 
304
  # Initialize tracks
305
  for i in range(len(st.session_state.game_state['hex_grid'])):
306
- st.session_state.game_state['hex_grid'][i][5]['type'] = 'track'
 
3
  import json
4
  import math
5
 
6
+ # Set page config for a wider, immersive layout
7
+ st.set_page_config(page_title="HexCitySaga", layout="wide")
8
+
9
  # Initialize game state
10
  if 'game_state' not in st.session_state:
11
  st.session_state.game_state = {
 
34
  "Train": "The {property} train sped through with {word}."
35
  }
36
 
37
+ # Game of Life rules
38
  def apply_game_of_life(grid):
39
  new_grid = [[cell.copy() for cell in row] for row in grid]
40
  for i in range(len(grid)):
 
184
  if (i >= 0 && i < hexGrid.length && j >= 0 && j < hexGrid[0].length && hexGrid[i][j].type === 'empty') {
185
  let emoji = document.getElementById('selected_emoji').innerHTML;
186
  if (!monsterMode) {
187
+ if (['🏠', '🏑', '🏒', 'πŸ₯', '🏦'].includes(emoji)) {
 
188
  buildings.push({
189
  x: i, y: j, emoji: emoji,
190
  color: [random(100, 255), random(100, 255), random(100, 255)],
 
218
  }
219
 
220
  function addStory(type, word) {
221
+ let cardIndex = st.session_state.drawn_cards % 52;
222
+ let card = JSON.parse(document.getElementById('deck').innerHTML)[cardIndex];
223
  let suit = card[0];
224
+ let sentence = `A ${SUIT_PROPERTIES[suit]} event with ${type.toLowerCase()} ${word}`;
 
 
 
225
  story.push(sentence);
226
  st.session_state.drawn_cards += 1;
227
  }
 
263
  for p, s in st.session_state.game_state['players'].items():
264
  st.sidebar.write(f"{p}: {s}")
265
 
266
+ # Game HTML with deck included
267
  game_html = f"""
268
  <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.2/p5.min.js"></script>
269
  <div id="hex_grid" style="display:none">{json.dumps(st.session_state.game_state['hex_grid'])}</div>
 
276
  <div id="player_id" style="display:none">{player_id}</div>
277
  <div id="selected_emoji" style="display:none">{selected_emoji}</div>
278
  <div id="story" style="display:none">{json.dumps(st.session_state.game_state['story'])}</div>
279
+ <div id="deck" style="display:none">{json.dumps(st.session_state.deck)}</div>
280
+ <script>{p5js_code}</script>
281
  """
282
 
283
  # Main layout
284
  st.title("HexCitySaga: Build, Battle, and Tell Your Tale")
285
  st.write(f"Player: {player_id}. Click to place {selected_emoji}. Keys: M (monster), G/R (monster type), T (train)")
286
+ st.components.v1.html(game_html, height=500)
287
 
288
  # State update handler
289
  def update_state(data):
 
304
 
305
  # Initialize tracks
306
  for i in range(len(st.session_state.game_state['hex_grid'])):
307
+ st.session_state.game_state['hex_grid'][i][5]['type'] = 'track'