apirrone commited on
Commit
06b33b7
·
1 Parent(s): 3aeef46
Files changed (1) hide show
  1. reachy_mini_simon/main.py +33 -22
reachy_mini_simon/main.py CHANGED
@@ -201,10 +201,10 @@ class SequenceDisplay:
201
  """Displays sequence with head movements and sounds."""
202
 
203
  def __init__(self):
204
- self.MOVE_DURATION = 0.5
205
- self.HOLD_DURATION = 0.3
206
- self.RETURN_DURATION = 0.4
207
- self.PAUSE_DURATION = 0.2
208
 
209
  def show_direction(self, direction: Direction, reachy_mini: ReachyMini):
210
  """Display a single direction with animation and sound.
@@ -351,25 +351,34 @@ class ReachyMiniSimon(ReachyMiniApp):
351
  sound = DIRECTION_SOUNDS[direction]
352
  reachy_mini.media.play_sound(str(sound))
353
 
354
- print(
355
- f" Input {len(player_input)}: {direction.value.upper()} "
356
- f"({len(player_input)}/{len(game.sequence)})"
357
- )
358
-
359
- # Check if sequence is complete
360
- if len(player_input) == len(game.sequence):
361
- # Validate input
362
- if game.validate_input(player_input):
363
- print("\n✓ Correct!\n")
 
 
 
 
 
 
 
 
 
 
 
 
364
  reachy_mini.media.play_sound(str(SUCCESS_SOUND))
365
 
366
  # Add to sequence and continue (no celebration during game)
367
  game.add_to_sequence()
368
  time.sleep(0.5)
369
  state = GameState.SHOWING_SEQUENCE
370
- else:
371
- print("\n✗ Wrong sequence!\n")
372
- state = GameState.GAME_OVER
373
 
374
  elif state == GameState.CELEBRATING:
375
  # Play celebration emotion (randomly choose for variety)
@@ -395,19 +404,21 @@ class ReachyMiniSimon(ReachyMiniApp):
395
  state = GameState.IDLE
396
 
397
  elif state == GameState.GAME_OVER:
398
- # Check if new record before playing game over sound
 
 
 
 
 
399
  is_new_record = game.is_new_record()
400
 
401
  if is_new_record and emotions_available:
402
- # Celebrate new record!
403
  print("\n🎉 NEW RECORD! 🎉\n")
404
  game.update_best_score()
405
  state = GameState.CELEBRATING
406
  else:
407
  # Regular game over
408
- reachy_mini.media.play_sound(str(GAME_OVER_SOUND))
409
- reachy_mini.goto_target(antennas=[-0.5, -0.5], duration=0.5)
410
-
411
  print("=" * 50)
412
  print(f"Game Over! Final Score: Round {game.current_round}")
413
  print(f"Best Score: Round {game.best_round}")
 
201
  """Displays sequence with head movements and sounds."""
202
 
203
  def __init__(self):
204
+ self.MOVE_DURATION = 0.3 # Faster movement to direction
205
+ self.HOLD_DURATION = 0.2 # Shorter hold time
206
+ self.RETURN_DURATION = 0.3 # Faster return to neutral
207
+ self.PAUSE_DURATION = 0.1 # Shorter pause between directions
208
 
209
  def show_direction(self, direction: Direction, reachy_mini: ReachyMini):
210
  """Display a single direction with animation and sound.
 
351
  sound = DIRECTION_SOUNDS[direction]
352
  reachy_mini.media.play_sound(str(sound))
353
 
354
+ # Check immediately if this input is correct
355
+ current_index = len(player_input) - 1
356
+ expected_direction = game.sequence[current_index]
357
+
358
+ if direction != expected_direction:
359
+ # Wrong input! Lose immediately
360
+ print(
361
+ f" Input {len(player_input)}: {direction.value.upper()} "
362
+ f"({len(player_input)}/{len(game.sequence)})"
363
+ )
364
+ print(f"\n✗ Wrong! Expected {expected_direction.value.upper()}\n")
365
+ state = GameState.GAME_OVER
366
+ else:
367
+ # Correct so far
368
+ print(
369
+ f" Input {len(player_input)}: {direction.value.upper()} "
370
+ f"({len(player_input)}/{len(game.sequence)})"
371
+ )
372
+
373
+ # Check if sequence is complete
374
+ if len(player_input) == len(game.sequence):
375
+ print("\n✓ Complete sequence correct!\n")
376
  reachy_mini.media.play_sound(str(SUCCESS_SOUND))
377
 
378
  # Add to sequence and continue (no celebration during game)
379
  game.add_to_sequence()
380
  time.sleep(0.5)
381
  state = GameState.SHOWING_SEQUENCE
 
 
 
382
 
383
  elif state == GameState.CELEBRATING:
384
  # Play celebration emotion (randomly choose for variety)
 
404
  state = GameState.IDLE
405
 
406
  elif state == GameState.GAME_OVER:
407
+ # Always play game over sound first
408
+ reachy_mini.media.play_sound(str(GAME_OVER_SOUND))
409
+ reachy_mini.goto_target(antennas=[-0.5, -0.5], duration=0.5)
410
+ time.sleep(0.5) # Let the sound play
411
+
412
+ # Check if new record
413
  is_new_record = game.is_new_record()
414
 
415
  if is_new_record and emotions_available:
416
+ # Celebrate new record after game over sound!
417
  print("\n🎉 NEW RECORD! 🎉\n")
418
  game.update_best_score()
419
  state = GameState.CELEBRATING
420
  else:
421
  # Regular game over
 
 
 
422
  print("=" * 50)
423
  print(f"Game Over! Final Score: Round {game.current_round}")
424
  print(f"Best Score: Round {game.best_round}")