Emil Skogsund (aider) commited on
Commit
cd61cd2
·
1 Parent(s): 8668a46

feat: Add debug output to console for game state and key events

Browse files
Files changed (1) hide show
  1. app.py +8 -0
app.py CHANGED
@@ -19,6 +19,8 @@ if 'snake' not in st.session_state:
19
  st.session_state.game_running = False
20
  st.session_state.key = None # Initialize key
21
 
 
 
22
  # Streamlit UI
23
  st.title("Snake Game")
24
  canvas = st.empty()
@@ -51,7 +53,11 @@ def update_food(snake):
51
 
52
  # Main game loop
53
  def game_step():
 
54
  grid = draw_grid(st.session_state.snake, st.session_state.food)
 
 
 
55
  canvas.image(grid, width=800) # Increased canvas size
56
 
57
  # Move snake
@@ -65,6 +71,7 @@ def game_step():
65
  elif st.session_state.key == "ArrowRight" and st.session_state.direction != (0, -1):
66
  new_direction = (0, 1)
67
 
 
68
  st.session_state.direction = new_direction
69
  st.session_state.snake = move_snake(st.session_state.snake, st.session_state.direction)
70
 
@@ -98,6 +105,7 @@ document.addEventListener('keydown', (event) => {
98
  key_event = st.query_params.get("key", [None])[0]
99
  if key_event:
100
  st.session_state.key = key_event
 
101
 
102
  # Game loop
103
  while st.session_state.game_running:
 
19
  st.session_state.game_running = False
20
  st.session_state.key = None # Initialize key
21
 
22
+ print("Game initialized with snake:", st.session_state.snake)
23
+
24
  # Streamlit UI
25
  st.title("Snake Game")
26
  canvas = st.empty()
 
53
 
54
  # Main game loop
55
  def game_step():
56
+ print("Game step started")
57
  grid = draw_grid(st.session_state.snake, st.session_state.food)
58
+ print("Current snake position:", st.session_state.snake)
59
+ print("Current direction:", st.session_state.direction)
60
+ print("Current food position:", st.session_state.food)
61
  canvas.image(grid, width=800) # Increased canvas size
62
 
63
  # Move snake
 
71
  elif st.session_state.key == "ArrowRight" and st.session_state.direction != (0, -1):
72
  new_direction = (0, 1)
73
 
74
+ print("New direction:", new_direction)
75
  st.session_state.direction = new_direction
76
  st.session_state.snake = move_snake(st.session_state.snake, st.session_state.direction)
77
 
 
105
  key_event = st.query_params.get("key", [None])[0]
106
  if key_event:
107
  st.session_state.key = key_event
108
+ print("Key event captured:", key_event)
109
 
110
  # Game loop
111
  while st.session_state.game_running: